// JavaScript Document

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }

function loadSectionPhotos(section) {
	
var xhr = null;
	
	if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();	
	}
	else if(window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xhr.onreadystatechange = function() { 
			if(xhr.readyState == 4 && xhr.status == 200) {
				var docXML= xhr.responseXML;
				var photosTmp = docXML.getElementsByTagName("photo");
				currentPhotos = new Array();
				currentImages = new Array();
				var miniatures = "";
				for(i = 0; i < photosTmp.length; i++) {
					var id = photosTmp[i].getElementsByTagName("id")[0].firstChild.nodeValue;
					var title = photosTmp[i].getElementsByTagName("title")[0].firstChild.nodeValue;
					var src = photosTmp[i].getElementsByTagName("src")[0].firstChild.nodeValue;
					currentPhotos[i] = new Array(id,title,src);
					currentImages[i] = new Image();
					currentImages[i].src = src;	
					miniatures += "<a href='Javascript:showPhoto("+(i+1)+")'><img src='/photos/small/"+id+".jpg' border='0'/></a>";

				
				}
				document.getElementById("photoTotal").innerHTML = currentPhotos.length;
				document.getElementById("miniatures").innerHTML = miniatures;
				if(document.getElementById("miniatures").style.display != "block") {
				showPhoto(1);
				}
				
				
			}
	
	};
var src = "/include/photosXML.php?section=" + section;
	xhr.open("GET",src, true);
	xhr.send(null);		
	
}

function miniatures() {
miniaturesON = true;
document.getElementById("miniatures").style.display = "block";
document.getElementById("photoLoaderDiv").style.display = "none";
document.getElementById("changeBar").style.visibility = "hidden";

}

function showPhoto(index) {
	
	if(document.getElementById("miniatures").style.display == "block") {	
		document.getElementById("miniatures").style.display = "none";
		document.getElementById("flashObject").innerHTML = "";
		document.getElementById("photoLoaderDiv").style.display = "block";
		document.getElementById("changeBar").style.visibility = "visible";
		miniaturesON = false;
		//document.getElementById("photoLoaderDiv").innerHTML =  AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','898','height','500','id','photoLoader','align','middle','src','photoLoader','quality','high','bgcolor','#111111','name','photoLoader','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','swliveconnect','true','movie','photoLoader','wmode','opaque' );
		var player = new SWFObject("photoLoader.swf", "photoLoader", "898", "500", "7", "#111111");
		player.addParam("allowScriptAccess","always");
		player.addParam("wmmode","opaque");
		player.addParam("swliveconnect","true");
		player.addVariable("swliveconnect","true");
		player.write("flashObject");
		
	}
	
	var id = currentPhotos[index-1][0];
	var title = currentPhotos[index-1][1];
	currentPhotoId = id;
	currentPhotoNum = index;
	document.getElementById("photoTitle").innerHTML = title;
	urchinTracker("Galerie/"+id+"/"+title+"/");
	document.getElementById("photoCounter").innerHTML = currentPhotoNum;
	window.setTimeout(function() { getFlashMovie("photoLoader").SetVariable("imgSrc", currentImages[index - 1].src); },50);


	
}

function addCart() {
	if(miniaturesON == false) {
window.location.href = "cart/add.php?id=" + currentPhotoId;	
	}
}

function prevPhoto() {
	if(currentPhotoNum == 1) showPhoto(currentPhotos.length);
	else showPhoto(currentPhotoNum - 1);
}

function nextPhoto() {
	if(currentPhotoNum == currentPhotos.length) showPhoto(1);
	else showPhoto(currentPhotoNum + 1);
}
