/*



Custom Functions
*/

Event.observe(window, "load", init);


/*



This is the function that attached the Javascript functions to the page
*/
function init(){


	/*
	
	
	Embed Flash
	*/
	IEHacks.EmbedFlash("FlashFeature", 550, 210, "interface/flash/SlideShow.swf", true);



	/*
	
	
	
	Makes Internet Explorer render 32 bit PNGs properly
	*/
	IEHacks.MakePNGTransparent("#head h1 img");
	IEHacks.MakePNGTransparent("img#flamingo");
	IEHacks.MakePNGTransparent(".SearchTips img");
	IEHacks.MakePNGTransparent("generationsgold img");
	IEHacks.MakePNGTransparent("extrabuttons img");
	IEHacks.MakePNGTransparent("extrabuttons img");
	/*
	
	
	#PrimaryNav Drop Down show's the first ul child
	*/
	$$(".SubNav li", "#PrimaryNav li").each(function(node, i){
		if(node.down("ul")){
			node.down("a").addClassName("HasChildren");
			var ul = node.down("ul");
			node.observe(
				"mouseover",
				function(){
					node.addClassName("hover");
					ul.show();
				}
			);
			node.observe(
				"mouseout",
				function(){
					node.removeClassName("hover");
					ul.hide();
				}
			);
		}
	});
	/*
	
	Adjust the bottom of the drop downs
	*/
	$$(".SubNav li ul").each(function(node, i){
		var ul = node;
		var li = node.up();
		var pul = li.up();
		
		var ulh = ul.getDimensions().height;
		var pulh = pul.getDimensions().height;
		var lih = 21;
		var liy = ($$("#sub .SubNav")[0].immediateDescendants().indexOf(li)) * lih;
		var newuly = (liy + ulh - pulh) * -1;
		//           180 + 40 - 212
		// console.log("ulh: " + ulh + ", " + "pulh: " + pulh);
		// console.log("liy: " + liy);
		if (liy + ulh > pulh){
			// console.log("newuly: " + newuly);
			ul.setStyle({
				"top": new String(newuly + "px")
			});
		}
	});
	
	/*
	
	
	
	Forms
	*/
		/*
		
		
		
		Focus on an input
		*/
		$$("input").each(function(node, i){
			node.observe("focus", function(){node.toggleClassName("focus");});
			node.observe("blur", function(){node.toggleClassName("focus");});
		});
		/*
		
		
		
		Button Hover
		*/
		$$(".OnlineBanking button").each(function(node, i){
			node.observe("mouseover", function(){node.toggleClassName("hover");});
			node.observe("mouseout", function(){node.toggleClassName("hover");});
		});
		/*
		
		
		
		Clear the email input on the Newsletter form
		*/
		if ($("NewsletterEmail")){
			var node = $("NewsletterEmail");
			AlreadyReset = false;
			node.observe(
				"click",
				function(){
					if (!AlreadyReset){
						node.clear();
						AlreadyReset = true;
					}
				}
			);
		}


}


var IEHacks = {

	/*
	
	This function makes 32 bit PNG's with transparency work
	*/	
	MakePNGTransparent: function(selector) {
		if (navigator.userAgent.indexOf("MSIE ") == -1){
			return false;
		} else {
			$$(selector).each(function(node, i){
				var node = $(node);
				if (node.src.indexOf("png") == -1) {
					node.runtimeStyle.filter = "";
					return;
				}
				var oldSrc = node.src;
				node.src = "interface/images/transparent.gif";
				node.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldSrc + "',sizingMethod='scale')";
			});
		}
	},
	/*
	
	
	
	This function is used to embed the Flash into the page
	
	Variables:
	
		Variable Name   : Laman        : Data Type
	
		EF_object       : id of object : String
		EF_width        : width        : String
		EF_height       : height       : String
		EF_filename     : filename     : String
		EF_transparency : transparency : Boolean
	
	*/
	EmbedFlash: function(EF_object, EF_width, EF_height, EF_filename, EF_transparency) {
		/*
			var EF_object = "FlashFeature";
			var EF_width = "100%";
			var EF_height = "100%";
			var EF_filename = "/interface/flash/FlashFeature.swf";
			var EF_filename = true;
		*/
	
		if($(EF_object)){
			
			if (EF_transparency){
				var EF_transparency_ParamMarkup = new String('<param name="wmode" value="transparent" />');
				var EF_transparency_EmbedMarkup = new String('wmode="transparent"');
			} else {
				var EF_transparency_ParamMarkup = new String('');
				var EF_transparency_EmbedMarkup = new String('');
			}
	
			var FlashHTML =   new String('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + EF_width + '" height="' + EF_height + '" id="' + EF_object + '" align="middle">'
							+ '<param name="allowScriptAccess" value="sameDomain" />'
							+ EF_transparency_ParamMarkup
							+ '<param name="movie" value="' + EF_filename + '" />'
							+ '<param name="quality" value="high" />'
							+ '<embed src="' + EF_filename + '" '+ EF_transparency_EmbedMarkup + ' quality="high" width="' + EF_width + '" height="' + EF_height + '" name="' + EF_object + '" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
						+ '</object>');

			$(EF_object).update(FlashHTML);
		}
	}
}


