$.preloadImages = function(){
	for(var i = 0; i < arguments.length; i++){
		$('<img />')
			.attr('src', arguments[i])
			.load(function(){
				$('#imgPreloadDiv').append($(this));
			}
		);
	}
}


$(document).ready(function(){
	$("#pag-filterBtn").click(function(){
		return IndustryFilterToggle();
	});
});


$(document).click(function(){
	if($("#pag-filterList").is(':visible')){
		IndustryFilterToggle();
	}
});


$.SetFilterOnClick = function(){
	$("#pag-filterBtn").click(function(){
		return IndustryFilterToggle();
	});
};


function IndustryFilterToggle(){
	$("#pag-filterList").slideToggle("default");
	$(this).toggleClass("slidemenuactive");
	return false;
}


function IndustryFilterHide(){
	$("#pag-filterList").hide();
	$(this).toggleClass("slidemenuactive");
	return false;
}


var xmlHttp;


function GetXmlHttpObject(){ 
	var objXMLHttp = null
	if(window.XMLHttpRequest){objXMLHttp = new XMLHttpRequest()}
	else if(window.ActiveXObject){objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")}
	return objXMLHttp
}


function Project_DetailA(pid){
	if(pid){
		xmlHttp = GetXmlHttpObject()
		if(xmlHttp == null){
			alert("Unable to complete request. Your web browser may not support XML HTTP Requests.");
			return;
		}
		var url = "/include/project_detail_A.php?pid=" + escape(pid);
		xmlHttp.onreadystatechange = Project_DetailA_StateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}


function Project_DetailA_StateChanged(){
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if(xmlHttp.status == 200){
			if(document.getElementById('projColA')){
				document.getElementById('projColA').innerHTML = xmlHttp.responseText;
				tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
			}
		}else{
			alert("An unknown error occurred while attempting to complete your request. Contact with the server may have been lost. Please wait a few minutes and try again.");
		}
	}
}


function Project_DetailB(cid, skip, industryId){
	if(cid){
		xmlHttp = GetXmlHttpObject()
		if(xmlHttp == null){
			alert("Unable to complete request. Your web browser may not support XML HTTP Requests.");
			return;
		}
		var url = "/include/project_detail_B.php?cid=" + escape(cid) + '&skip=' + escape(skip) + '&industryId=' + escape(industryId);
		xmlHttp.onreadystatechange = Project_DetailB_StateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}


function Project_DetailB_StateChanged(){
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if(xmlHttp.status == 200){
			if(document.getElementById('projColB')){
				document.getElementById('projColB').innerHTML = xmlHttp.responseText;
				$.SetFilterOnClick();
			}
		}else{
			alert("An unknown error occurred while attempting to complete your request. Contact with the server may have been lost. Please wait a few minutes and try again.");
		}
	} 
}


function Project_SwapImg($img, src){
	var actions = 2;
	var img = $('<img src="' + src + '" />').load(next);
	$img.fadeTo(500, 0.0, next);
	function next(){
		if(--actions) return;
		$img.attr({src: src}).fadeTo(500, 1.0);
	}
}


function Project_DetailB_ThumbClick(f, h, lnk){
	if(f && h){
		if(document.getElementById('projMainImageAreaImage')){
			Project_SwapImg($('#projMainImageAreaImage'), '/include/image.php?path=' + f + '&width=415&height=' + h + '&op=resize');
			document.getElementById('projMainImageAreaHref').className = 'thickbox';
			document.getElementById('projMainImageAreaHref').href      = '#TB_inline?a=1&type=image&width=790&height=540&inlineId=tbd';
			tb_init('a.thickbox, area.thickbox, input.thickbox'); // pass where to apply thickbox
  		}
	}
}