function fProject(nProjectID,sTitle){
	this.nProjectID=nProjectID;
	this.sTitle=sTitle;
}

function fProjectImage(nImageID,nProjectID,sTitle,sThumb,sImage,sVideo){
	this.nImageID=nImageID;
	this.sTitle=sTitle;
	this.nProjectID=nProjectID;
	this.sThumb=sThumb;
	this.sImage=sImage;
	this.sVideo=sVideo;
}


 function fOpenProject(nProjectIndex,bInfo,nPozTop){
	var arrPreloadImg=[]

	$("#oLBTitle").html(arrWorks[nProjectIndex].sTitle)
	$("#oLBControlls").html("<img src=\"/images/btn_Portfolio_off.gif\" alt=\"Project Gallery\" onclick=\"fShowProjectGallery(true);\" /><img src=\"/images/btn_Info_off.gif\" alt=\"Project Info\" onclick=\"fShowProjectInfo(true);\" />")
	$("#oLBGallery").html("")
	
	var count=0, nFirst=null
	for(var x=0; x<arrImages.length; x++){
		if(arrImages[x].nProjectID==arrWorks[nProjectIndex].nProjectID && count<8){
			if(!nFirst && nFirst!=0) nFirst=x
			count++
			$("#oLBGallery").append("<div id=\"oThumb"+ x +"\" class=\"clsThumb"+ (arrImages[x].sVideo?" clsThumbVideo":"") +"\" onclick=\"fPlayItem("+x+",true)\"><img src=\""+ arrImages[x].sThumb +"\" alt=\"\" /><img src=\"images/icon_play.png\" alt=\"\" class=\"clsVideoIcon\" /></div>")
			if(count!=4 && count!=8) $("#oLBGallery").append("<div class=\"clsSpacer\"></div>")
			
			arrPreloadImg.push(SITE_DOMAIN + arrImages[x].sImage);
		}
	}
	
	$.preloadImages.add(arrPreloadImg);
	$.preloadImages.start('project-images')

	$("#oLBInfoText").html($("#oMoreInfo"+ nProjectIndex).html())

	fPopupLayer("",false,nPozTop)
	
	if(bInfo){
		if(nFirst || nFirst==0) fPlayItem(nFirst, false)
		fShowProjectInfo(false)
	}
	else{
		if(nFirst || nFirst==0) fPlayItem(nFirst, true)
		fShowProjectGallery(false);
	}
 }
 
 var sCurrDisplayedTab=""
 
 function fShowProjectInfo(bAnimate){
	if(sCurrDisplayedTab=="info")return;
	sCurrDisplayedTab="info"
	$("#oLBControlls img:first").attr("src","/images/btn_Portfolio_off.gif");
	$("#oLBControlls img:last").attr("src","/images/btn_Info_on.gif");
	
	var nInfoHeight=0;
	if(bAnimate){
		$("#oLBGallery").fadeOut("fast",function(){
			$("#oLBInfo").fadeIn("fast",function(){
				nInfoHeight=$("#oLBInfoText").outerHeight();
				$("#oLBInfo").animate({height:nInfoHeight}, 800)
			})
		})
	}
	else{
		$("#oLBGallery").hide()
		$("#oLBInfo").show()
		nInfoHeight=$("#oLBInfoText").outerHeight();
		$("#oLBInfo").css("height",nInfoHeight);
		
	}
 }
 
function fShowProjectGallery(bAnimate){
	if(sCurrDisplayedTab=="gallery"){return;}
	sCurrDisplayedTab="gallery"
	$("#oLBControlls img:last").attr("src","/images/btn_Info_off.gif");
	$("#oLBControlls img:first").attr("src","/images/btn_Portfolio_on.gif");
	
	if(bAnimate){
		$("#oLBInfo").animate({height:215}, 400, function(){
			$("#oLBInfo").fadeOut("fast",function(){$("#oLBGallery").fadeIn("fast")})
		})
	}
	else{
		$("#oLBInfo").hide()
		$("#oLBGallery").show()
		$("#oLBInfo").css("height","215px");
	}
}

function fFlashMovie(sImageUrl, sVideoUrl, bPlay){
	var sAutoPlay=(bPlay?"true":"false");
	var str='<object id="oFlashMovie" width="755" height="460" swLiveConnect="true" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'
	str+='<param name="movie" value="/flash/player5.swf">';
	str+='<param name="allowFullScreen" value="true" />';
	str+='<param name="wmode" value="transparent" />';
	str+='<param name="bgcolor" value="#000000" />';
	str+='<param name="quality" value="high">';		
	str+='<param name="flashvars" value="file='+ sVideoUrl +'&autoplay='+ sAutoPlay +'&pic='+ sImageUrl +'">';
	str+='<embed id="oFlashMovie" src="/flash/player5.swf" width="755" height="460" allowFullScreen="true" bgcolor="#000000" flashvars="file='+ sVideoUrl +'&autoplay='+ sAutoPlay +'&pic='+ sImageUrl +'" wmode="transparent" quality="high" type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>';
	str+='</object>';

	return str
}

