//document.onselectstart = function() {return false;}
//document.onmousedown = function() {return false;}

var sizeBy = "height";
var imagePanner = "";
var currentY = 0;
var mouseY = 0;
var mouseRatio = 0;
var galleryImages = Array();
var resizeTimer = "";
var resizeLeftTimer = "";
var triggermousestop = 0;
var mousestop = 0;

$(document).ready(function(){
	
	//Force the size and margin on all TD elements, for the sake of the project description page
	$('table').removeAttr("style");
	$('table').removeAttr("width");
	$('table').removeAttr("height");
	$('td').css({"width":"180px","margin-left":"10px","text-align":"left","padding-left":"10px","padding-right":"10px"})
	$('tr:nth-child(2n+1)').css({"background-color":"#f2f2f2","height":"25px"});
		
	//Project Gallery Arrow Hovers
	$(".rightslideshowarrow").mouseenter(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/rightarrowhover.png)' });
			   }),
	$(".rightslideshowarrow").mouseleave(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/rightarrow.png)' });
	   }); 
	   
	 $(".leftslideshowarrow").mouseenter(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/leftarrowhover.png)' });
			   }),
	$(".leftslideshowarrow").mouseleave(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/leftarrow.png)' });
	   });   
   
	
	  //Project selection nav
   
   $("#rightarrow").mouseenter(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/rightarrowhover.png)' });
			   }),
	$("#rightarrow").mouseleave(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/rightarrow.png)' });
	   }); 
	   
	 $("#leftarrow").mouseenter(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/leftarrowhover.png)' });
			   }),
	$("#leftarrow").mouseleave(function() {
			$(this).css({ backgroundImage : 'url(http://neoscapelabs.com/projects/portman/_uploads/projects/theproject/leftarrow.png)' });
	   });
	   
	 
	   
