var xmlHttp;		// Create the xmlHTTP variable that will store the XmlHttp object.
var type;
var project = "";
var category = "";

function getAlbumClickable(proj,cat) {	
	project = proj;	category = cat;	
	type = "getAlbumClickable";	
	xmlHttp=GetXmlHttpObject();	
	if (xmlHttp==null) {		
		alert ("Browser does not support HTTP Request");		
		return;	
	}	
	var url="../portfolio/ajax.php";						/*Defines the url (filename) to send to the server*/	
	url=url+"?action=getAlbumClickable&proj="+proj+"&cat="+cat;		/*Adds a parameters to the url with the content of the input field*/	
	url=url+"&sid="+Math.random();							/*Adds a random number to prevent the server from using a cached file*/	
	xmlHttp.onreadystatechange=stateChanged;				/*Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered*/	
	xmlHttp.open("GET",url,true);							/*Opens the XMLHTTP object with the given url.*/	
	xmlHttp.send(null);										/*Sends an HTTP request to the server*/
}

function getAlbum(proj, cat) {
	project = proj;
	category = cat;
	type = "getAlbum";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="../portfolio/ajax.php";						//Defines the url (filename) to send to the server
	url=url+"?action=getAlbum&proj="+proj+"&cat="+cat;		//Adds a parameters to the url with the content of the input field
	url=url+"&sid="+Math.random();							//Adds a random number to prevent the server from using a cached file
	xmlHttp.onreadystatechange=stateChanged;				//Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered
	xmlHttp.open("GET",url,true);							//Opens the XMLHTTP object with the given url.
	xmlHttp.send(null);										//Sends an HTTP request to the server
}

function getAlbum2(proj, cat) {
	project = proj;
	category = cat;
	type = "getAlbum2";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="../portfolio/ajax.php";						//Defines the url (filename) to send to the server
	url=url+"?action=getAlbum2&proj="+proj+"&cat="+cat;		//Adds a parameters to the url with the content of the input field
	url=url+"&sid="+Math.random();							//Adds a random number to prevent the server from using a cached file
	xmlHttp.onreadystatechange=stateChanged;				//Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered
	xmlHttp.open("GET",url,true);							//Opens the XMLHTTP object with the given url.
	xmlHttp.send(null);										//Sends an HTTP request to the server
}

function getBigPicture(proj, cat) {
	type = "getBigPicture";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}	var url="../portfolio/ajax.php";						/*Defines the url (filename) to send to the server*/	
	url=url+"?action=getBigPicture&proj="+proj+"&cat="+cat;		/*Adds a parameters to the url with the content of the input field*/	
	url=url+"&sid="+Math.random();								/*Adds a random number to prevent the server from using a cached file*/	
	xmlHttp.onreadystatechange=stateChanged;					/*Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered*/	
	xmlHttp.open("GET",url,true);								/*Opens the XMLHTTP object with the given url.*/	
	xmlHttp.send(null);											/*Sends an HTTP request to the server*/
}	

function getBigPicture2(proj, cat) {
	type = "getBigPicture2";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}	
	if (proj == "OakStreet")
		document.getElementById('phbig2').style.display='block';
	else
		document.getElementById('phbig2').style.display='none';
	
	var url="../portfolio/ajax.php";							
	
	url=url+"?action=getBigPicture2&proj="+proj+"&cat="+cat;		/*Defines the url (filename) to send to the server*/	
	url=url+"&sid="+Math.random();								/*Adds a random number to prevent the server from using a cached file*/				
	xmlHttp.onreadystatechange=stateChanged;					/*Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered*/	
	xmlHttp.open("GET",url,true);								/*Opens the XMLHTTP object with the given url.*/	
	xmlHttp.send(null);											/*Sends an HTTP request to the server*/
}	