function fVideoPlayEnd(){
	//alert('end of movie');
}

function fPlayItem(nImageIndex, bPlay){
	$(".clsThumbSelected").removeClass("clsThumbSelected");
	$("#oThumb"+nImageIndex).addClass("clsThumbSelected");
	
	if(arrImages[nImageIndex].sVideo){
		str=fFlashMovie(arrImages[nImageIndex].sImage, arrImages[nImageIndex].sVideo, bPlay);
	}
	else{
		str="<img src=\""+ SITE_DOMAIN + arrImages[nImageIndex].sImage +"\" alt=\"\" />"
	}

	$("#oLBPlayer").html(str);
} 	
 
 
function fShowReal(){
	var str=fFlashMovie("/images/showreel_img.jpg", "/trixter01.flv",true);
	$("#oLBTitle").html("TRIXTER SHOWREEL")
	$("#oLBControlls").hide()
	$("#oLBGallery").hide();
	$("#oLBInfo").hide();
	$("#oLBPlayer").html(str);
	fPopupLayer(550,true)
}

 
var bWebsiteLoaded=false;
var bPopupVisiable=false, nPopupWidth=0, nPopupHeight=0;

function fPopupLayerPosition(bAutoPoz,nPozTop){
	if(!nPozTop) nPozTop=505;
	if(!bPopupVisiable) return;
	var obj=document.getElementById("oPopupLayerFrame");
	var nLeft=(document.body.offsetWidth-nPopupWidth)/2 +"px";
	var nTop=(document.documentElement.clientHeight-nPopupHeight)/2;
	nTop+=document.documentElement.scrollTop;
	nTop=(nTop<=0 ? 0 : nTop+"px");
	
	obj.style.width=nPopupWidth;
	//obj.style.height=nPopupHeight;
	obj.style.left=nLeft;
	if(bAutoPoz){
		obj.style.top=nTop;
	}
	else{
		obj.style.top=(nPozTop+10)+"px";
		var nScrollTo=(nPozTop?nPozTop:505)
		$("html:not(:animated),body:not(:animated)").animate({scrollTop:nScrollTo}, 800);
	}

	//document.getElementById("oPopupLayer").style.height=document.body.offsetHeight;
	//$("#oPopupLayer").css("height",$(".clsPageAlign").outerHeight()+215)
}

function fPopupLayer(nHeight,bAutoPoz,nPozTop){
	if(!bWebsiteLoaded) return;   // making sure everything is loaded
	nPopupWidth=822;
	nPopupHeight=(nHeight||850);
	var obj=document.getElementById("oPopupLayerFrame");
	bPopupVisiable=true;
	fPopupLayerPosition(bAutoPoz,nPozTop);

	obj.style.width=nPopupWidth +"px";
	//obj.style.height=nPopupHeight +"px";
	
	//document.getElementById("oPopupLayer").style.height=document.body.offsetHeight;
	document.getElementById("oPopupLayer").style.display="block";
	
	$("#oPopupLayer").show();
	$("#oPopupLayerFrame").fadeIn("slow",function(){
		$(".clsPopupLayerFrame").removeClass("clsPopupLayerFrameTrans");
		$(".clsPopupLayerFrameBody").removeClass("clsPopupLayerFrameBodyTrans");
		$(".clsLbBorder").show();
		
	});
	
}

function fClosePopupLayer(){
	sCurrDisplayedTab=""
	$("#oLBPlayer").html("");
	bPopupVisiable=false;
	nPopupWidth=0;
	nPopupHeight=0;
	$(".clsLbBorder").hide();
	$(".clsPopupLayerFrame").addClass("clsPopupLayerFrameTrans");
	$(".clsPopupLayerFrameBody").addClass("clsPopupLayerFrameBodyTrans");
	$("#oPopupLayerFrame").fadeOut("slow", function(){
		$("#oPopupLayer").hide();
		
		$("#oLBInfo").css("height","215px");
	});
	
}


// ie7 & ffx uses fixed positioning which is not supperted in ie6
//if(bIE6) window.attachEvent("onscroll", fPopupLayerPosition)
window.attachEvent("onresize", fPopupLayerPosition)