
/********************************* PAGE VARIABLES *********************************/

//Determine is_ie 
var agt = navigator.userAgent.toLowerCase(); 
document.is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

//Set page constants
document.contentWidth = 770;		//width of content area
document.contentY = 50;				//y position of content area
document.ContentArea = null;		//content area div (set on initialisation)

//home page image rotation
document.crntHomeImageNo = 0;
document.homeImagePath = "resources/__home_pics/";
document.homeImageArray = new Array("FaceRight.jpg", "Bubbles.jpg", "LaFront.jpg", "FaceReception.jpg", "Katsura5.jpg");


document.mainNavPath = "images/main_nav/";
document.mainNavArray = new Array("home","drama","compro","reel","contact");

/********************************* PAGE INITIALISATION *********************************/

function initPage(rootPath)
{
	//Get ref to content area and set as document 
	document.ContentArea = (document.getElementById) ? document.getElementById("ContentArea") : document.all["ContentArea"];
	
	if (rootPath != null)
	{
		document.homeImagePath = (rootPath + document.homeImagePath);
		document.mainNavPath = (rootPath + document.mainNavPath);
	};
	
	//Centre content area horizontally
	centreContentArea();
	
	//Turn visibility on
	document.ContentArea.style.visibility = "visible";
	
	//Init main nav bar
	initMainNavBar();
};


/********************************* HOME PAGE IMAGE FUNCTIONS *********************************/


function initHomeRotate()
{
	//Get ref to image object
	document.homePic = document.getElementById("HomePic");
	
	//Load first image
	loadNextHomePic();
};

function loadNextHomePic()
{
	//Set image
	document.homePic.src = document.homeImagePath + document.homeImageArray[document.crntHomeImageNo];
	
	//Increase counter to next item (reset if out of range)
	if (++document.crntHomeImageNo >= document.homeImageArray.length) document.crntHomeImageNo = 0;
	
	//Set timer to countdown for next image to be loaded
	window.setTimeout("loadNextHomePic()", 5000);
};



/********************************* CONTENT CENTERING FUNCTIONS *********************************/

//Centre ContentDiv
function centreContentArea()
{
	//Get document width
	var documentWidth = parseInt(document.body.clientWidth);
	
	//Calculate xPos of content area
	var contentX = Math.round((documentWidth - document.contentWidth) / 2);
	if (contentX < 5) contentX = 5;
	
	setDivXY(document.ContentArea, contentX, document.contentY);
};


//Set x and y position of a div
function setDivXY(obj, xPos, yPos)
{
	if (document.is_ie)
	{
		obj.style.pixelLeft = xPos;
		obj.style.pixelTop = yPos;
	}
	else
	{
		obj.style.left = xPos + "px";
		obj.style.top = yPos + "px";
	}
};


/********************************* MAIN NAV FUNCTIONS *********************************/


function initMainNavBar()
{
	for (var i=0; i<document.mainNavArray.length; i++)
	{
		//Get ref to current item
		var crntItem = document.mainNavArray[i];
		
		//Get ref to current image
		var crntImg = document.getElementById("mn" + crntItem + "Img");
		
		crntImg.imgOff = createImageObject(document.mainNavPath + "nav_" + crntItem + "_off.gif");
		crntImg.imgOver = createImageObject(document.mainNavPath + "nav_" + crntItem + "_over.gif");
		
		//window.alert(crntImg.imgOff.src);
		
		if (crntItem == document.navSection)
		{
			crntImg.src = crntImg.imgOver.src;
		}
		else
		{
			//Set mouseover and mouseout event handlers for image
			crntImg.onmouseover = function() {	this.src = this.imgOver.src;	};
			crntImg.onmouseout = function() {	this.src = this.imgOff.src;	};
		}
	}
};


/********************************* GENERAL FUNCTIONS *********************************/


//::Create an image object, and set the source
function createImageObject(filePath)
{
	//Create image object
	var imgObj = new Image();
	
	//Set image object source
	imgObj.src = filePath;
	
	//Return image object
	return imgObj
};


//::Get variables from querystring, return name, value pairs object
function getQueryStringParameters() 
{
	//Get querystring for current page
	var query = window.location.search.substring(1);
	
	//Split query string into array of name=value strings
	var parms = query.split('&');
	
	//Set output object
	var outputObj = new Object();
	
	//Loop through each name=value pair
	for (var i = 0; i < parms.length; i++) 
	{
		//Get position of "=" symbol
		var pos = parms[i].indexOf('=');
		
		//If "=" symbol found
		if (pos > 0) 
		{
			//Get name and value strings
			var name = parms[i].substring(0,pos);
			var value = parms[i].substring(pos+1);
			
			//Add to output object
			outputObj[name] = value;
		};
	};
	
	//Return output object
	return outputObj
};





/********************************* POP UP AND SHOW CLIP FUNCTIONS *********************************/

function centrePopUp(pop_width, pop_height)
{
   //get screen dimensions
   var screen_width = parseInt(screen.availWidth); var screen_height = parseInt(screen.availHeight);
   
   //calc x and y positions
   var xpos = Math.round(((screen_width - pop_width)/2));  var ypos = Math.round(((screen_height - pop_height)/2));
   
   //set output string with width and height dims
   var dim_string = 'width=' + pop_width + ',height=' + pop_height;
   
   //do browser detect to see if nav
   var agt=navigator.userAgent.toLowerCase();
   
   var is_nav4 = false;
   
   if ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
				&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
				&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
								&& (parseInt(navigator.appVersion) <= 4))
   {
	is_nav4 = true;
   }
   
   //if nav 4
   if (is_nav4) 
	return (dim_string + ",screenX=" + xpos + ",screenY=" + ypos);
   else 
	return (dim_string + ",left=" + xpos + ",top=" + ypos);
 };

function showClip(cType, movie)
{
	//window.alert("view movie: " + clip);
	
	if (movie == null)  movie = document.crntMovieObject.ref;
	
	//Set page src
	var page_src = "clip_viewer.html?cType=" + cType + "&movie=" + movie;
	
	//Set win settings
	var win_config = centrePopUp(440,450) + ',scrollbars=no,resize=no';
	
	//Open window and focus it
	var win = window.open(page_src, "movieViewer", win_config);
	win.focus();
};


function showBio()
{
	//Set win settings
	var win_config = centrePopUp(790,470) + ',scrollbars=no,resize=no';
	
	//Open window and focus it
	var win = window.open("bio.php", "bioViewer", win_config);
	win.focus();
};
