// Alert Box code for debugging: alert("I am an alert box!!")

var xmlHttp;		//Create the xmlHTTP variable that will store the XmlHttp object.
var type;
var project = "";
var category = "";

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 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 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 changeDivClickable(imgURL, imgURLClickable, frame)
{
	document.getElementById("phbig"+frame).innerHTML = "<a href='"+imgURLClickable+"' rel='lightbox'><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);
		}
		else if(type == "getBigPicture")
		{
			document.getElementById("phbig").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
}