//Social Media hover buttons
$(".socialicon").hover(function() {
			var thissocialicon = $(this).attr("src");
			SplitName = thissocialicon.split("bw.png");
			$(this).attr("src",SplitName[0]+".png");
			}, 
					function() {
					var thissocialicon = $(this).attr("src");
					SplitName = thissocialicon.split(".png");
					$(this).attr("src",SplitName[0]+"bw.png");
	});


	//starting with thumbnails
	$("#thumbnailView").addClass("active");
	var thumbnailviewstatus = true;


	$("#listView").click(function(){
		$("#listView").addClass("active");
		$("#thumbnailView").removeClass("active");
		$("#loadedlist").fadeIn(100);
		$("#thumbnailsscroll").height(125);
		$("#projectnavigationblock").height(125);
		$(".projectthumbnailtitlecontainer").height(0);
		$(".scrollarrow").height(125);
		$("#loadedthumbnails").fadeOut(100);
		$("#leftarrowdisabler").height(125);
		$("#rightarrowdisabler").height(125);
		$(".projectthumbnailtitle").fadeOut(100);
		resizeList();
		var thumbnailviewstatus = false;
		//$.post("listdata.php",{"leftofflist":0,"howmanyfitlist":howmanyflitlistitems},function(data){
								//$("#loadedlist").html(data);});
								$("#leftarrowdisabler").show();

		
	});
	
	
	$("#thumbnailView").click(function(){
		$("#listView").removeClass("active");
		$("#thumbnailView").addClass("active");
		$("#loadedthumbnails").fadeIn(100);
		$("#thumbnailsscroll").height(70);
		$("#projectnavigationblock").height(70);
		$(".projectthumbnailtitlecontainer").height(10);
		$(".scrollarrow").height(70);
		$("#leftarrowdisabler").height(70);
		$("#rightarrowdisabler").height(70);
		$("#loadedlist").fadeOut(100);
		$(".projectthumbnailtitle").fadeIn(100);
		var thumbnailviewstatus = true;
		resizeList();
		//$.post("thumbnails.php",{"leftoff":0,"howmanyfit":howmanyfit, "emptyspace":emptyspace, "spaceavailable":spaceavailable},function(data){
								//$("#loadedthumbnails").html(data);});
		//var leftoff = 0;
		//var leftofflist = 0;
	});
	
	

						

							
	
	
	//Positioning for project titles
	/*
	$(".thumbnailpicture").hover(function(){
			$('.projectthumbnailtitle').show();
			//get the color hover
			var thumbsourceimg = $(this).attr("src");
			SplitName = thumbsourceimg.split(".jpg");
			$(this).attr("src",SplitName[0]+"col.jpg");
			//position the title
			var position = $(this).position();
			var titlewidth = ($('.projectthumbnailtitle').width)/2;
			$(".projectthumbnailtitle").css("left", position.left-titlewidth);
		},
		function(){
			$('.projectthumbnailtitle').show();
			//Black and white thumbnail
			var thumbsourceimg = $(this).attr("src");
			SplitName = thumbsourceimg.split("col.jpg");
			$(this).attr("src",SplitName[0]+".jpg");
		}
	);
	
	
	
	$(".thumbnailpicture").hover(function() {
			var thumbsourceimg = $(this).attr("src");
			SplitName = thumbsourceimg.split(".jpg");
			$(this).attr("src",SplitName[0]+"col.jpg");
			//alert("SplitName[0]+"col".jpg");
			$('.projectthumbnailtitle').show();
			var imagewidth = ($(this).width())/2;
			var offset = this.offsetLeft;
			var titleposition = offset - (imagewidth)/2;
			//alert(titlewidth);
			$('.projectthumbnailtitle').html('TOMORROW SQUARE MARRIOTT | SHANGHAI <span class="countryredbold" id="countryidprojects"> china</span>');
			$('.projectthumbnailtitle').css('margin-left',titleposition);

			}, 
					function() {
					var thumbsourceimg = $(this).attr("src");
					SplitName = thumbsourceimg.split("col.jpg");
					$(this).attr("src",SplitName[0]+".jpg");
					$(".projectthumbnailtitle").hide();
					$(".projectthumbnailtitle").stop(true, true);
		});
	*/
	
	
	//$("#americasmartatlanta").click(function(){
		
	//});
						   
	// lets figure out the height of the content pane on the left and set the height accordingly for the scrollbars, etc.
	//aH = (($(window).height())-($("#navigationblock").height() + $("#header").height() + 20));
	$("#leftcontentarea").css({"height":parseInt((($(window).height())-($("#navigationblock").height()+$("#header").height()+40)))});
	$("#leftcontentcontainer").css({"height":parseInt((($(window).height())-($("#navigationblock").height())))});
	
	
	
	// The thumbnail and list navigation for the projects page
	$("#thumbnailsscroll").css({"width":parseInt((($(window).width())-70))});
	$("#listscroll").css({"width":parseInt((($(window).width())))});
		//alert($("#thumbnailsscroll").css("width")+ "  common.js value");

	//$("#rightcontentcontainer").css({"height":parseInt(  (($(window).height())-($("#navigationblock").height() + $("#header").height()))  ),"width":parseInt(($(window).width()-425))});
	
	removeMe = parseInt($("#socialmedia").height()?$("#socialmedia").height():0);
	
	$("#rightcontentcontainer").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":parseInt( $(window).width()-$("#leftcontentcontainer").width())});
	
	
	// this will set the height of the project gallery image on load, only if the object exists!!
	if($("#projectgalleryimage")){
		
		
		//(function($) {
			//$(function() { //on DOM ready
				//$("#scroller").simplyScroll({
					//className: 'vert',
					//horizontal: false,
					//frameRate: 20,
					//speed: 10
				//});
			//});
		//})(jQuery);
		
		
		
		
		//alert("project gallery");
		$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
		//$(".vert").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":parseInt($(window).width())});
		//$(".vert .simply-scroll-clip").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":parseInt($(window).width())});
		//$("#scroller").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
		//$("#projectgalleryimage").css({"height":"100%"});
		
		
		
		
		
		
	//Calculate the gallery image scrolling		
	/*	$("#panner").hover(function(event){
			//alert(triggermousestop);
			mouseRatio = parseInt(  parseInt($("#projectgalleryimage").height()) /  parseInt($("#panner").height()) );
			imageTop = parseInt( ((event.pageY-50) * -1) * mouseRatio);
			$(this).mousemove(function(event) {
				mouseY = parseInt((event.pageY));
				imageTop = parseInt( (mouseY * -1) * mouseRatio);
				//New shot at trying to stop the scroll from going too far down past an image. Stop @ bottom
				//How close are we to seeing the bottom of the image. Image height Minis (Plus a negaive) how much we've already scrolled
				var closetobottom =  parseInt($("#projectgalleryimage").height()) + parseInt($("#projectgalleryimage").css("margin-top"));
				//Height of the visible gallery area
				var gallerywindow = parseInt($("#panner").height()-100);
				//alert(firsthover);
				var findthebottom = parseInt($("#panner").height()-100) + (imageTop*-1);
				//alert(ab);
				//if(findthebottom>=parseInt($("#projectgalleryimage").height())){
				//	alert("Test");
				//}
				
				
				//alert(firsthover);
					if(findthebottom>=parseInt($("#projectgalleryimage").height())){
						
						if(triggermousestop==0){
							mousestop = mouseY;
							triggermousestop = 1;
							}
						if(mouseY<mousestop){//if you're going up
							$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
							
						}else{//We're going down around or anywhere BUT up
						
							//kick back, relax, and do nothing
							}
					}else{//We're not at the bottom, scroll away!
						$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
						triggermousestop = 0;
						}
			  	currentY = mouseY;
			});
			
		},function(){
			currentY = mouseY;
			$('#panner').unbind('mousemove');
		});
		
		
		
		
		*/
		$("#panner").hover(function(event){
			//alert($("#projectgalleryimage").height());
			// need to determine the ratio that we will be moving the image at
			mouseRatio = parseInt(  parseInt($("#projectgalleryimage").height()) /  parseInt($("#panner").height()) );
			//alert($("#projectgalleryimage").css("bottom"));
			//alert(mouseRatio);
			// now we need to jump to the location there mouse it at immediately
			imageTop = parseInt( ((event.pageY-50) * -1) * mouseRatio);
			//alert(imageTop);
			//$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
			$(this).mousemove(function(event) {
				mouseY = parseInt((event.pageY-50));
				//alert(mouseY)
				//var direction = "";
				//if(parseInt(mouseY) <= parseInt(currentY)){
					//mouseDirection = "-";
				//alert("Test")	
					//imageTop = parseInt( (mouseY * -1) * mouseRatio);
					
				//}else{
					//mouseDirection = "+";
					
					//imageTop = parseInt( (mouseY * -1) * mouseRatio);
				//}
				imageTop = parseInt( (mouseY * -1) * mouseRatio);
				//alert(imageTop);
				var closetobottom =  parseInt($("#projectgalleryimage").height()) + parseInt($("#projectgalleryimage").css("margin-top"));
				//Height of the visible gallery area
				var gallerywindow = parseInt($("#panner").height()-100);
				
					if(parseInt($("#projectgalleryimage").css("margin-top")) < 1500){
								$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
							}
						
			});
			
		},function(){
			currentY = mouseY;
			$('#panner').unbind('mousemove');
		});
		
		
		
		
		
		
		
		
		
		
		/*$("#panup").hover(function(){
			//alert('pan up');
			//$("#projectgalleryimage").css({"margin-top":"-100px"});
			
			//function panImage(a){
			//$("#projectgalleryimage").css({"margin-top":parseInt($("#projectgalleryimage").css("margin-top")-100)});
			panImage('up');
			
			//panImage('up');
		},function(){
				clearTimeout(imagePanner);
	
		});
		
		
		$("#pandown").hover(function() {
			panImage('down');
			}, 
					function() {
					clearTimeout(imagePanner);
	});*/
		
		
	}
	
	// if we are hovering over the project gallery iamge, and it is not full width, we want to change to a zoom mouse icon
	if(parseInt($("#projectgalleryimage").width()) < parseInt( $(window).width()-$("#leftcontentcontainer").width())){
		$("#projectgalleryimage").attr("title","Click to zoom image | 迅速移动的点击图象");
		$("#panner").attr("title","Click to zoom image | 迅速移动的点击图象");
		$("#projectgalleryimage").hover(function() {
				//var thissocialicon = $(this).attr("src");
				//SplitName = thissocialicon.split("bw.png");
				//$(this).attr("src",SplitName[0]+".png");
				$(this).css({"cursor":"pointer"});
			}, 
			function() {
				//var thissocialicon = $(this).attr("src");
				//SplitName = thissocialicon.split(".png");
				//$(this).attr("src",SplitName[0]+"bw.png");
				$(this).css({"cursor":"default"});
		});
		
		// hover on the zoom out
		$("#zoomout").hover(function() {
				//var thissocialicon = $(this).attr("src");
				//SplitName = thissocialicon.split("bw.png");
				//$(this).attr("src",SplitName[0]+".png");
				$(this).css({"cursor":"pointer"});
			}, 
			function() {
				//var thissocialicon = $(this).attr("src");
				//SplitName = thissocialicon.split(".png");
				//$(this).attr("src",SplitName[0]+"bw.png");
				$(this).css({"cursor":"default"});
		});
		
		// now if they click the image we need to fit it to the width of the page
		$("#projectgalleryimage").click(function(){
			//if(sizeBy == "height"){
				$("#projectgalleryimage").css({"height":"auto","width":parseInt($(window).width())});
				sizeBy = "width";
				//$("#zoomout").show();
				$(".panbutton").show();
				$("#projectgalleryimage").attr("title","Click here to zoom out | 点击这里迅速移动 ");
				$("#panner").attr("title","Click here to zoom out | 点击这里迅速移动 ");
				//$("#projectgalleryimage").css({"cursor":"pointer"});
				//$(".simply-scroll-btn").show();
				
				//$("#scrollthis").css({"height":parseInt($("#projectgalleryimage").height()),"width":parseInt($(window).width())});
				//$("#scrollthis").css({"height":parseInt($("#projectgalleryimage").height()),"width":parseInt($(window).width())});
				//alert($("#scrollthis").height());
				//$('#projectgalleryimage').unbind('click');
			/*}else{
				$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
				sizeBy = "height";
				//$("#zoomout").hide();
				//$(".simply-scroll-btn").hide();
				$(".panbutton").hide();
				$("#projectgalleryimage").css({"margin-top":"0px"});
				$("#projectgalleryimage").attr("title","Click to zoom image");
				$('#projectgalleryimage').unbind('click');
			}*/
			
		});
		//ZOOMING OUT of the panning in the gallery page zoom
		$("#panner").click(function(){
			//Reset the mouse y stop check
			var triggermousestop = 0;
			//alert(triggermousestop);
			var mousestop = 0;
			$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
			sizeBy = "height";
			//alert("Test");
			//$("#zoomout").hide();
			//$(".simply-scroll-btn").hide();
			
			$(".panbutton").hide();
			$("#projectgalleryimage").css({"margin-top":"0px"});
			$("#projectgalleryimage").attr("title","Click to zoom image | 迅速移动的点击图象");
			//$("#projectgalleryimage").css({"cursor":"pointer"});
		});
	}
	
	
	// are we on the portman companies page?
	if($(".companylink").height()){	
		//This bit here overrides the td padding set at the top for project descriptions
		$('.companylink').css({"padding":"0 0 0 10px","background-color":"#000"})	
		h = parseInt(  (($(window).height()-(($("#navigationblock").height()+($("#header").height()-15))-removeMe))/2)  );
		w = parseInt(($(window).width()-$("#leftcontentcontainer").width())/2);
		$(".companylink").each(function(){
			$(this).find('img').css({"height":h,"width": w});
			$(this).css({"height":h,"width": w});
		});
	}
	
	
	// start the scrollbars now that we know the height ofthe content pane
	//$('.scroll-pane').jScrollPane();
	//$('#readmore').jScrollPane();
	
	//If the thumbnailscroll div exists 
	if($("#thumbnailsscroll").size() > 0){
		//alert("Initial Post");
		//Figure out how many we need and send this to php
		var spaceavailable = ($("#thumbnailsscroll").width());
		var spaceforeach = 160//$(".thumbnailpicture").width();
		var howmanyfit = Math.floor(spaceavailable / spaceforeach);
		var howmanyfitlist = Math.floor(spaceavailable / 448);
		//var howmanyflitlistitems= ( Math.floor(spaceavailable/448)*4); 
		var howmanyflitlistitems= ( Math.floor(spaceavailable/280)*4);
		var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach));
			//var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach))
		//var emptyspace = 10;
		//alert(emptyspace);
		//make sure list is empty
		$("#loadedthumbnails").empty(); //Emty the thumbnail div
		//Check if the list view is even on the page
		//load list
		$.post("listdata.php", { howmanyfit: howmanyfit}, function(data) {
		$("#loadedlist").append(data); }); 
		//$();.css("width","")
		//load thumbnails
		
		$.post("thumbnails.php", { howmanyfit: howmanyfit, "emptyspace":emptyspace, "spaceavailable":spaceavailable}, function(data) {
		$("#loadedthumbnails").append(data); }); 
		//load thumbnails for the projects section
		//starting values for the state of the left and right arows for the project page 
		var rightstatus = "on"
		var leftstatus = "off";
	}
		
		
	
		
					   
	// handle mousing over the main nav items
	$(".navitem").hover(
		function(){
			skipMe = false;
			if($(this).attr("src").indexOf("_on") >= 0){
				skipMe = true;
			}else{
				$(this).attr("src",$(this).attr("src").replace("_off","_on"));
			}
		},
		function(){
			if(skipMe == false){
				$(this).attr("src",$(this).attr("src").replace("_on","_off"));
			}
		}
	);










