var xmldoc;


function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {
		el.style.display = 'none';
		var content = document.getElementById('PopUpContent');
		content.innerHTML = "";
	}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-305;
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-430;
	popUpDiv.style.left = window_width + 'px';
}




function importXML(xmlfilename,pictureid,seite)
{
/*	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = showPicture(pictureid);
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) showPicture(pictureid)
		};
 	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load(xmlfilename);
*/

	var xmlHttp = null;
	// Mozilla, Opera, Safari sowie Internet Explorer 7
	if (typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp) {
		// Internet Explorer 6 und älter
		try {
			xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp  = null;
			}
		}
	}
	if (xmlHttp) {
		xmlHttp.open('GET', xmlfilename, true);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				//alert(xmlHttp.responseText);
				xmlDoc = xmlHttp.responseXML;
				showPicture(pictureid,seite);
			}
		};
		xmlHttp.send(null);
	}

}






function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}




function popup2(windowname,pictureid,seite){
	xmlfilename = '/_zoom/picsdef.xml';
	importXML(xmlfilename,pictureid,seite);
	popup(windowname);
	pageTracker._trackPageview(seite +"/Bildzoom_"+pictureid); 
	
	//switchContent(contenttype,contentsource);
	//setNavigation(contentsource);
}
function showPicture(pictureid,seite){
	//alert(pictureid);
	x = xmlDoc.getElementsByTagName('photos');
	//zoompath = xmlDoc.getElementsByTagName('photo')[0].attributes[2].nodeValue;
	
	var m = 0;	
	var FooterNavi = "";
	var idaktuellesbild = 0;
	
	for (j=0; j < x[0].childNodes.length; j++)
	{		
		if (x[0].childNodes[j].nodeType != 1) continue;
		
		if (x[0].childNodes[j].attributes[0].nodeValue == seite) {
			// Scheife für jedes Bild
		
			var picutreno = m + 1;
			if ((pictureid-1) != m){ 
				FooterNavi += '<a href="javascript:showPicture(\''+picutreno+'\',\''+ seite +'\')">' + picutreno + '</a>&nbsp;&nbsp;';
				}			
			else {
				idaktuellesbild = m;
				FooterNavi += picutreno + '&nbsp;&nbsp;';
				switchContent('image',j);
								
				var pictitle = 	document.getElementById('PopUpPictureTitle');
				pictitle.innerHTML = x[0].childNodes[j].firstChild.data;
				}		
			m++;			
			}		
	}
	// Pfeile für Vor und Zurück Navi einblenden
	
	if (pictureid > 1 ){		
		prev = idaktuellesbild;
		pfeil_prev = "<a href=\"javascript:showPicture('"+ prev + "','"+ seite +"')\">Vorheriges</a>&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp";		
	}
	else pfeil_prev = "Vorheriges&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp;";
	
	FooterNavi = pfeil_prev + FooterNavi;
	
	if (pictureid < m){		
		next = idaktuellesbild+2;		
		pfeil_next = "&nbsp;&nbsp&nbsp;&nbsp;<a href=\"javascript:showPicture('"+ next + "','"+seite+"')\">N&auml;chstes</a>";
	}
	else pfeil_next = "&nbsp;&nbsp&nbsp;&nbsp;N&auml;chstes";
	FooterNavi = FooterNavi + pfeil_next;
	var footer = document.getElementById('PopUpFooter');
	footer.innerHTML = FooterNavi;

}

function switchContent(contenttype,contentid){
	
	if (contenttype == "image"){
		var content = document.getElementById('PopUpContent');
		content.innerHTML = "<a href='javascript:popup(\"popUpDiv\")'><img border='0' src='/_zoom/big/"+x[0].childNodes[contentid].attributes[1].nodeValue+"'></a>";
	}		
	else if (contenttype == "flash"){
		var content = document.getElementById('PopUpContent');
		content.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="630" height="550"> <param name="movie" value="../../_flash/'+contentsource+'.swf" />  <param name="quality" value="high" />  <embed src="../../_flash/'+contentsource+'.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="630" height="550"></embed> </object>';
	}
	
}


function replaceAtmoPic(imagesrc){
		var content = document.getElementById('ATMOPIC');
		content.innerHTML = '<img src="' + imagesrc + '" alt="CarSign Kennzeichenhalter, Kennzeichenhalterung" width="349" height="232" />';	
}
