var xmlHttp
function displayLargePic(src, width_orig, height_orig, alt) {
	document.getElementById("attLargePic").style.display='none';
	//document.getElementById("displayLargePic").style.display='';
	//$("#displayLargePic").fadeIn("slow");


	
	var width = 640;
	var height = 768;
	if(width_orig > width || height_orig > height) {
		new_height = (width / width_orig) * height_orig;
		if(new_height > height) {
			width = ( height / new_height ) * width;
			new_height = (width / width_orig) * height_orig;
		}
		height = new_height;
	} else {
		width = width_orig;
		height = height_orig;
	}
	glob_width = width;
	glob_height = height;
	
	pic = new Image(width_orig, height_orig);
	pic.src = src;
	glob_src = src;
	glob_alt = alt;

	outputLargePic(glob_src, glob_width, glob_height, glob_alt);
	getPicComment(src); // Hämtar bildkommentar
} 
function outputLargePic(src, width, height, alt) {
	if(pic.complete) {
		document.getElementById("displayLoading").style.display='none';
		document.getElementById("attLargePic").src=src;
		document.getElementById("attLargePic").width=width;
		document.getElementById("attLargePic").height=height;
		document.getElementById("attLargePic").alt=alt;
		document.getElementById("attLargePic").style.display='';
		document.getElementById("fullPicLink").href=src;
		document.getElementById("fullPicLink").alt=alt;
		document.getElementById("fullPicLink").innerHTML=alt;
		$('#displayLargePic').dialog('option', 'width', width);
		$('#displayLargePic').dialog("open");
		$('#displayLargePic').dialog({modal: true, draggable: false, resizable: false, height: 'auto', width: width, minWidth: 100});
		//new Effect.ScrollTo('displayLargePic');
	} else {
		document.getElementById("displayLoading").innerHTML="Laddar..." +alt;
		document.getElementById("displayLoading").style.display='';
		document.getElementById("fullPicLink").href=src;
		document.getElementById("fullPicLink").alt=alt;
		document.getElementById("fullPicLink").innerHTML=alt;
		setTimeout('outputLargePic(glob_src, glob_width, glob_height, glob_alt)', 100);
	}
}

function picInfoLink() {
	if(document.getElementById('displayPicInfo').style.display=='none') {
		$('#displayPicInfo').show("blind");
		document.getElementById('picInfoLink').innerHTML='Göm bildinformation';
	} else {
		$('#displayPicInfo').hide("blind");
		document.getElementById('picInfoLink').innerHTML='Visa bildinformation';
	}
}
	
function startRequest(str, page) {
	//söker efter åäö och ersätter de tecknen, annars problem i FF
	function str_replace(search, replace, subject) {
		return subject.split(search).join(replace);
	}
	var specialCharArray = new Array('Å','Ä','Ö','å','ä','ö');
	var replaceSpecialCharArray = new Array('AA','AE','OE','aa','ae','oe');
	for(var i=0; i<6; i++) {
		str = str_replace(specialCharArray[i], replaceSpecialCharArray[i], str);
	}
	if(str != "") {
		//document.getElementById("bildgalleri").style.display='none';
		document.getElementById("bildgalleri").style.display='none';
		document.getElementById("preload").innerHTML="Laddar bilder...";
		var url="ajaxPhotoGallery/includes/loadPicGallery.php?sid=" + Math.random() + "&album=" + str + "&page=" + page;
		xmlHttp=GetXmlHttpObject(stateChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
} 

function stateChanged() { 
   if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
   { 
        document.getElementById("bildgalleri").innerHTML=xmlHttp.responseText;
		setTimeout('outputdata()', 500);
   } 
} 

function outputdata() {
	document.getElementById("bildgalleri").style.display='none'; 
	$('#bildgalleri').fadeIn("slow");
	document.getElementById("preload").innerHTML="Klicka på bilderna för att få upp en större version.";
}

// Hämtar bildkommentar
function getPicComment(picId) { 
   	var url="ajaxPhotoGallery/includes/adminPicGallery.php?sid=" + Math.random() + "&picId=" + picId + "&getPicComment=&output=";
   	xmlHttp=GetXmlHttpObject(stateReceivedComment);
   	xmlHttp.open("GET", url , true);  
	xmlHttp.send(null);
}

function stateReceivedComment() { 
   if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
   { 
		if(xmlHttp.responseText != "") {
			document.getElementById("outputPicComment").style.display='block';
			document.getElementById("outputPicComment").innerHTML="<b>"+xmlHttp.responseText+"</b>";
		} else {
			document.getElementById("outputPicComment").style.display='none';
			document.getElementById("outputPicComment").innerHTML="";
		}
		getPicStats(glob_src); // Hämtar bildstats
   } 
} 
	
// Hämtar bildstatistik
function getPicStats(picId) { 
   	var url="ajaxPhotoGallery/includes/adminPicGallery.php?sid=" + Math.random() + "&picId=" + picId + "&getPicStats=";
   	xmlHttp=GetXmlHttpObject(stateReceivedStats);
   	xmlHttp.open("GET", url , true);  
	xmlHttp.send(null);
}

function updatePicStats(picId) { 
   	var url="ajaxPhotoGallery/includes/adminPicGallery.php?sid=" + Math.random() + "&picId=" + picId + "&getPicStats=&updatePicDownloaded";
   	xmlHttp=GetXmlHttpObject(stateReceivedStats);
   	xmlHttp.open("GET", url , true);  
	xmlHttp.send(null);
}

function stateReceivedStats() { 
   if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
   { 
		if(xmlHttp.responseText != "") {
			document.getElementById("outputPicStats").innerHTML=xmlHttp.responseText;
		}
		getPicAtt(glob_src); // Hämtar bildattribut
   } 
} 

// Hämtar bild attributer, bredd, höjd, storlek
function getPicAtt(picId) { 
   	var url="ajaxPhotoGallery/includes/adminPicGallery.php?sid=" + Math.random() + "&picId=" + picId + "&getPicAttributes=";
   	xmlHttp=GetXmlHttpObject(statePicAtt);
   	xmlHttp.open("GET", url , true);  
	xmlHttp.send(null);
}

function statePicAtt() { 
   if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
   { 
		if(xmlHttp.responseText != "") {
			document.getElementById("outputPicAttributes").innerHTML=xmlHttp.responseText;
		}
   } 
} 
	
function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 