// this function will handle clicking either the next/previous arrows for the gallery as well as jumping to a specific array element
$("#rightsideshowarrow").click(function() {
	//Reset the mouse y stop check
	var triggermousestop = 0;
	//alert(triggermousestop);
	var mousestop = 0;
	//This will zoom us back out on the new image
	$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
			sizeBy = "height";
			$(".panbutton").hide();
			$("#projectgalleryimage").css({"margin-top":"0px"});
			$("#projectgalleryimage").attr("title","Click to zoom image | 迅速移动的点击图象");
	//Goes to next image, or start if we're at the end
	if((parseInt($("#projectgallery").attr('rel'))+1)<=parseInt($("#projectbiggallery").attr('rel'))){
		val = (parseInt($("#projectgallery").attr('rel'))+1);
	}else{
		val = 0;
	}
	$("#projectgallery").attr('rel',val);
	projectGallerySwap(val);
});	





//Small Arrows on projects page

$(".leftsmallarrow").hover(
		function(){
			$(this).attr("src","_images/smallarrows/leftred.jpg");
		},
		function(){
			$(this).attr("src","_images/smallarrows/leftblack.jpg");
		}
	);
	
	$(".rightsmallarrow").hover(
		function(){
			$(this).attr("src","_images/smallarrows/rightred.jpg");
		},
		function(){
			$(this).attr("src","_images/smallarrows/rightblack.jpg");
		}
	);

	










