
var BottomOfNavBar = 163;
var GoalTopPositionOfImage = 30;
var AnimationStepTime = 30;
var AnimationStepCount = 20;
var ImageOpenWidth = 700;
var ImageOpenHeight = 500;

var BannerOpenHeight=281;
var BannerCloseHeight=77;

var MenuOpenTop = 346;
var MenuCloseTop = 143;

var FooterHeight = 65;

var OpenImageContainer;
var OpenContentContainer;
var LastSeen;

LastSeen="home";


var divBanner;
var divMenu;
var divFooter;
var intBannerStep;

var IsLoaded=false;

function OpenDemo(){
	window.open("overview/digitalmettle.html", "", "height=570, width=440,status=yes,toolbar=no,menubar=no,location=no");
} 

function window_onload(){
	divBanner=document.getElementById("divBanner");
	divMenu=document.getElementById("divMenu");
	divFooter=document.getElementById("divfooter");
	intBannerStep=(BannerOpenHeight-BannerCloseHeight)/AnimationStepCount;
	//var gq=GetQuerystring("start_link");
	IsLoaded=true;
	//if(gq==null || gq==""){
		window.setTimeout("ShowFooter()", 1000);
	//}else{
	//	window.setTimeout("ShowMe('" + gq + "');", 100);
	//}
	parent.show_start_link();

}

var JumpToTarget = "";

function SetJumpTo(newTarget){
	if(newTarget==null){
		JumpToTarget="";
	}else{
		JumpToTarget=newTarget;
	}
	
}




function ShowMe(NowSeen) {

	//alert(NowSeen + ' ' + IsLoaded);
		
	if(OpenImageContainer!=null){
		CloseImage(OpenImageContainer);
	}
	NowSeen=NowSeen.toString();
	if(!IsLoaded){
		if(LastSeen!=NowSeen){
			window.setTimeout("ShowMe('" + NowSeen + "');", 500);
		}
		return;
	}
	
	if(LastSeen!=NowSeen){
		divFooter.style.display='none';
		var intDelay=10;
		
		CloseContent(LastSeen);
		
		
		if(NowSeen=="tourstart"){
			var ifrmTour = document.getElementById("ifrmContent_tourstart");
			ifrmTour.src = "demo.html";
		}
		
		if(LastSeen=="tourstart"){
			var ifrmTour = document.getElementById("ifrmContent_tourstart");
			ifrmTour.src = "about:blank";
		}
		
		
		if(LastSeen=="home"){
			intDelay=AnimationStepTime*AnimationStepCount+100;
			CloseBanner(1);
		}
		if(NowSeen=="home"){
			intDelay=AnimationStepTime*AnimationStepCount+100;
			OpenBanner(1);
		}
		
		
		window.setTimeout("OpenContent('" + NowSeen + "');", intDelay);
		
		
		LastSeen=NowSeen;
		
	}
}


function CloseContent(strContentName){
	var divObj = document.getElementById("divContent_"+strContentName);
	divObj.style.height='1px';
	divObj.style.overflow="hidden";
	divObj.style.visibility="hidden";
	divObj.style.display="none";
}

function OpenContent(strContentName){
	OpenContentContainer = document.getElementById("divContent_"+strContentName);
	OpenContentContainer.style.visibility="visible";
	OpenContentContainer.style.display="inline";
	var NewContentHeight=(document.body.clientHeight-FooterHeight-(OpenContentContainer.style.top).replace('px', ''));
	if(OpenContentContainer.style.top==''){
		NewContentHeight=(document.body.clientHeight-FooterHeight-BottomOfNavBar);
	}
	var ContentStep = NewContentHeight/AnimationStepCount;
	window.setTimeout("OpeningContent(" + 1 + ", " + ContentStep + ")", 1);
}


function JumpTo(){
	if(JumpToTarget!=""){
	   try{
		var pJumpTo =  document.getElementById("p_" + LastSeen + "_" + JumpToTarget);
		pJumpTo.scrollIntoView();
	   }catch(e){
   	   }
	}
}

function OpeningContent(intStep, ContentStep){
	if(intStep==AnimationStepCount){
		OpenContentContainer.style.overflow="visible";
		window.setTimeout("JumpTo()", 500);
		window.setTimeout("ShowFooter()", 501);
	}else{
		var NewStep = parseInt(intStep)+1;
		OpenContentContainer.style.height=intStep * ContentStep;
		window.setTimeout("OpeningContent(" + NewStep + ", " + ContentStep + ")", AnimationStepTime);
	}
	
}

function ShowFooter(){
	if(document.body.scrollHeight==document.body.clientHeight)return;
	if(document.body.scrollHeight+FooterHeight < document.body.clientHeight){
		divFooter.style.top=(document.body.clientHeight-FooterHeight) + 'px';
	}else{
		divFooter.style.top=document.body.scrollHeight + 'px';
	}
	divFooter.style.display='';
}

