// JavaScript Document
var locator;
var string;

      var pages = [ "the_film","cast","crew","about_us","latest_news","financing","links", "contact_us" ];
	  var imageOn;
	  var imageOff;
	  //if (imageOn==null) alert("imageOn null");
	  if (document.images) {
		  //alert("after if.");
		  imageOn = new Array( pages.length );
	  	  imageOff = new Array( pages.length );
		  // The following loads each of the navigation bar images
		  // into the browser cache -- in particular, setting the an Image objects
		  // src causes the image to be loaded into cache. Then when this same
		  // name is used (or set) later in a displayed image, the cached version
		  // is chosen.
	  for (var i=0;i<pages.length;i++){
		  var pageName = pages[i];
		   imageOn[pageName] = new Image();
		   imageOn[pageName].src = "images/"+pageName+"_on.jpg"; 
		   imageOff[pageName] = new Image();
		   imageOff[pageName].src = "images/"+pageName+"_off.jpg";
	    }
      }
	  
	/* preload images. The arguments array is the variable length
	array passed in of image names to preload.
	*/
function preloadImages(){
	var images = new Array( arguments.length );
	for (var i=0; i< arguments.length; i++){
		images[i] = new Image();
		images[i].src = "images/"+ arguments[i];
	}
}

	  
	/* 
	The navigation bar sits to the left of the content window. Each navigation 
	button is a jpg, that has an 'on' and 'off' state (turns on with mouse over 
    and when selected. Each button is placed in it's own table row and is 
	written out with the following function.
	*/
	//style="position: absolute; top: '+vertical+'px; left:100"
function trNavTable( name, index ){
	var currentPageName=document.body.id.toString();
	var suffix="_off.jpg";
	if (name == currentPageName) {suffix="_on.jpg";} 
	var pageName = name;
	var vertical = index*24 + 170;
	if ( pageName=="the_film" ) pageName="index";
	s= '<TR><TD align=right>    \
		  <A onmouseover="imgOn(\''+name+'\')" \
            onfocus=this.blur() onmouseout="imgOff(\''+name+'\')" \
            href="'+pageName+'.shtml" target=_self> \
		    <IMG height=18 id="'+name+'" src="images/'+name+suffix+'" \
			 border=0 name="'+name+'" /> \
		  </A> \
		</TD></TR>';
	document.write(s);
}
// Function to 'activate' images on onMouseOver.
function imgOn(imgName) {
        if (document.images) {
			var newSource = imageOn[imgName].src;
			// don't update source if image doesn't change!
			if ( document.images[imgName].src != newSource ) 
              document.images[imgName].src = newSource;
        }
}

// Function to 'deactivate' images on onMouseOff.
function imgOff( imgName ) {
		var pageName=document.body.id.toString();
		// on mouse roll off, don't turn off this image if the page
		// we are on is still selected (pageName == imgName).
        if (document.images && pageName && pageName!=imgName) {
            document.images[imgName].src = imageOff[imgName].src;
        }
}	
function displayContentImg( imageFile ){
	displayImage("contentImage", imageFile);
}
function clearContentImg(){ 
	displayImage("contentImage", "blankthumb.jpg");
	}
	
function displayImage(imgName, imageFile){
	if (document.images) {
    	document.images[imgName].src = "images/" + imageFile;
	}
}
function blankImage(imgName){
	if (document.images) {
    	document.images[imgName].src = "images/blank.gif";
	}
}