$("#leftslideshowarrow").click(function() {
	//Reset the mouse y stop check
	var triggermousestop = 0;
	var mousestop = 0;
	//zoom out on new image
	$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
			sizeBy = "height";
			//$("#zoomout").hide();
			//$(".simply-scroll-btn").hide();
			$(".panbutton").hide();
			$("#projectgalleryimage").css({"margin-top":"0px"});
			$("#projectgalleryimage").attr("title","Click to zoom image | 迅速移动的点击图象");
		//Changes image and checks if we're at the end
	if((parseInt($("#projectgallery").attr('rel'))-1)>=0){
		val = (parseInt($("#projectgallery").attr('rel'))-1);
	}else{
		val = parseInt($("#projectbiggallery").attr('rel'));
	}
	$("#projectgallery").attr('rel',val);
	projectGallerySwap(val);
});	




	

//Thumbnail hover tooltips for the projects page

	$(".emptyBox").hover(
		function(){
			var thisboxid = parseInt($(this).attr("rel"));
			//splitboxname = thisboxid.split("project");
			var thumbnailpic = galleryImages[thisboxid];
			var position = $(this).position();
			$(".imagepreviewpic").attr("src", thumbnailpic);
			$(".imagepreview").css("left", position.left-47);
			$(".imagepreview").show(); 
			$(this).addClass("hoverBox");
		},
		function(){
			$(".imagepreview").hide();
			$(this).removeClass("hoverBox");
			$(".imagepreviewpic").attr("src", "_images/blank.png");
		}
	);
	
	
	
	
	// this will swap the gallery image when clicked
	$(".emptyBox").click(function(){
		$(".emptyBox").each(function(){
			$(this).removeClass("hoverBox");
			$(this).removeClass("currentBox");
		});
		$(this).addClass("currentBox");
		$("#projectgallery").attr('rel',parseInt($(this).attr("rel")));
		projectGallerySwap(parseInt($(this).attr("rel")));				  
	});
		
	
	//Alert for Project Video
	$("#projectvideo").click(function() {
	  alert('A video will popup here.');
	});

});





		// a = direction to pan
		function panImage(a){
			//alert($("#projectgalleryimage").css("margin-top"));
			if(a == 'up'){
				var imageTop = (parseInt($("#projectgalleryimage").css("margin-top")) - 20);
				
				if(parseInt(imageTop * -1) < parseInt(  $("#projectgalleryimage").height()-(parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ))  )){
					$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
					imagePanner = setTimeout("panImage('up');",100);
				}
			}else{
				var imageTop = (parseInt($("#projectgalleryimage").css("margin-top")) + 20);
				if(parseInt(imageTop * -1) > 0){
					$("#projectgalleryimage").css({"margin-top":imageTop+"px"});
					imagePanner = setTimeout("panImage('down');",100);
				}
			}
			
		}






