// the sole purpose of this script is to defeat the background image flicker for image-replaced links in IE 6
try {
 document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

/* substitutes for CSS2 selectors
******************************************************************/
$(document).ready(function(){
	$("input[type='text']").addClass("text");
	$("#content-aside .section > :header").addClass("section-head");
	$("#content-aside .section > div").addClass("section-body");
});

/* accordion
******************************************************************/
$(document).ready(function(){
	// assign appropriate classes to accordion children (using 'even' and 'odd' to select appropriate children)
	$(".accordion").children(":even").addClass("accordion-topic").end().children(":odd").addClass("accordion-panel");
	// initialize accordion
	$(".accordion").children(":first").addClass("on").end().children(":odd:not(:first)").hide();
	$(".accordion > :even").click(function(){
		if (!$(this).hasClass("on")) {
			$(".accordion > :even.on").removeClass("on");
			$(this).addClass("on");
			$(".accordion > :odd:visible").slideUp();
			$(this).next().slideDown();
		}
	});
	$(".accordion > :even").hover(function(){
		$(this).not(".on").addClass("hover");
	}, function(){
		$(this).removeClass("hover");
	});	
});

/* toggleVal
******************************************************************/
$(document).ready(function() {
	$("#identification").addClass("inactive").toggleVal();
	$("#password").addClass("inactive").toggleVal();
});

$(document).ready(function() {
	// make any links with rel="external" to open in new windows
	$("a[@rel$='external']").click(function(){
		this.target = "_blank";
	});
});

/* Flash handling
******************************************************************/
$(document).ready(function(){
/* headers
*******************************/
	// before setting specific section headers, make the default be the one used in "our story" section
	$("#header").flash(
		{ src: "/flash/ecl_green_banner.swf", width: 945, height: 180 }, 
		{ update: false, version: 8 }
	);
	$("#home #header").flash(
		{ src: "/flash/ecl_home_page.swf", width: 945, height: 305 }, 
		{ update: false, version: 8 }
	);
	$("#personal-banking #header").flash(
		{ src: "/flash/ecl_yellow_banner.swf", width: 945, height: 180 }, 
		{ update: false, version: 8 }
	);
	$("#business-banking #header").flash(
		{ src: "/flash/ecl_red_banner.swf", width: 945, height: 180 }, 
		{ update: false, version: 8 }
	);
/* video
*******************************/
	// load the fresh growth video
	$("#growth-video").flash(
		{ src: "/flash/growth/ecl_whitecastle.swf", width: 320, height: 411, flashvars: { globalAssetPath: '/flash/growth/', videoToLoad: 'ecl_whitecastle.flv'} }, 
		{ update: false, version: 8 }
	);
	
	// load the first video
	$("#video").flash(
		{ src: "/flash/video/ecl_question.swf", width: 473, height: 370, flashvars: { globalAssetPath: '/flash/video/', videoToLoad: 'ecl_question1_standing.flv'} }, 
		{ update: false, version: 8 }
	);
	// add .hover class to each video question to make them appear clickable
	$("#video_q li").hover(
		function () {
			$(this).addClass("hover");
		}, 
		function () {
			$(this).removeClass("hover");
		}
	);
	// set up click event for each video question to remove the current video and load the requested one
	$("#video_q li").each(function(i) {
		// set index to 1
		i++;
		$(this).bind("click", function() {
			$("#video").empty().flash(
				{ src: "/flash/video/ecl_question.swf", width: 473, height: 370, flashvars: { globalAssetPath: '/flash/video/', videoToLoad: 'ecl_question' + i + '_standing.flv'} }, 
				{ update: false, version: 8 }
			);
		});
	});
});

/* survey page
******************************************************************/
$(document).ready(function(){
	// set up click event for the anchor links to control the accordion functionality
	$("a.accordion_control").click(function(){
		// grab target id from the anchor link href (but don't include the '#' part)
		var target_id = $(this).attr("href").split("#");
		if (!$(".accordion > :even#" + target_id[1] + "").hasClass("on")) {
			$(".accordion").children(":even.on").removeClass("on").end().children(":even#" + target_id[1] + "").addClass("on").end().children(":odd:visible").slideUp().end().children(":even#" + target_id[1] + "").next().slideDown();
		}
		return false;
	});
	$("a.accordion_control").hover(function(){
		var target_id = $(this).attr("href").split("#");
		if ($(".accordion > :even#" + target_id[1] + "").hasClass("on")) {
			$(this).attr("style", "text-decoration:none; cursor:default");
		}
	}, function(){
		var target_id = $(this).attr("href").split("#");
		if ($(".accordion > :even#" + target_id[1] + "").hasClass("on")) {
			$(this).removeAttr("style");
		}
	});
});