//JavaScript Document CasaScreens 0.8 13 June 2009

var CasaScreen = new Object();

CasaScreen.height=600;//default image size
CasaScreen.scale=100;//for scrolling
CasaScreen.pics = new Array("cmweb_child_input.jpg", "cmweb_health.jpg", "cmweb_hearings.jpg", "cmweb_case_selector.jpg", "cmweb_reports_menu.jpg", "cmweb_chd_adv_rpt.jpg", "cmweb_vol_input.jpg", "cmweb_vol_cases.jpg", "cmweb_vol_training.jpg");
CasaScreen.picWidths = new Array(763, 763, 758, 762, 780, 539, 771, 781, 776);
CasaScreen.picHeights = new Array(600, 600, 600, 600, 600, 600, 600, 600, 600);

CasaScreen.preLoadImages = function()//Optional
{
	var preload = new Array();
	for(var i = 0; i < CasaScreen.pics.length; i++)
	{
		preload[i] = new Image();
		preload[i].src = "images/" + CasaScreen.pics[i];
	}
};

CasaScreen.init = function()//Add event handlers
{
	var theTable = document.getElementById('imageTable');
	var theList;
	if (theTable){
		theList = theTable.getElementsByTagName("a");
		for (var i = 0; i < theList.length; i++) theList[i].onclick = CasaScreen.clickHandler;
	}
	//alert("init complete");
};

CasaScreen.clickHandler = function()
{
	//first get the file name from the href
	var theHref = this.href;
	var thePath = theHref.split("/");
	theHref = thePath[thePath.length - 1];
	//now search the picture array	
	var foundIt = -1;
	for (var i = 0; i < CasaScreen.pics.length; i++)
	{
		if ( CasaScreen.pics[i].match(theHref) ) foundIt = i;
	}
	if ( foundIt >= 0){
		CasaScreen.showTop(foundIt);
		return false;
	}
};

CasaScreen.showTop = function(iPic)//Prepares to show the screenshot
{
	var myElement, myBackground;//the topbox
	var picWidth, picHeight=600;//the image
	var divWidth=955, divHeight=635, xPos=0, yPos=16;//to position screenshot in div
	
	//get details of the image
	picWidth = CasaScreen.picWidths[iPic];
	picHeight = CasaScreen.picHeights[iPic];
	
	//calc style data
	if(divWidth > picWidth) xPos = Math.round((divWidth - picWidth) * 0.5);
	//if(divHeight > picHeight) yPos = Math.round((divHeight - picHeight) * 0.5);
	myBackground = "url(images/" + CasaScreen.pics[iPic] + ")";
	
	//get element and set style
	myElement = document.getElementById('topbox');
	myElement.style.backgroundImage = myBackground;
	myElement.style.width= picWidth + "px";
	myElement.style.left= xPos + "px";
	myElement.style.top= yPos + "px";
	myElement.className= "seen";
	
	//element is ready so scroll to screen
	CasaScreen.scale = 1;
	CasaScreen.height = picHeight;
	CasaScreen.scrollTop();
};

CasaScreen.scrollTop = function()
{
	var myElement = document.getElementById('topbox');
	if(CasaScreen.scale <= 100){//was set to 1 in showTop
		//grow the element height
		myElement.style.height= Math.round((CasaScreen.height * CasaScreen.scale / 100)) + "px";
		CasaScreen.scale++;
		tim = window.setTimeout("CasaScreen.scrollTop()", 1);
	}
	else window.clearTimeout( tim );
};

CasaScreen.closeTop = function()
{
	document.getElementById('topbox').className= "unseen";
};
//End of CasaScreen object

window.onload = function()//DOM Scripting p103
{
	CasaScreen.init();
	CasaScreen.preLoadImages();
};