function rightprojectnav(){ 
			var spaceavailable = ($("#thumbnailsscroll").width()) 
			var spaceforeach = 160//$(".thumbnailpicture").width();
			var howmanyfit = Math.floor(spaceavailable / spaceforeach)
			if(spaceavailable - (howmanyfit*spaceforeach) > 150 ){
				var emptyspace = -1;
			}else{
				var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach))
			}
			//var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach))
   			var howmanyfitlist = Math.floor(spaceavailable / 448);
			//var howmanyflitlistitems= ( Math.floor(spaceavailable/448)*4);
			var howmanyflitlistitems= ( Math.floor(spaceavailable/280)*4); 
	
						if($("#thumbnailView").hasClass('active')){
						//only post to thumbnail page
						//alert(rightprojectnav);	
							var lastpic = parseInt($(".thumbnailpicture").last().attr('id'));
							var leftoff=lastpic;
							$.post("thumbnails.php",{"leftoff":leftoff,"howmanyfit":howmanyfit, "emptyspace":emptyspace, "spaceavailable":spaceavailable},function(data){
								$("#loadedthumbnails").html(data);});
						}else{
						//Only post to list	 
							var lastlist = parseInt($(".listitem").last().attr('id'));
							var leftofflist=lastlist+1;
							$.post("listdata.php",{"leftofflist":leftofflist,"howmanyfitlist":howmanyflitlistitems},function(data){
								$("#loadedlist").html(data);});
					 	}
			};
			
