var fadeTime = 2000;
var timeOn = 5000;
var t;

$(document).ready(function(){
     // slideshow panel right
	 var t = setTimeout("panelleftslideshow()",timeOn);
     // set width of photo list (for carousel)
	 var $photoWidth = 425;
	 var $nbOfPhoto = $("#photo-nb a").length;
	 $("#container ul").css("width",$photoWidth*$nbOfPhoto+"px");
     // show / hide conctacts
     $("#contact").mouseover(function(){
	     $(this).css("width","425px");
	     $(this).css("border","1px solid #999999");
	     $(this).css("background","#4c4c4c");
	     $(this).find("#trigger span").css("border","none");
	     $(this).find("#trigger span").css("margin-top","2px");
	     $(this).find(".cache").css("display","block");
		 $("#photo-nb").css("display","none");
	 });
     $("#contact").mouseout(function(){
	     $(this).css("width","50px");
	     $(this).css("border","none");
	     $(this).css("background","none");
	     $(this).find("#trigger span").css("border","1px solid #999999");
	     $(this).find("#trigger span").css("margin-top","3px");
	     $(this).find(".cache").css("display","none");
		 $("#photo-nb").css("display","block");
	 });
	 // enlarge photo
     // show enlarge button if javascript on
	 $("#container ul li a").css("display","block");
	 $("#container ul li a").css("opacity","0.6");
	 $("#container ul li a").click(function(){
	     $("#overlay").css("display","block");
	     $("#overlay").css("opacity","0.6");
	     $("#overlay").css("height",getWindowHeight()+"px");
	     $("#overlaycontent").fadeIn("slow"); 
		 var $largePhotoWidth = $("#overlaycontent").width()-10;
		 var $largePhotoHeight = $("#overlaycontent").height()-10;
		 if(getWindowWidth()>$largePhotoWidth)
		 {
			$("#overlaycontent").css("left",(((getWindowWidth()-$largePhotoWidth)/2)-20)+"px");
		 }	
		 if(getWindowHeight()>$largePhotoHeight)
		 {
			$("#overlaycontent").css("top","5px");
		 }
		 var $oTop = $("#overlaycontent").css("top");
		 $("#overlaycontent").css("top",(parseInt($oTop)+$(window).scrollTop())+"px");
		 $("#overlaycontent a").css("margin-left",($largePhotoWidth-50)+"px");
		 // close button
		 $("#overlaycontent a").click(function(){ 
			$("#overlay").css("display","none");
			$("#overlaycontent").css("display","none");
			return false;
		 });
		 return false;
	 });
	 // window open for floor plan
	 $("#photo-nb a:last").click(function(){
	     var $href = $(this).attr("href");
		 window.open($href);
		 return false;
	 });	 
	 // window open for brochure
	 $("#buildings-to-sell td a").click(function(){
	     var $href = $(this).attr("href");
		 window.open($href);
		 return false;
	 }); 
	 // window open for 4cast
	 $("#fin-tech td a").click(function(){
	     var $href = $(this).attr("href");
		 window.open($href);
		 return false;
	 });
	 // carousel
	 $("#photo-nb a").click(function(){
	     var $index = $("#photo-nb a").index(this);
		 if($index<$nbOfPhoto-1)// so that doesn't apply to floor plan link 
	     {
			$("#container ul").animate({"left":(-$photoWidth*$index)+"px"});
			var $linkToPhotoLarge = $("#container ul li img:eq("+$index+")").attr("src");
			$linkToPhotoLarge = $linkToPhotoLarge.split(".jpg");
			$linkToPhotoLarge = $linkToPhotoLarge[0]+"_large.jpg"+$linkToPhotoLarge[1];
			$("#overlaycontent>img").attr("src",$linkToPhotoLarge);
			$("#photo-nb a").removeClass();
			$(this).addClass("select");
			return false;
		}
	 });
});


function panelleftslideshow()
{
    var $img1 = $("#contentgraphic div:eq(0) img");
    var $img2 = $("#contentgraphic div:eq(1) img");
    	 
	if($img1.is(':hidden'))
	{
		$img1.fadeIn(fadeTime);
		$img2.fadeOut(fadeTime);
	}
	else
	{
	    $img1.fadeOut(fadeTime);
	    $img2.fadeIn(fadeTime);
	}
	t = setTimeout("panelleftslideshow()",timeOn);
}

function showPhoto(im)
{
	im.fadeIn(fadeTime);
}

function hidePhoto(im)
{
	im.fadeOut(fadeTime);
}

function getWindowWidth() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getWindowHeight() {
  var myHeight = 0
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
