// Estevan Skate v2 JavaScript Document

/** preload ********************************************************\
|																	|
|	This function will be called on page load and it preloads all	|
|	the necessary images and reduces laoding time for the page.		|
|																	|
\*******************************************************************/
function preload()
{
  preloadImages( 'images/layout/banner1.jpg', 'images/layout/banner2.jpg',
				'images/layout/banner3.jpg', 'images/layout/banner4.jpg', 
				'images/layout/banner5.jpg', 'images/layout/background.jpg',
				'images/layout/background2.jpg', 'images/layout/bottomAdvertise.jpg', 
				'images/layout/bottomContact.jpg', 'images/layout/bottomDisclaimer.jpg', 
				'images/layout/bottomFAQ.jpg', 'images/layout/bottomHome.jpg',
				'images/layout/bottomLeft.jpg', 'images/layout/bottomMap.jpg',
				'images/layout/bottomPolicy.jpg', 'images/layout/navArticles.jpg', 
				'images/layout/navContact.jpg', 'images/layout/navXsiv.jpg',
				'images/layout/navContests.jpg', 'images/layout/navEvents.jpg',
				'images/layout/navForum.jpg', 'images/layout/navSkatepark.jpg',
				'images/layout/navLinks.jpg', 'images/layout/navReviews.jpg',
				'images/layout/navStills.jpg', 'images/layout/navStore.jpg', 
				'images/layout/navTips.jpg', 'images/layout/navArticles2.jpg', 
				'images/layout/navContact2.jpg', 'images/layout/navXsiv2.jpg',
				'images/layout/navContests2.jpg', 'images/layout/navEvents2.jpg',
				'images/layout/navForum2.jpg', 'images/layout/navSkatepark2.jpg',
				'images/layout/navLinks2.jpg', 'images/layout/navReviews2.jpg',
				'images/layout/navStills2.jpg', 'images/layout/navStore2.jpg', 
				'images/layout/navTips2.jpg' );
}

/** preloadImages **************************************************\
|																	|
|	This function with take the arguments passed into it and		|
|	preload them into the browser. It assumes the arguments passed  |
|	into it are image files.										|
|																	|
\*******************************************************************/
function preloadImages()
{
  var d = document; 
  if( d.images )
  { 
  	if( !d.p ) 
	{
		d.p = new Array();
	}
	
    var i, j = d.p.length, a = preloadImages.arguments; 
	
	for( i=0; i < a.length; i++ )
    {
		if ( a[i].indexOf("#") != 0 )
		{ 
			d.p[j] = new Image;
			d.p[j++].src = a[i];
		}
	}
  }
}

/** popup **********************************************************\
|																	|
|	This function will be used to create the popup window 			|
|																	|
\*******************************************************************/
function popup( url, h, w ) 
{
	day = new Date();
	id = day.getTime();

		eval("page" + id + " = window.open('" + url + "', '" + id + "', 					'toolbar=0,status=no,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left = 287,top = 109');");

}

/** showEmail ******************************************************\
|																	|
|	This function will be used to create a mailto link using the	|
|	email as the text for the link. Mainly used to prevent email 	|
|	parsers from grabbing an email address.							|
|																	|
\*******************************************************************/
function showEmail(userName, emailServer)
{
	var emailLink = userName + "@" + emailServer;
	document.write("<a href='mailto:" + emailLink + "'>");
	document.write( emailLink );
	document.write("</a>");
}

/** emailLink ******************************************************\
|																	|
|	This function will be used to create a mailto link using the	|
|	email as the message for the link. Mainly used to prevent email |
|	parsers from grabbing an email address.							|
|																	|
\*******************************************************************/
function emailLink(userName, emailServer, message)
{
	var emailLink = userName + "@" + emailServer;
	document.write("<a href='mailto:" + emailLink + "'>");
	document.write( message );
	document.write("</a>");
}

/** pageCheck ******************************************************\
|																	|
|	This function will check to see if the frame "nav" exists. If	|
|	it doesn't it will send the user to a page where nav exists.	|
|	It also sends along a variable called frame defining which		|
|	page to display in the nav frame.								|
|																	|
\*******************************************************************/
function pageCheck( target )
{
	if (document.getElementById)
	{ 
		existFrame = document.getElementById( 'nav' );
	} 
	else if (document.layers) 
	{ 
		existFrame = document.layers[ 'nav' ];
	} 
	else if (document.all) 
	{ 
		existFrame = document.all[ 'nav' ];
	}

	if( existFrame == null )
	{
		 window.location = 'http://www.estevanskate.com/index.html?frame=' + target;
	}
}

/** setPage ********************************************************\
|																	|
|	This function will check to see if the variable frame has been	|
|	passed along the URL. If it has it will set the nav frame to	|
|	value of the frame variable.									|
|																	|
\*******************************************************************/
function setPage()
{
	if( window.location.search.length != 0 )
	{
		frameName = window.location.search.split( "?" )[1].split( "=" )[1];
		
		eval( "parent.nav.location = 'http://www.estevanskate.com/" + frameName + "'" );
	}
}

function toggleMenu( img, obj )
{
	if (document.getElementById)
	{ 
		imgIcon = document.getElementById( img );
		divContent = document.getElementById( obj );
	} 
	else if (document.layers) 
	{ 
		imgIcon = document.layers[ img ];
		divContent = document.layers[ obj ];
	} 
	else if (document.all) 
	{ 
		imgIcon = document.all[ img ];
		divContent = document.all[ obj ];
	} 

	if( divContent.style.display == 'none' )
	{
		divContent.style.display = 'block';
		imgIcon.src = "images/layout/menu_close.gif";
	}
	else
	{
		divContent.style.display = "none";
		imgIcon.src = "images/layout/menu_open.gif";
	}
}