function leftprojectnav(){ 
			var spaceavailable = ($("#thumbnailsscroll").width()) 
			var spaceforeach = 160//$(".thumbnailpicture").width();
			var howmanyfit = Math.floor(spaceavailable / spaceforeach)
			var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach))
			//var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach))
			var howmanyfitlist = Math.floor(spaceavailable / 448);
			//var howmanyflitlistitems= ( Math.floor(spaceavailable/448)*4); 
			var howmanyflitlistitems= ( Math.floor(spaceavailable/280)*4);
						if($("#thumbnailView").hasClass('active')){
						//only post to thumbnail page	
							var firstpic = $(".thumbnailpicture").first().attr('id');
							var startingpic = firstpic - howmanyfit;
							
							if(startingpic<=0){
								var leftoff=0;
							}else{
								var leftoff=startingpic;
							}
							//alert(howmanyfit);
							//alert(leftprojectnav)

							$.post("thumbnails.php",{"leftoff":leftoff,"howmanyfit":howmanyfit, "emptyspace":emptyspace},function(data){
								$("#loadedthumbnails").html(data);});
						}else{
						//Only post to list	 
							var firstlist = $(".listitem").first().attr('id');
							var startinglist = (parseInt(firstlist) - parseInt(howmanyflitlistitems));
							if(startinglist<=0){
								var leftofflist=0;
							}else{
								var leftofflist=startinglist;
							}
							
							$.post("listdata.php",{"leftofflist":leftofflist,"howmanyfitlist":howmanyflitlistitems},function(data){
								$("#loadedlist").html(data);});
					 	}
			};



// this function will run whenever the window is re-sized
$(window).resize(function(){
						  
	if($("#leftcontentarea").size() > 0){
		clearTimeout(resizeLeftTimer);
		resizeLeftTimer = setTimeout("resizeLeft()",50);
	}					  
	
	if($("#thumbnailsscroll").size() > 0){
		clearTimeout(resizeTimer);
		resizeTimer = setTimeout("resizeList()",500);
	}
					
						  
						  
	//$("#leftcontentarea").css({"height":parseInt(  (($(window).height())-($("#navigationblock").height() + $("#header").height() + 40))  )});
	//$("#leftcontentcontainer").css({"height":parseInt( (($(window).height())-($("#navigationblock").height())) +20)});
	//if($(".biocontent").width()){
		//$(".biocontent").css({"height":parseInt(  (($(window).height())-($("#navigationblock").height() + $("#header").height() + 100))  )});
	//}
	
	// The thumbnail and list navigation for the projects page
	if($("#thumbnailView").hasClass("active")){
		$("#thumbnailsscroll").css({"width":parseInt((($(window).width())-70))});
	}else{
		//$("#thumbnailsscroll").css({"width":parseInt((($(window).width())))});
		$("#thumbnailsscroll").css({"width":parseInt((($(window).width())-80))});
	}
		

	//$("#listscroll").css({"width":parseInt((($(window).width())-80))});
	//alert($("#thumbnailsscroll").css("width")+ "  common.js value");
		
	//Figure out how many we need and send this to php
	/*
	$("#loadedthumbnails").empty(); //Emty the thumbnail div*/
	//var spaceavailable = ($("#thumbnailsscroll").width()) 
	//var spaceforeach = 160//$(".thumbnailpicture").width();
	//var howmanyfit = Math.floor(spaceavailable / spaceforeach)
	//var howmanyfitlist = Math.floor(spaceavailable / 200);
	//var howmanyflitlistitems= ( Math.floor(spaceavailable/230)*4); 
	//alert (howmanyfitlist);
	
	/*
	$("#loadedthumbnails").empty(); //Emty the thumbnail div*/
	
	//if($("#thumbnailView").hasClass("active")){
	//	var leftoff = parseInt($(".thumbnailpicture").first().attr('id'));
	//	$.post("thumbnails.php", { "howmanyfit": howmanyfit, "leftoff":leftoff }, function(data) {
	//	$("#loadedthumbnails").html(data); }); 
	//}else{
	//	var leftofflist = parseInt($(".listitem").first().attr('id'));
	//	$.post("listdata.php", { "leftofflist":leftofflist,"howmanyfitlist": howmanyflitlistitems }, function(data) {
	//	$("#loadedlist").html(data); });
	//}
	
	
				
	
	removeMe = parseInt($("#socialmedia").height()?$("#socialmedia").height():0);
	
	$("#rightcontentcontainer").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":parseInt( $(window).width()-$("#leftcontentcontainer").width())});
	
	// are we on the portman companies page?
	if($(".companylink").height()){		
		h = parseInt(  (($(window).height()-(($("#navigationblock").height()+($("#header").height()-15))-removeMe))/2)  );
		w = parseInt(($(window).width()-$("#leftcontentcontainer").width())/2);
		$(".companylink").each(function(){
			$(this).find('img').css({"height":h,"width": w});
			$(this).css({"height":h,"width": w});
		});
	}
	
	
	// this will set the height of the project gallery image on load, only if the object exists!!
	if($("#projectgalleryimage").height() || $("#projectgalleryimage").width()){
		//alert("project gallery");
		
		//alert($("#projectgalleryimage").width()+" | "+$(window).width());
		// we need to know if they are zoomed in or not so things size accordingly
		if(sizeBy == "width"){
			//alert($("#projectgalleryimage").height());	
			$("#projectgalleryimage").css({"height":"auto","width":parseInt( $(window).width())});	
		}else{
			$("#projectgalleryimage").css({"height":parseInt(  ( $(window).height()-(( $("#navigationblock").height() + ($("#header").height()-15) ) - removeMe ) )  ),"width":"auto"});
		}
	}
	
});