function emailAddress(userName, domainName){
	s = userName+'@'+domainName;
	return s;
}
// onmouseout="clearContentImg()"
function linkToWithClass( linkHTML, thumbNail, linkTitle, className ){
	s='<a class="'+className+'" href="'+linkHTML+'" onfocus="this.blur()" onmouseover="displayContentImg(\''+thumbNail+'\')" >'+linkTitle+'</a>';
	return s;
}
// assumes a className of "team"
function linkTo( linkHTML, thumbNail, linkTitle ){
	return linkToWithClass( linkHTML, thumbNail, linkTitle, "team");
}
function linkToCrew( linkHTML, thumbNail, linkTitle ){
	return linkToWithClass( linkHTML, thumbNail, linkTitle, "crew")+'<br>';
}
function infoEmail(){
	userName = 'info';
	domainName = 'pigdogfilms.com';
	s = '<A CLASS="email" onfocus=this.blur() HREF="mailto:'+emailAddress(userName,domainName)+'">'+emailAddress(userName,domainName)+'</A>';
	return s;
}
function investorEmail(){
	userName = 'investments';
	domainName = 'pigdogfilms.com';
	s='<a CLASS="email" onfocus=this.blur() HREF="mailto:'+emailAddress(userName,domainName)+'">'+emailAddress(userName,domainName)+'</a>';
	return s;
}

function writeTitle( title ){
	s = '<tr> <td  height=30 align="center" colSpan=2>' +
	     '<b class="content_title">'+ title +'</b></td></tr>';
	//alert(s);
	document.write( s );
}
function writeContent( content ){
	s = '<tr> <td height="310" colSpan=2 VALIGN="top">' + content + '</td> </tr> ';
	//alert(s);
	document.write(s);
}

 function emptyContentButton(){
	s = '<td height=20 WIDTH="173">'+
		'<img src="images/blank.gif" border="0" height="1" width="173"/> </td> ';
	//alert("Empty content button: " + s );
	document.write(s);
}
function writeButtonHTML( pageName, page, justify, src ){
	var href = ' HREF="javascript:location=\''+pageName+'.shtml?pageCount='+page+'\';">';
	if(justify=="left") { position="222px";}
	else { position="502px";}
	var s = ' <td align="'+justify+'" height=20 WIDTH=173><a class="cursor" onfocus=this.blur() ';
	s += href;
	s += '<img src="images/'+src+'" border="0" height="20" align="'+justify+'"  style="position: absolute; top: 365px; left: '+position+'" /> </a></td> ';
	//alert("writeButton: " + s );
	document.write(s);
}
function moreButton( pageName, thisPage ){
	var page, justify, src;
	page = thisPage+1;
	justify = 'right';
	src = 'more_arrow.gif' ;
	writeButtonHTML( pageName, page, justify, src );
}
function backButton( pageName, thisPage ){
	var page, justify, src;
	page = thisPage-1;
	justify = 'left';
	src = 'back_arrow.gif' ;
	writeButtonHTML( pageName, page, justify, src );
}
function homeButton( homeName ){
	var page, justify, src;
	page = 1;
	justify = 'left';
	src = 'back_arrow.gif' ;
	writeButtonHTML( homeName, page, justify, src );
}

function writeContentNavButtons(pageName, maxPages, thisPage ){
	
	if( maxPages > 1 ) {// we need NavButtons
		// left button
		if ( thisPage > 1 ) { backButton( pageName, thisPage ); }
		else {emptyContentButton()}
		// right button
		if (thisPage < maxPages ) {moreButton( pageName, thisPage);}
		else {emptyContentButton();}
	}
	
}
function writeChildContentNavButtons( homePage, pageName, maxPages, thisPage){
	// left button
	// if we are past page 1, then the back button stays within the childs pageName
	if ( thisPage > 1 ) { backButton( pageName, thisPage ); }
	// we are at the first page, then the back takes us to the root.
	else {homeButton( homePage );}
	// right button
	if (thisPage < maxPages ) {moreButton( pageName, thisPage);}
	else {emptyContentButton();}
}

function getURLPageNumber(){
	var pageCount = 1;
	var query = location.search.substring(1);
	var pairs = query.split(",");
	var pos = pairs[0].indexOf('=');
	if (pos != -1){ 
		pageCount = parseInt(pairs[0].substring(pos+1));
	}
	else { pageCount = 1; }
	return pageCount;
}
function writeAnchorTagNewPageURL( URL, title ){
	var s = '<a class="team" href="javascript:window.open(\'http://'+URL+'\'); void 0;" onfocus="this.blur()" >' + title + '</a>'	;
	//alert(s);
	return s;

}