function CloseBanner(intStep){
	if(intStep==AnimationStepCount){
		divBanner.style.height=BannerCloseHeight;
		divMenu.style.top=MenuCloseTop;
	}else{
		divBanner.style.height=BannerOpenHeight-(intBannerStep*parseInt(intStep));
		divMenu.style.top=MenuOpenTop-(intBannerStep*parseInt(intStep));
		var NewStep = parseInt(intStep)+1;
		window.setTimeout("CloseBanner(" + NewStep + ")", AnimationStepTime);
	}
}

function OpenBanner(intStep){
	if(intStep==AnimationStepCount){
		divBanner.style.height=BannerOpenHeight;
		divMenu.style.top=MenuOpenTop;
	}else{
		divBanner.style.height=BannerCloseHeight+(intBannerStep*parseInt(intStep));
		divMenu.style.top=MenuCloseTop+(intBannerStep*parseInt(intStep));
		var NewStep = parseInt(intStep)+1;
		window.setTimeout("OpenBanner(" + NewStep + ")", AnimationStepTime);
	}
}




function OpenCloseImage(theDivObject){
	if(OpenImageContainer==theDivObject){
		CloseImage(theDivObject);
	}else{
		if(OpenImageContainer!=null){
			CloseImage(OpenImageContainer);
		}
		OpenImage(theDivObject);
	}
}

function CloseImage(theDivObject){
	theDivObject.style.top = theDivObject.getAttribute('normalTop');
	theDivObject.style.width = theDivObject.getAttribute('normalWidth');
	theDivObject.style.height = theDivObject.getAttribute('normalHeight');	
	theDivObject.style.left = theDivObject.getAttribute('normalLeft');
	theDivObject.style.zIndex = 1;
	OpenImageContainer=null;
}

function OpenImage(theDivObject){
	theDivObject.setAttribute('normalTop', theDivObject.style.top);
	theDivObject.setAttribute('normalWidth', theDivObject.style.width);
	theDivObject.setAttribute('normalHeight', theDivObject.style.height);
	theDivObject.setAttribute('normalLeft', theDivObject.style.left);
	var newTop;
	if(document.body.scrollTop>BottomOfNavBar){
		newTop=document.body.scrollTop-BottomOfNavBar+GoalTopPositionOfImage;
	}else{
		newTop=GoalTopPositionOfImage;
	}
	var oldTop = (theDivObject.style.top).replace('px', '');
	var TopStep;
	
	if(oldTop<newTop){
		theDivObject.style.top=newTop;
		TopStep = 0;
	}else{
		TopStep=(oldTop-newTop)/AnimationStepCount;
	}
	
	var oldWidth = (theDivObject.style.width).replace('px', '');
	var oldHeight = (theDivObject.style.height).replace('px', '');
	var WidthStep = (getNumberAttributeDefault(theDivObject, "ImageOpenWidth", ImageOpenWidth)-oldWidth)/AnimationStepCount;
	var HeightStep = (getNumberAttributeDefault(theDivObject, "ImageOpenHeight", ImageOpenHeight)-oldHeight)/AnimationStepCount;
	theDivObject.style.zIndex = 2;			
	OpenImageContainer=theDivObject;
	window.setTimeout("OpeningImage(1, "+ newTop + ", "+ oldTop + ", "+ TopStep + ", " + oldWidth + ", " + WidthStep + ", " + oldHeight + ", " + HeightStep + ")", 1);
}

function OpeningImage(intStep, newTop, oldTop, TopStep, oldWidth, WidthStep, oldHeight, HeightStep){
	if(intStep==AnimationStepCount){
		OpenImageContainer.style.top=newTop;
		window.status = OpenImageContainer.style.top;
		OpenImageContainer.style.width=getNumberAttributeDefault(OpenImageContainer, "ImageOpenWidth", ImageOpenWidth);
		OpenImageContainer.style.height=getNumberAttributeDefault(OpenImageContainer, "ImageOpenHeight", ImageOpenHeight);
		OpenImageContainer.style.left = parseInt(OpenImageContainer.getAttribute('normalLeft').replace('px', ''))-getNumberAttributeDefault(OpenImageContainer, "ImageOpenWidth", ImageOpenWidth)+parseInt(OpenImageContainer.getAttribute('normalWidth').replace('px', ''));
	}else{
		if(TopStep>0) OpenImageContainer.style.top=oldTop-(TopStep*intStep);
		OpenImageContainer.style.width=oldWidth+(WidthStep*intStep);
		OpenImageContainer.style.left=parseInt(OpenImageContainer.getAttribute('normalLeft').replace('px', ''))-(WidthStep*intStep);
		OpenImageContainer.style.height=oldHeight+(HeightStep*intStep);
		var NewStep = parseInt(intStep)+1;
		window.setTimeout("OpeningImage(" + NewStep + ", "+ newTop + ", "+ oldTop + ", "+ TopStep + ", " + oldWidth + ", " + WidthStep + ", " + oldHeight + ", " + HeightStep + ")", AnimationStepTime);
	}
}

function getNumberAttributeDefault(theObject, theAttribute, theDefault){
	var theValue = theObject.getAttribute(theAttribute)
	if(theValue!=null) {
		return parseInt(theValue);
	}else{
		return theDefault;
	}
}