// this function will check the number of projects listed on the screen and adjust after user is done resizing the window
function resizeList(){
	//alert("this is a test");	
	
	//Fire the functions that check where the previous and last arrows go
	//rightprojectnav();
	//leftprojectnav();
	//alert("Test");
	var spaceavailable = ($("#thumbnailsscroll").width()) 
	var spaceforeach = 160//$(".thumbnailpicture").width();
	var howmanyfit = Math.floor(spaceavailable / spaceforeach)
	var howmanyfitlist = Math.floor(spaceavailable / 448);
	//var howmanyflitlistitems= ( Math.floor(spaceavailable/448)*4);
	var howmanyflitlistitems= ( Math.floor(spaceavailable/280)*4);
	var emptyspace = Math.floor(spaceavailable - (howmanyfit*spaceforeach)) ;
	var spaceavailable = ($("#thumbnailsscroll").width());
	//alert (howmanyfitlist);
	
	
	if($("#thumbnailView").hasClass("active")){
		var leftoff = parseInt($(".thumbnailpicture").first().attr('id'));
		//alert("Resized Post")
		$.post("thumbnails.php", { "howmanyfit": howmanyfit, "leftoff":leftoff, "emptyspace":emptyspace, "spaceavailable":spaceavailable }, function(data) {
		$("#loadedthumbnails").html(data); }); 
	}else{
		var leftofflist = parseInt($(".listitem").first().attr('id'));
		$.post("listdata.php", { "leftofflist":leftofflist,"howmanyfitlist": howmanyflitlistitems }, function(data) {
		$("#loadedlist").html(data); });
	}
	
	
	
}
	
	
function resizeLeft(){
		$("#leftcontentarea").css({"height":parseInt(  (($(window).height())-($("#navigationblock").height() + $("#header").height() + 40))  )});
		$("#leftcontentcontainer").css({"height":parseInt( (($(window).height())-($("#navigationblock").height())) +20)});	
	}
		
	
	
// this function will set the background image
// a = the image to be shown
/*function setBackground(a){
	$(function(){
		$.fn.supersized.options={  
			startwidth:1920,  
			startheight:1080,
			vertical_center:1,
			slides:[{image:a}]
		};
		$('#supersized').supersized();
	});
}*/


// this function will obscure email addresses from spam bots
function jemail(user, domain, suffix, linkText, cssClass){
	var cssText = "";
	if(cssClass){
		cssText = ' class="'+cssClass+'"';
	}
	if(linkText){
		document.write('<a href="'+'mailto:'+user+'@'+domain+'.'+suffix+'"'+cssText+' title="click here to send us an email">'+linkText+'</a>');
	}
	else{
		document.write('<a href="'+'mailto:'+user+'@'+domain+'.'+suffix+'"'+cssText+' title="click here to send us an email">'+user+'@'+domain+'.'+suffix+'</a>');
	}
}


// this function will set the language as selected by the visitor
// a = the language they would like to view the site in
// b = the page they were on
function setLanguage(a,b){
	$.post("_libraries/php/setlanguage.php",{language:a},
		function(data){
			if(data == "true"){
				location.href=b;
			}else{
				alert('An error has occured while changining your language.\n\nPlease try again.');
			}
		}
	);
}


