/**
 * Lädt onclick auf ein kleines Vorschaubild die größere Version in die Großansicht
 * Ändert den Link, die Caption und alt-Attribut
 */ 

var imageSwitcher = {
	
	hideElement: function(element) {
		element.style.display ="none";
	},
	
	showElement: function(element) {
		element.style.display ="block";
	},
	
	trackSwitching: function (mandant) {
		etracker.incrementEtrackerSimple(mandant, "/expose/weitere-ansichten/bilderwechsel");
	},
	
	updateElement: function(element, innerHtml) {
		element.innerHTML = innerHtml;
	},
	
	updateZoomCaption: function(urlLink, textTitle) {
		if (document.getElementById("changeboxCaption")) imageSwitcher.updateElement($("changeboxCaption"), "<a href='" + urlLink + "' rel='noindex,nofollow'>" + "<img src='/img/icons/ico_lupe.gif' alt='vergr&ouml;&szlig;ern' />&nbsp;&nbsp;" + decodeURI(textTitle) + "&nbsp;vergr&ouml;&szlig;ern</a>");
	},
	
	updateVideoCaption: function(urlLink, textTitle) {
		imageSwitcher.updateElement($("changeboxCaption"), "<a href='" + urlLink + "' rel='noindex,nofollow'>" + "&nbsp;&nbsp;" + decodeURI(textTitle) + "</a>");
	},
	
	switchImage: function(urlImage, textTitle, height, width, margin, urlLink, mandant, panorama) {
			
		var objLink = $("changeboxLink");
		var objImage = $("changeboxImage");
		
		imageSwitcher.hideElement($("slideshow"));
		imageSwitcher.hideElement($("video"));
		imageSwitcher.hideElement($("panorama"));
		
		if (panorama) {							
						
			// Panoramaplayer laden
			var html =
				"<applet archive=\"/panoapplet.jar\" code=\"panoapplet\" width=\"" + width + "\" height=\"" + height + "\" style=\"margin: " + margin + "px;\">" + 
					"<param name=\"file\" value=\"/ShowPanorama?mediaName=" + encodeURI(urlImage) + "\"/>" + 
					"<param name=\"initialView\" value=\"0.000000, 180.000005, 50.000001\" />" + 
					"<param name=\"autoSpin\" value=\"-50\" />" + 
				"</applet>"
			$("panorama").innerHTML = html;
			
			// Panorama anzeigen
			imageSwitcher.showElement($("panorama"));
			 			
			// Bildunterschrift austauschen			
			imageSwitcher.updateZoomCaption(urlLink, textTitle);
			
		} else {
			// preload image
			imgPreload = new Image();
			imgPreload.onload = function() {
				objImage.src = urlImage;
			}						

			// Bildunterschrift und Unterschriftsverlinkung aktualisieren
			imageSwitcher.updateZoomCaption(urlLink, textTitle);
			
			// Bild und Bildverlinkung aktualisieren
			objImage.setAttribute("alt", decodeURI(textTitle));
			objImage.style.height = height + "px";
			objImage.style.width = width + "px";
			objImage.style.marginTop = margin + "px";
			//objLink.href = urlLink;
			objImage.src = urlImage;
			imgPreload.src = objImage.src;
			
			// Bild anzeigen
			imageSwitcher.showElement($("slideshow"));
		
		}
		// Bildwechsel eTrackern
			// imageSwitcher.trackSwitching(mandant);
	},
	
	switchToVideo: function (baseUrl, videoPath, urlLink, textTitle, mandant, thumbUrl, configUrl, width, height){
		// Panorama und Slideshow verstecken
		imageSwitcher.hideElement($("slideshow"));
		imageSwitcher.hideElement($("panorama"));
		// VideoPlayer einfügen
		videoHelper.renderFlashPlayer("immoflashcontent", baseUrl, videoPath, thumbUrl, configUrl, width, height);
		// Bildunterschrift aktualisieren
		imageSwitcher.updateVideoCaption(urlLink, textTitle);
		// VideoPlayer anzeigen
		imageSwitcher.showElement($("video"));
		// Bildwechsel eTrackern
		imageSwitcher.trackSwitching(mandant);
	},
	
	ivwPxBM: function (element) {
		var IVW = "<img src=\"http://morgpost.ivwbox.de/cgi-bin/ivw/CP/immobilienmarkt?r="+escape(document.referrer)+"&d="+(Math.random()*100000)+"\" width=\"1\" height=\"1\" alt=\"\" class=\"countPixel\"/>";
		document.getElementById(element).innerHTML = IVW;
	},
	
	ivwPxHA: function (element) {
        var IVW = "<img src=\"http://abendbl.ivwbox.de/cgi-bin/ivw/CP/17010?r="+escape(document.referrer)+"&d="+(Math.random()*100000)+"\" width=\"1\" height=\"1\" alt=\"\" class=\"countPixel\"/>";
        document.getElementById(element).innerHTML = IVW;
	}
}
