// plays the 3D logo intro
function playIntro() {
	$("#playIntro").click();
}

function returnToPage() {
	tb_remove();
}

// this runs on page load
$(function(){ 

	// preload rollover images
	$.preloadImages(["./images/header/home2.jpg", 
					"./images/header/products2.jpg", 
					"./images/header/safety2.jpg", 
					"./images/header/dealers2.jpg", 
					"./images/header/aboutus2.jpg", 
					"./images/header/contact2.jpg"]);

	var addRollover = function(sectionName, menuTipX, menuTipWidth, menuTipAlign) {
		var section = $('li#' +sectionName);
		section.mouseover(function() { 
							// move this section to top layer
							this.style.zIndex = 20;
							// replace image
							$(this).find('span').css('background-image' ,'url(/images/header/' +sectionName+ '2.jpg)'); 
							// get this section's current horizontal position
							var sectionX = $(this).css('left');
							// calculate the tab's horizontal position
							var tabX = (sectionX.substring(0, sectionX.length-2)) - 17;
							// move the tab to new horizontal position and make sure it is visible
							$('#tab').css("left", tabX+"px").css('visibility', 'visible');
							// change, move, and resize menu tip
							var tip = $(this).attr('title');
							$('#menuTip').text(tip).css({ left: menuTipX+'px', width: menuTipWidth+'px', textAlign: menuTipAlign}).fadeIn('fast');
					   		});
		section.mouseout(function() { 
							// disappear tab
							$("#tab").css('visibility', 'hidden');
							// replace image
							$(this).find('span').css('background-image', 'url(/images/header/' +sectionName+ '.jpg)'); 
							// move this section to bottom layer
							this.style.zIndex = 0;
							// remove menu tip
							$('#menuTip').text('');
							});
	}
	
	// add tab to page
	var topNav_ul = $('#topNav ul');
	topNav_ul.before('<img id="tab" src="/images/header/tab.jpg" />');

	// add menu tip to page
	topNav_ul.after('<div id="menuTip"></div>');

	// add rollovers to all li's
	addRollover('home', 80, 310, 'left');
	addRollover('products', 150, 265, 'left');
	addRollover('safety', 220, 175, 'left');
	addRollover('dealers', 35, 160, 'right');
	addRollover('aboutus', 80, 185, 'right');
	addRollover('contact', 105, 230, 'right');
	
	// replace logo
	$('#logo').flash({
    	src: '/flash/logo_loop/logo_loop.swf',
    	width: 365,
    	height: 205,
		wmode: 'transparent' },
        { version: 6, update: false }
	);

	// apply Thickbox to playIntro link
	tb_init('#playIntro');

	// replace intro
	$('#intro').flash({
    	src: '/flash/intro/intro.swf',
    	width: 400,
    	height: 300 },
        { version: 6, expressInstall: true }
	);
	
});

