function returnToFrontPage() { window.location.href="index.html"; }

function gotoNewLocation(destinationHref) {
	window.location.href = destinationHref;
	return false;
}

function setupMenuItemHover($menuItem, leftPos, topPos) {
	$menuItem.hover(
	function() {
		$('#page').append("\
			<ul id='crossMenu'>\
				<li class='crossMenuElem' id='crossMenuImage'>&nbsp;</li>\
				<li class='crossMenuElem' id='crossMenuWeb'>&nbsp;</li>\
				<li class='crossMenuElem' id='crossMenuPR'>&nbsp;</li>\
				<li class='crossMenuElem' id='crossMenuSEO'>&nbsp;</li>\
				<li class='crossMenuElem' id='crossMenuInfo'>&nbsp;</li>\
			</ul>");
			$('#crossMenu')
				.hover( 
					function() { }, 
					function() { $('#crossMenu').remove(); })
				.css({ 'left':leftPos, 'top':topPos });
			$('.crossMenuElem')
				.css({'background-color':'white', 'opacity':'0.3'})
				.hover( 
					function() { $(this).css({'background-color':'white', 'opacity':'0.0'}); },
					function() { $(this).css({'background-color':'white', 'opacity':'0.3'}); }
				);
			$('#crossMenuImage').click(function() { window.location.href="working-with-image-at-aispire.html" });
			$('#crossMenuWeb').click(function() { window.location.href="working-with-web-at-aispire.html" });
			$('#crossMenuPR').click(function() { window.location.href="pr-press-and-copy-at-aispire.html" });
			$('#crossMenuSEO').click(function() { window.location.href="working-with-seo-at-aispire.html" });
			$('#crossMenuInfo').click(function() { window.location.href="info-at-aispire.html" });
	}, 
	function() { $('li.menuCurrLocn').css({'background-color':'white', 'opacity':'0.0'}); });
}

function setupMenuItemClick($menuItem, aHref) {
	if (aHref==undefined) { aHref="index.html"; }
	$menuItem.click(function() {  return gotoNewLocation(aHref);  });
	$menuItem.mouseover(function(){window.status=aHref;return true;}).mouseout(function(){window.status='Done';return true;});
}

function preloadBanners() {
	baseURL = "IconsAndBackgrounds/";
	bannerFilenames = ['banner-image.jpg','banner-web.jpg','banner-pr.jpg','banner-seo.jpg','banner-info.jpg'];
	$.each(bannerFilenames, function(i) {
		var fname = bannerFilenames[i];
		var img = new Image();
		img.src = baseURL+fname;
	});
}

function menuMonitor($liTag, i, pixelWidthArray, leftPos, topPos) {
	var aHref = $liTag.find('a').attr('href');
	for (var j=0; j<pixelWidthArray.length; j++) {
		if(i==j) {  $liTag.html("").css({ 'left':j*2+'px', 'width':pixelWidthArray[i]+'px' });  }
	}
	if (i==1) { setupMenuItemHover($liTag, leftPos, topPos); } 
	else      { setupMenuItemClick($liTag, aHref); }
}

function setupMenus() {
	// turn off nonJS stuff
	$('.nonJS').hide();
	// generic ul styling
	$('#navig ul').css({ 'height':'60px' });
	// generic li styling
	$('#navig ul li').css({
		'float':'left',
		'position':'relative',
		'top':'15px',
		'height':'18px',
		'display':'block',
		'margin':'0',
		'padding':'2px',
		'background-color':'white',
		'cursor':'pointer',
		'opacity':'0.0'
	});
	$('#navig ul li').hover(
		function() { $(this).css({'background-color':'white', 'opacity':'0.0'}); },
		function() { $(this).css({'background-color':'white', 'opacity':'0.3'}); }
	);
	
	// TOP MENU
	$('#menuTOP').css({ 'background-image':'url("IconsAndBackgrounds/menu-top4.gif")', 'width':'312px' });
	$('#menuTOP li').each(function(i) {
		var $liTag = $(this);
		var aHref = $liTag.find('a').attr('href');
		if (i==0) {  $liTag.html("").css({ 'left':'0px', 'width':'79px' });  }
		if (i==1) {  $liTag.html("").css({ 'left':'2px', 'width':'55px' });  }
		if (i==2) {  $liTag.html("").css({ 'left':'4px', 'width':'34px' });  }
		if (i==3) {  $liTag.html("").css({ 'left':'6px', 'width':'47px' });  }
		if (i==4) {  $liTag.html("").css({ 'left':'8px', 'width':'62px' });  }
		setupMenuItemClick($(this), aHref);
	});

	// IMAGE SUB-MENU
	$('#menuIMAGE').css({ 'background-image':'url("IconsAndBackgrounds/menu-image.gif")', 'width':'434px' });
	$('#menuIMAGE li').each(function(i) {
		var pixelWidthArray=[53,70,191,90];
		menuMonitor($(this), i, pixelWidthArray, 316, 373);
	});
	
	// WEB SUB-MENU
	$('#menuWEB').css({ 'background-image':'url("IconsAndBackgrounds/menu-web.gif")', 'width':'404px' });
	$('#menuWEB li').each(function(i) {
		var pixelWidthArray=[53,55,78,98,83];
		menuMonitor($(this), i, pixelWidthArray, 323, 338);
	});
	
	// PR SUB-MENU
	$('#menuPR').css({ 'background-image':'url("IconsAndBackgrounds/menu-pr.gif")', 'width':'381px' });
	$('#menuPR li').each(function(i) {
		var pixelWidthArray=[53,34,53,112,105];
		menuMonitor($(this), i, pixelWidthArray, 324, 304);
	});

	// SEO SUB-MENU
	$('#menuSEO').css({ 'background-image':'url("IconsAndBackgrounds/menu-seo.gif")', 'width':'381px' });
	$('#menuSEO li').each(function(i) {
		var pixelWidthArray=[53,48,132,119];
		menuMonitor($(this), i, pixelWidthArray, 331, 269);
	});

	// INFO SUB-MENU
	$('#menuINFO').css({ 'background-image':'url("IconsAndBackgrounds/menu-info.gif")', 'width':'363px' });
	$('#menuINFO li').each(function(i) {
		var pixelWidthArray=[53,59,83,60,70];
		menuMonitor($(this), i, pixelWidthArray, 345, 234);
	});
}

$(document).ready(function(){
	// handle logo and tagline clicking
	$('#aispireLogo').add('#tagline').click(function(){ returnToFrontPage(); });
	setupMenus(); // start the javascript re-working of the menu
	$('div.portfolioExample a.group').fancybox(); // if present
	$('#tagline').fadeIn(1250); // if present
	$('#banner').fadeIn(400); // if present
	preloadBanners();
	// fade all menu items ready for hover	
	$('li.menuItem').css({'background-color':'white', 'opacity':'0.3'});
//	$('li.menuCurrLocn').css({'background-color':'white', 'opacity':'0.3'});
});