
function pageInit()
{
	setupPrimaryNavigation();
}
addEvent( window, "load", pageInit, false );

function setupPrimaryNavigation()
{
	var primaryNavigationLinks = document.getElementById( "PrimaryNavigationContainer" ).getElementsByTagName( "A" );
	var classNames = new Array( 	
		"home",
		"aboutRapidRadio",
		"ourProducts",
		"clientVehicles",
		"vipArea",
		"contactUs"
	)
	
	for( var i = 0; i < primaryNavigationLinks.length; i++ )
	{
		var a = primaryNavigationLinks[i];
		
		// Now find the td and apply class
		var td = a.parentNode;
		td.className = classNames[i];
	}
	
	// Preload navigation images
	var imgs = new Array( 
		"/Templates/Shared/img/PrimaryNavigation.Home-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.AboutRapidRadio-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.Services-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.OurProducts-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.ClientVehicles-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.VipArea-Hover.gif",
		"/Templates/Shared/img/PrimaryNavigation.ContactUs-Hover.gif"
		);
	
	for( var i = 0; i < imgs.length; i++ )
	{
		var image = new Image();
		image.src = imgs[ i ];
	}
}

function addEvent( element, eventTypeName, delegate, useCapture )
{
	if( element.addEventListener )
	{
		element.addEventListener( eventTypeName, delegate, useCapture );
		return true;
	} 
	else if( element.attachEvent )
	{
		var r = element.attachEvent( "on" + eventTypeName, delegate );
		return r;
	}
}

function enlargeImage( title, imagePath )
{
	var image = new Image();
	image.src = imagePath;
	width = image.width;
	height = image.height;
	
	createContentLayer( title, image, width, height );
}

var contentLayer = null;
function createContentLayer( title, content, contentWidth, contentHeight )
{
	if( contentLayer )
		removeContentLayer();
	
	// Wrapper DIV - window
	var contentLayerDiv = document.createElement( "DIV" );
	contentLayerDiv.id = "ContentLayerDiv";
	
	if( contentWidth )
		contentLayerDiv.width = contentWidth;
	
	if( contentHeight )
		contentLayerDiv.width = contentHeight;	
	
	// Content div
	var layerContent = document.createElement( "DIV" );
	layerContent.id = "LayerContent";
	
	// Title / close div
	var contentLayerTab = document.createElement( "DIV" );
	contentLayerTab.id = "ContentLayerTab";
	contentLayerTab.innerHTML = title;

	//Create close option
	var contentClose = document.createElement( "DIV" );
	contentClose.id = "ContentLayerClose";
	contentClose.innerHTML = "<a href='javascript:void(0)' onclick='removeContentLayer()'>Close</a>";

	contentLayerDiv.appendChild( layerContent );
	contentLayerDiv.appendChild( contentLayerTab );
	contentLayerTab.appendChild( contentClose );
	document.body.appendChild( contentLayerDiv );
	
	if( typeof content == "object" )
	{
		layerContent.appendChild( content );
	}
	else
	{
		layerContent.innerHTML = content;
	}
	
	contentLayerDiv.style.display = "block";
	
	var width = contentLayerDiv.offsetWidth;
	var height = contentLayerDiv.offsetHeight;
	var left = "";
	var top  = "";

	if( window.innerWidth )
	{
		left = ( window.innerWidth - width ) / 2;
		top  = ( window.innerHeight - height ) / 2 - ( 20 );
	}
	else
	{
		left = (document.body.offsetWidth - width) / 2;
		top  = (document.body.offsetWidth - height) / 2;
		top = top / 2;
	}
	
	contentLayerDiv.style.top = top;
	contentLayerDiv.style.left = left;
	
	Drag.init( contentLayerDiv );
	
	contentLayer = contentLayerDiv;
}

function removeContentLayer()
{
	contentLayer.parentNode.removeChild( contentLayer );
	contentLayer = null;
}
	
/* SCROLLER */
var pos = 0;
var end = 0;
var speed = 50;
var scrollOn = ( window.scroll ) ? true : false;
var Stop = true;

function scrollWindow()
{
	if( scrollOn && !Stop )
	{
		pos -= speed;
		window.scroll( 0, pos );
		
		if( pos < 0 )
		{
			pos = 0;
			Stop = true;
		}
		
		setTimeout( 'scrollWindow()', 1 );
	}
}

function startScroll()
{
	if( window.innerHeight )
	{
		pos = window.pageYOffset
	}
	else if( document.body )
	{
		pos = document.body.scrollTop
	}
	
	Stop = false;
	scrollWindow( );
}

function StartStop()
{
	Stop = ( Stop ) ? false : true;
	if( !Stop ) 
	{
		startScroll();
	}
}
