// JavaScript Document


$(window).resize(function() {
						  winwth = document.documentElement.offsetWidth;
						  winhgt = document.documentElement.offsetHeight;
						  document.getElementById('portsize').value = winwth;
						  
						  if(winwth<980) {  
						  
						  	document.getElementById('container').style.margin = '0px 0px 4px 50px;'; 
							document.getElementById('container').style.left = '490px'; 
						} else { 
							document.getElementById('container').style.margin = '0px auto 4px -490px;'; 
							document.getElementById('container').style.left = '50%'; 
						}
						
						
						setHeight();
						  
						  });


var blurBG = function(total, url) {
	
	var num = document.getElementById('bg_number').innerHTML;
	var set = document.getElementById('bg_set').innerHTML;
	
	var this_slide = document.getElementById('bg_id_'+num).innerHTML;
	
	if(set==0) { 
	for (i=1;i<=(total-1);i++)	{ document.getElementById('bgslide_'+i+'_blur').style.display = 'none';	}
	
	document.getElementById('bgslide_'+num+'_blur').style.display = '';
	document.getElementById('bg_set').innerHTML = 1;
	document.cookie = "pl_bg="+this_slide+"; expires=Sat, 15 Nov 2031 01:01:01 GMT; path=/";
	$('#bg_slideshow').fadeOut(1000, function() { 
											  document.getElementById('rightslide').style.display = '';
											  $('#rightslide').animate({width:'722px'}, 1000, "swing", function() {
											  setTimeout("window.location = '"+url+"';", 200); 
												});
	});
	
	}
	
	return false;
}

var returnBlur = function(id, ref) {
	
	/** If returning from an internal page **/
	if(ref==1) { $('#rightcol').animate({width:'1px'}, 1000, "swing", function() { 
										document.getElementById('rightcol').style.display = 'none';
										$('#bg_slideshow').fadeIn(1000, function() {  $('.bgslide_'+id+'_blur').hide(1); });
										
										}); }
	
	/** If returning from another site **/
	else {
	$('#bg_slideshow').fadeIn(1000, function() {$('.bgslide_'+id+'_blur').hide(1);});
	}
}

var fadeContent = function() {
	
	$('#content').fadeIn();
}

var setHeight = function() { 
						   
			var margin = 167;
			var targetHeight = document.getElementById('content').offsetHeight+margin; 
			var currentHeight = document.getElementById('leftcol').offsetHeight; 
			var leftHeight = document.getElementById('leftcontent').offsetHeight+margin;
			
			var winHeight = window.innerHeight;
			
			//alert(winHeight+' - '+targetHeight);
			
			// If right content is taller than left
			if(targetHeight<winHeight) { 
			document.getElementById('leftcol').style.height = winHeight+'px';	
			document.getElementById('rightcol').style.height = winHeight+'px';	
			} 
			
			else if(targetHeight>leftHeight) { 
			document.getElementById('leftcol').style.height = targetHeight+'px';	
			document.getElementById('rightcol').style.height = targetHeight+'px';	
			} 
			
			// if left is taller than right
			else if(leftHeight>currentHeight) {  //alert(leftHeight+'-'+currentHeight);
			document.getElementById('leftcol').style.height = leftHeight+'px';	
			document.getElementById('rightcol').style.height = leftHeight+'px';	
			}
			
						   };
						   
						   
						   
var loadFolio = function(cat,slug,id,clicktype) {
	//if(document.getElementById('largeImage')) { var currH = document.getElementById('largeImage').offsetHeight;  } else { var currH = 500; } 
	//document.getElementById('loadingImage').style.height = currH+'px';
	$('#loadImage').fadeOut();
	$('#loadingImage').fadeIn(function () { 
	$('#loadImage').load('ajax_portfolio.php?cat='+cat+'&slug='+slug+' #folioImage', function() { $('#loadingImage').fadeOut( function() { $('#loadImage').fadeIn(); setHeight(); }) });
	
	$('#loadText').fadeOut( function() { $('#loadText').val = ''; });
	$('#loadText').load('ajax_portfolio.php?cat='+cat+'&slug='+slug+' #folioText', function() { $('#loadText').fadeIn() }) });
	
	
	$('.thumbClass').removeClass('thumblinkActive');
	$('.thumbClass').addClass('thumblink');
	$('#thumblink'+id).removeClass('thumblink');
	$('#thumblink'+id).addClass('thumblinkActive');

	var count_curr = document.getElementById('count'+id).value;
	
	document.getElementById('thumb_curr').value = eval(count_curr);
	
	var pane = $('#window');
	pane.jScrollPane(
		{
			showArrows: true, horizontalGutter: 10
		}
	);
	var api = pane.data('jsp');
	if (count_curr%2) { /* odd */ targetPos = count_curr; } else { /* even */ targetPos = count_curr-1; }
	
	targCalc = targetPos-1;
	
	if(targCalc>0) { targCalc  = targCalc/2; }
	
	
	
	scrollTarget = (targCalc)*80;
	
	
	// center thumbs
	if(scrollTarget>0) { scrollTarget= scrollTarget-80;  }
	
	//alert(targCalc+' x 80 = '+scrollTarget);
	
	if(clicktype=='arrow' || clicktype=='pageload') {   api.scrollTo(parseInt(scrollTarget), parseInt(0)); }
		
	
}

var loadArrow = function(dir) {
	
	var thumb_total = eval(document.getElementById('thumb_total').value);
	var count_curr = eval(document.getElementById('thumb_curr').value);
	
	//alert(thumb_total+'-'+count_curr);
	
	if(dir=='next' && count_curr<thumb_total) {	var target = eval(count_curr)+1; }
				
	else if (dir=='next') { var target = 1; }
	
	else if(dir=='back' && count_curr>1) { var target = eval(count_curr)-1; }
				
	else if (dir=='back') { var target = thumb_total;	}
	
	
	var cat = document.getElementById('cat'+target).value;
	var slug = document.getElementById('slug'+target).value;
	var id = document.getElementById('id'+target).value;
	loadFolio(cat,slug,id, 'arrow');
	
}
