var hrefpath='http://www.updatapartners.com';
var isLoading='no';

function hideDescriptions(){
	$$(".portfoliorollover").each(
		function(s){
			$(s).hide();
		}
	);
}

function alertbox(text) {
	$('errorlayer_text').innerHTML=text;
	$('errorlayer').show();
}

function loadstart() {
	$('loading').show();
}

function loadend() {
	$('loading').hide();
	Effect.BlindDown('main',{duration:0.5,afterFinish:function(){isLoading='no';} });
}

function newsletter(type,email) {
	new Ajax.Request(hrefpath+"/includes/newsletter.php", {
		method: "post",
		parameters: { type: type,email: email },
		onComplete: function(transport) {
			$('newsletter-response').innerHTML=transport.responseText;
		}
	});
}

function sortPortfolio(sort,sortid,pg) {
	if(isLoading=='no'){
		isLoading='yes';
		var histSort = '';
		var histSortID = ':';
		var histPage = ':';
		
		if(sort) histSort = sort;
		if(sortid) histSortID = ':'+sortid;
		if(pg) histPage = ':'+pg;
		
		var histString = histSort+histSortID+histPage;
		if(histString!='::') window.location.hash = histString;
		
		if (sortid=='advsearch') {
			/*var search=new Array();
			search['keyword']=$('advsearchinput').value;
			search['location']=$('searchlocation').value;
			search['status']=$('searchstatus').value;
			search['year']=$('searchyear').value;
			search['member']=$('searchmember').value;
			search['sector']=$('searchsector').value;
			search['transaction']=$('searchtransaction').value;
			sortid=search.serialize();*/
			sortid=$('advsearchform').serialize();
			/*var form=$('advsearchform');
			sortid=Form.serialize(form);*/
		}
		Effect.BlindUp('main',{duration:0.5});
		
		var update = function(){
			new Ajax.Updater('main',hrefpath+'/includes/portfolio-browse.php', {
				method: 'get', 
				parameters: {sort:sort,sortid:sortid,pg:pg},
				onLoading: function() {loadstart();},
				onFailure: function() {
					alertbox("This page has failed to load, please try again.");
				},
				onComplete: function() { loadend(); }
			});
		}
		
		var t = setTimeout(update, 600);
	}
}

function sortCaseStudies(sort,sortid,pg) {
	if(isLoading=='no'){
		isLoading='yes';
		var histSort = '';
		var histSortID = ':';
		var histPage = ':';
		
		if(sort) histSort = sort;
		if(sortid) histSortID = ':'+sortid;
		if(pg) histPage = ':'+pg;
		
		var histString = histSort+histSortID+histPage;
		if(histString!='::') window.location.hash = histString;
	
		Effect.BlindUp('main',{duration:0.5});
		
		var update = function(){
			new Ajax.Updater('main',hrefpath+'/includes/casestudies-browse.php', {
				method: 'get', 
				parameters: {sort:sort,sortid:sortid,pg:pg},
				onLoading: function() {loadstart();},
				onFailure: function() {
					alertbox("This page has failed to load, please try again.");
				},
				onComplete: function() { loadend(); }
			});
		}
		
		var t = setTimeout(update, 600);
	}
}

function sortNews(sort,sortid,pg) {
	if(isLoading=='no'){
		isLoading='yes';
		var histSort = '';
		var histSortID = ':';
		var histPage = ':';
		
		if(sort) histSort = sort;
		if(sortid) histSortID = ':'+sortid;
		if(pg) histPage = ':'+pg;
		
		var histString = histSort+histSortID+histPage;
		if(histString!='::') window.location.hash = histString;
		
		Effect.BlindUp('main',{duration:0.5});
		
		var update = function(){
			new Ajax.Updater('main',hrefpath+'/includes/news-browse.php', {
				method: 'get', 
				parameters: {sort:sort,sortid:sortid,pg:pg},
				onLoading: function() {loadstart();},
				onFailure: function() {
					alertbox("This page has failed to load, please try again.");
				},
				onComplete: function() { loadend(); }
			});
		}
		var t = setTimeout(update, 600);
	}
}

function sortResources(sort,sortid,pg) {
	if(isLoading=='no'){
		isLoading='yes';
		var histSort = '';
		var histSortID = ':';
		var histPage = ':';
		
		if(sort) histSort = sort;
		if(sortid) histSortID = ':'+sortid;
		if(pg) histPage = ':'+pg;
		
		var histString = histSort+histSortID+histPage;
		if(histString!='::') window.location.hash = histString;
		
		
		$$('.play').each(Element.hide);
		Effect.BlindUp('main',{duration:0.5});
		
		var update = function(){
			new Ajax.Updater('main',hrefpath+'/includes/resources-browse.php', {
				method: 'get', 
				parameters: {sort:sort,sortid:sortid,pg:pg},
				onLoading: function() {loadstart();},
				onFailure: function() {
					alertbox("This page has failed to load, please try again.");
				},
				onComplete: function() { loadend(); }
			});
		}
		
		var t = setTimeout(update, 600);
	}
}


function updateUI(newLocation,file) {
	newLocation = unescape(newLocation);
	var newLoc = new Array();
	newLoc = newLocation.split(':');
	if(file=='portfolio.php'||file=='portfolio-profile.php') sortPortfolio(newLoc[0],newLoc[1],newLoc[2]);
	if(file=='news.php'||file=='news-listing.php') sortNews(newLoc[0],newLoc[1],newLoc[2]);
	if(file=='casestudies.php'||file=='casestudies-profile.php') sortCaseStudies(newLoc[0],newLoc[1],newLoc[2]);
}
