﻿$(function() {

	// set a cookie to keep the flash movie hidden for the duration of the session
	// set the variable
	var flash_intro = $.cookie("flash_intro");

	// we only need to run this on the home page
	if ($("body").hasClass("home")) {
		$("#content_main h2").hide();
		if (swfobject.hasFlashPlayerVersion("8.0.0")) {
			// user has Flash
			swfobject.embedSWF(appRoot + "App_Themes/YourPackagingPartner/ypp.swf", "flash", "960", "690", "8.0.0");
		} else {
			// computer says no
			$("#flash").html('<h1>Flash Plugin required</h1><p>You need to download the free Flash Player plugin to view our site intro.</p><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p><p>You can, however, view the rest of the site. <a id="enter_site" href="#">Enter the site here.</a></p>');
			$("#enter_site").click(function() {
				$("#flash").fadeTo(666, 0).remove();
				removeFlash();
			});
		}
		// if the user has seen the animation, jib it for this session
		if (flash_intro == "viewed") {
			$("#content_main h2").show().css("visibility","visible");
			$("#flash").css("z-index", "-1").remove();
			$("#navigation, #content, #footer").css("opacity", "1.0").removeClass("flash_hide");
		};
	}

	// style first #content paragraph
	$(".home #content p:first").addClass("p_first");

	// main navigation map
	try {
		$("img[usemap]").maphilight();
	}
	catch (err)
	{ /* fall over silently */ }

	/* i doubt we need to add this, it makes things look a bit messy
	$("map *").tooltip({
	delay: 100,
	showURL: false,
	top: -25,
	left: 10
	}); */

	// lightbox the case study side images
	if ($("body").hasClass("case_studies")) {

	}

}); 

function removeFlash() {				
	//set the cookie
	$.cookie("flash_intro", "viewed");
	$("#content_main h2").show().css("visibility","visible");
	// fadeIn #navigation & #footer
	$("#navigation, #footer").css("opacity", "0.0").removeClass("flash_hide").fadeTo(500,1, function() {
		// fadeIn #content
		$("#content").css("opacity", "0.0").removeClass("flash_hide").fadeTo(666,1, function() {
			$("#content").css("background", "#ffffff");  // IE needs this, otherwise it eats the bold text
		});
		$("#content_main h2").css("display","block");
		// remove #flash
		$("#flash").fadeTo(666,0).remove();
	});	
}

try {

	// maphilight plugin for the main menu
	$.fn.maphilight.defaults = {
		fade: true,
		fill: true,
		fillColor: 'ffffff',
		fillOpacity: 0.3,
		stroke: true,
		strokeColor: '7b8d27',
		strokeOpacity: 1,
		strokeWidth: 1
	}
}
catch (err)
{ /* fall over silently */ }



// used in the intro flash file
function openWin(url, w, h) {
	var winprop = "width=" + w + ",height=" + h;
	openwin = window.open(url,'',winprop);
}