// this function will allow a user to read more when viewing news, etc.
// a = the portion of the site that we are working with
// b = the id of the item that they want to see
function readMore(a,b,c){
	
	// we also want this function to be able to close an item that is currently being read by a user...need to check which state we are in
	if(a && b){
		if(c){
			$("#readmore").attr("title",c[1]);	
		}
		$('#readmore').load('_libraries/php/'+a+'_item.php?id='+b,function(){$("#newsitems").fadeOut(200); $("#mailinglist").hide(); $("#readmore").fadeIn(200); $(".readmorepdf").show(); $(".readmoreclose").show();});
		$(".addthis_button").fadeIn(200);

		
		// $('.scroll-pane').scrollToY(0);
		
		if(c){
			//alert($('#supersized').html());
			$('#supersized').empty();
			//$('#supersized').unbind();
			$(function(){
				$.fn.supersized.options = {  
					startwidth:1280,  
					startheight:720,
					vertical_center:1,
					slides:[
						{image:c[0],title:''}					
					]
				};
				$('#supersized').fadeOut(250,function(){$('#supersized').supersized(); $('#supersized').fadeIn(250);});
				//$('#supersized').supersized(); 
				//alert($('#supersized').html());
			});
		}
		
	}else{
		if($("#readmore").attr("title") != ""){
			//alert($('#supersized').html());
			$('#supersized').empty();
			//$('#supersized').unbind();
			$(function(){
				$.fn.supersized.options = {  
					startwidth:1280,  
					startheight:720,
					vertical_center:1,
					slides:[
						{image:$("#readmore").attr("title"),title:''}					
					]
				};
				$('#supersized').fadeOut(250,function(){$('#supersized').supersized(); $('#supersized').fadeIn(250);});
				//$('#supersized').supersized(); 
				//alert($('#supersized').html());
			});
		}
		$(".addthis_button").fadeOut(200);
		$("#readmore").fadeOut(200);
		$(".readmorepdf").hide();
		//$(".readmoreclose").hide();
		$("#newsitems").fadeIn(200);
		$("#mailinglist").show();
		
		
	}
	
	
	
	//This modifies the JScrollPane plugin so when we click on an item, the content scrolls/resets to the top
	//var element = $('#my-element').jScrollPane({/* ...settings... */});
	//var api = element.data('jsp');

	 
	 // this function also needs to be able to set the image on the right to be whatever (if anything) was uploaded or keep the regular image
	
	//$("#newsitems").css({'display':'none'});
	//$("#readmore").css({'display':'block'});
	
}



//This version of readmore focuses specifically on the map functions
function mapControl(a){
	//alert(a);
	// we also want this function to be able to close an item that is currently being read by a user...need to check which state we are in
	if(a){
		$('#projectlist').load('_libraries/php/country_item.php?cid='+a,
		function(){$("#countrylistmapcontrol").fadeOut(200); 
					$("#projectlist").fadeIn(200); 
					$("#returnglobe").show(); 
					});
					$('#zoomablemap').animate({'width':'3500px','height':'2800px','margin-top':y,'margin-left':x},2000);
	}else{
		$("#projectlist").fadeOut(200);
		$("#returnglobe").hide();
		$("#countrylistmapcontrol").fadeIn(200);
		//alert("Zoom out");
		$('#zoomablemap').animate({'width':'1280px','height':'720px','margin-top':0,'margin-left':0},2000);

		
		
	}
}


function styalizeli(){
		$('li').each(function(index) {
			//alert("test");
			$(this).addClass("careerli");
		});
	}
	
//This version of readmore focuses specifically on the Career Opportunities
function careerDetails(a){
	if(a){
		$('#readmore').load('_libraries/php/job_item.php?id='+a,function(){
				$("#newsitems").fadeOut(200); 
				$("#mailinglist").hide(); 
				$("#readmore").fadeIn(200); 
				$(".readmorepdf").show();
				$(".readmoreclose").show();
				styalizeli();
	
			});
		var newsid = a;
		$("#newspermalink").fadeIn(200);
		$(".addthis_button").fadeIn(200);
		$(".permalinktitle").fadeIn(200);
	}else{
		$(".permalinktitle").fadeOut(200);
		$("#newspermalink").fadeOut(200);
		$(".addthis_button").fadeOut(200);
		$("#readmore").fadeOut(200);
		$(".readmorepdf").hide();
		$("#newsitems").fadeIn(200);
		$("#mailinglist").show();
	}
}


// this function will handle going to the next or previous or specific image on the project gallery page
// a = the position in the arry that we wish to jump to
function projectGallerySwap(a){
	//alert(galleryImages[a]);
	$("#projectgalleryimage").css({"margin-top":"0px"});
	
	// need to look in the array and grab the corresponding image
	
	//$("#projectgalleryimage").attr("src","_uploads/projects/tomorrowsquare/"+a+".jpg");
	$("#projectgalleryimage").attr("src",galleryImages[a]);
	$("#projectgalleryimage").attr("alt",galleryAlts[a]);
	$(".emptyBox").each(function(){
		if(parseInt($(this).attr("rel")) != a){
			$(this).removeClass("hoverBox");
			$(this).removeClass("currentBox");
		}else{
			$(this).addClass("currentBox");
		}
	});
	//$(this).addClass("currentBox");*/
	//$('.emptyBox').attr('rel',a).addClass("currentBox");
	
	
	//$("#projectgalleryimage").attr("src","_uploads/projects/tomorrowsquare/"+a+".jpg");
	//for(i=0;i<=parseInt($("#projectbiggallery").attr('rel'));i++){
		
	//}
	
}

/*$('.thumbnailpicture').bind('mouseenter', function() {
  		alert('User clicked on "foo."');
	});*/
	
	//$('#returnglobe').fadeIn(100);
	//$.post('country.php',{country:$(this).attr('id')},function(data){$('#leftcontentarea').html(data);});