function getBigPictureClickable(proj, cat) {	
	type = "getBigPictureClickable";	
	xmlHttp=GetXmlHttpObject();	
	if (xmlHttp==null)	{		
		alert ("Browser does not support HTTP Request");		
		return;	
	}	
	var url="../portfolio/ajax.php";							/*Defines the url (filename) to send to the server*/	
	url=url+"?action=getBigPictureClickable&proj="+proj+"&cat="+cat;		
	/*Adds a parameters to the url with the content of the input field*/	
	url=url+"&sid="+Math.random();								/*Adds a random number to prevent the server from using a cached file*/	
	xmlHttp.onreadystatechange=stateChanged;					/*Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered*/	
	xmlHttp.open("GET",url,true);								/*Opens the XMLHTTP object with the given url.*/	
	xmlHttp.send(null);											/*Sends an HTTP request to the server*/
}	

function getProjCopy(proj, cat) {
	type = "getProjCopy";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="../portfolio/ajax.php";							//Defines the url (filename) to send to the server
	url=url+"?action=getProjCopy&proj="+proj+"&cat="+cat;		//Adds a parameters to the url with the content of the input field
	url=url+"&sid="+Math.random();								//Adds a random number to prevent the server from using a cached file
	xmlHttp.onreadystatechange=stateChanged;					//Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered
	xmlHttp.open("GET",url,true);								//Opens the XMLHTTP object with the given url.
	xmlHttp.send(null);											//Sends an HTTP request to the server
}

function changeDiv(imgURL) {
	document.getElementById("phbig").innerHTML = "<img src='"+imgURL+"' height='100%' width='100%'>";
}

function changeDiv2(imgURL1, imgURL2) {
	document.getElementById("phbig").innerHTML = "<img src='"+imgURL1+"' height='100%' width='100%'>";
	document.getElementById("phbig2").innerHTML = "<img src='"+imgURL2+"' height='100%' width='100%'>";
}

function changeDivClickable(imgURL, imgURLClickable, frame, copyCaption) {
	/*change title to caption*/		
	document.getElementById("phbig"+frame).innerHTML = 
		"<a href='"+imgURLClickable+"' rel='lightbox' title = '"+copyCaption+"' ><img src='"+imgURL+"' height='100%' width='100%' border='0'></a>";
}
/*The stateChanged() function executes every time the state of the XMLHTTP object changes.*/
/*When the state changes to 4 (or to "complete"), the content of the txtHint placeholder is filled with the response text. */
function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(type == "getAlbum") {
			document.getElementById("albumLinks").innerHTML=xmlHttp.responseText;
			getBigPicture(project, category);
		}		
		if(type == "getAlbum2") {
			document.getElementById("albumLinks").innerHTML=xmlHttp.responseText;
			getBigPicture2(project, category);
		}		
		else if (type =="getAlbumClickable") {			
			document.getElementById("albumLinks").innerHTML=xmlHttp.responseText;				
			getBigPictureClickable(project, category);		
		}
		else if(type == "getBigPicture") {
			document.getElementById("phbig").innerHTML=xmlHttp.responseText;
			getProjCopy(project, category)
		}				
		else if(type == "getBigPicture2") {
			document.getElementById("phbig").innerHTML=xmlHttp.responseText;
			document.getElementById("phbig2").innerHTML=xmlHttp.responseText;			
			getProjCopy(project, category)
		}				
		else if (type == "getBigPictureClickable") {			
			document.getElementById("phbig1").innerHTML=xmlHttp.responseText;			
			getProjCopy(project,category)		
		}
		else if(type == "getProjCopy") {
			document.getElementById("copy").innerHTML=xmlHttp.responseText;
		}
	}
}

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {/*Firefox or Opera*/
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {/*IE, cause Microsoft sucks with their stupid ActiveX*/
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function getCookie(c_name) { 
	if (document.cookie.length>0) {  
		c_start=document.cookie.indexOf(c_name + "=");  
		if (c_start!=-1) {   
			c_start=c_start + c_name.length+1;  
			c_end=document.cookie.indexOf(";",c_start);  
			if (c_end==-1) c_end=document.cookie.length;  
			return unescape(document.cookie.substring(c_start,c_end));  
		}  
	}  
	return null;
}
 

