
/*global $,log,app,style,svc,ml,confmodell,modeldisplayCtrl,layoutManager */
/*global imoustkey */



//richtiger Hintergrund fuer Modellbilder (VW -> grey, SEAT large -> dark)
function getHydraServerParams(resource, size, cabrio_status)
{
	var background = '';
	if (style.isVw || style.isLnf) {
		background = 'grey';
	}
	if (style.isSeat && size === 'L') {
		background = 'dark';
	}
	// cabrio option nur bei Audi
	if (cabrio_status) {
		return resource + background + cabrio_status + size;
	}
	return resource + background + size;
}

//URL fuer Medienservice mit Parametern modellcode, farbe, polster, maus generieren
function getModellImgURL (resource, farbe)
{
	if (!farbe) {
		farbe = confmodell.farbe;
	}
	
	var url = svc.media_base_url + confmodell.fabrikat + '/';
	if (confmodell.modellcode !== '') {
		url = url + "MC/" + confmodell.modellcode;
	} else {
		url = url + "MG/" + confmodell.modellgruppe;
		if (imoustkey !== '') {
			url = url + "/@/" + imoustkey;
		}
	}
	return url + '/' + resource + ".jpg" + 
		"?F=" + farbe + 
		"&P=" + confmodell.polster + 
		"&M=" + confmodell.mehrausstattungen;
}


function HydraMediaservice(params) {
	this.init(params);
}

$.extend(HydraMediaservice.prototype, {
	init : function(params) {
		this.isCabrio = false;
		this.roofOpen = true;
	},
	buttonImage : function(view) {
		if(view === 'front'){
			return getModellImgURL('frontcropXS');
		} else if (view === 'rear'){
			if(confmodell.fabrikat === 'S'){
				return "/error_404"; // Bei Seat ist keine Rückansicht vorhanden, Hydraserver liefert aber Frontbild
			}
			return getModellImgURL('backcropXS');
		} else if (view === 'interior'){
			return getModellImgURL('innencropXS');
		}
	},	
	modelImage : function(view, color) {
		var roof = !this.roofOpen || color ? "closed" : "open";
		
		if(view === 'front') {
			if(this.isCabrio) {
				return getModellImgURL(getHydraServerParams('front', 'M', roof), color);
			} else {
				return getModellImgURL(getHydraServerParams('front', 'M'), color);
			}
		} else if (view === 'rear') {
			if(this.isCabrio){
				return getModellImgURL(getHydraServerParams('back', 'M', roof), color);
			} else {
				return getModellImgURL(getHydraServerParams('back', 'M'), color);
			}
		} else if (view === 'interior'){
			return getModellImgURL(getHydraServerParams('innen', 'M'), color);
		}
	},
	modelImageBig : function(view, color) {
		var roof = !this.roofOpen || color ? "closed" : "open";
		
		if(view === 'front') {
			if(this.isCabrio){
				return getModellImgURL(getHydraServerParams('front', 'L', roof), color);
			} else {
				return getModellImgURL(getHydraServerParams('front', 'L'), color);
			}
		} else if (view === 'rear') {
			if(this.isCabrio){
				return getModellImgURL(getHydraServerParams('back', 'L', roof), color);
			} else {
				return getModellImgURL(getHydraServerParams('back', 'L'), color);
			}
		} else if (view === 'interior'){
			return getModellImgURL(getHydraServerParams('innen', 'L'), color);
		}
	},

	setCabrio: function(isCabrio, roofOpen){
		this.isCabrio = isCabrio;
		this.roofOpen = roofOpen;
	}
});

