// JavaScript Document

$(document).ready(function(){

	// test answer
	$(".testAnswer").hover(
		function(){
			$(this).css("background-image", "url(/assets/imgs/content/checkbox_checked.gif)");
		},
		function(){
			$(this).css("background-image", "url(/assets/imgs/content/checkbox.gif)");
		}
	);

	// dropdown menu
	$("#mainMenu > li[class!=professionalsLink]").hover(
		function(){
			$(this).find("ul").show();
			$(this).find("> a:not(.active)").css("color", "#1e3e69");
		},
		function(){
			$(this).find("ul").hide();
			$(this).find("> a:not(.active)").css("color", "#4e6e9a");
		}
	);
	
	// search form
	$("#searchFormRight").submit(function() {
		if (true)
		{
			return true;
		}
	});

	// setup accordions
	setupAccordion(".accordion", ".collapsable", ".opened", false, 100);
	
	// replace headers
	replaceHeaders("h1:not([class])", "/assets/swf/headers/h1.swf", "100%", "34", "8.0.0");
	replaceHeaders("h2:not([class])", "/assets/swf/headers/h2.swf", "100%", "20", "8.0.0");
	replaceHeaders("h2.contentBlockHeaderTitle", "/assets/swf/headers/h2_block.swf", "100%", "20", "8.0.0");
	replaceHeaders("h2.testQuestion", "/assets/swf/headers/h2_test.swf", "100%", "20", "8.0.0");
	
	// replace with image
	textToImage(".testimonialHeading", "/assets/imgs/content/testimonialHeaderLarge.gif");
	textToImage(".morelink a:not([class])", "/assets/imgs/content/moreLinks/leesmeer.gif");
	textToImage(".morelink a.testimonial", "/assets/imgs/content/moreLinks/leeshetheleverhaal.gif");
	textToImage(".morelink a.gebitsproblemen", "/assets/imgs/content/moreLinks/allesovergebitsproblemen.gif");
	textToImage(".morelink a.gebitscontrole", "/assets/imgs/content/moreLinks/allesovergebitscontrole.gif");
	textToImage(".morelink a.daMoreInfo", "/assets/imgs/content/moreLinks/meerinfo_en_speciale_actie.gif");
	textToImage(".onlineCheckDark", "/assets/imgs/content/doeonlinecheck_dark.gif");
	textToImage(".onlineCheckLight", "/assets/imgs/content/doeonlinecheck_light.gif");
	
});

function textToImage(elem, img)
{
	$(elem).html('<img src="' + img + '" alt="' + $(elem).html() + '" />');
}

function setupAccordion(containerElem, collapsableElem, openedElem, allowMultipleOpen, speed)
{
	$(containerElem + " " + collapsableElem).not(openedElem).children().not(":first-child").hide();	
	
	$(containerElem + " " + collapsableElem + " :first-child").click(function(){
		if (!allowMultipleOpen)
		{
			//$(containerElem + " " + collapsableElem).children().not(":first-child").hide(speed);
			$(this).parent().prevAll().children().not(":first-child").hide(speed);
			$(this).parent().nextAll().children().not(":first-child").hide();
			$(this).nextAll().show();
		} 
		else 
		{
			$(this).nextAll().toggle(speed);
		}
	});
}

function replaceHeaders(elem, swf, w, h, version)
{
	$(elem).each(function(i){

		var flashvars = {
			txt: $(this).html()
		};
		
		var params = {
			menu: "false",
			quality: "best",
			wmode: "transparent"
		};
		var attributes = {};
	
		$(this).html("<span id=" + this.tagName + "_" + this.className + "_" + i + "></span>");
	
		swfobject.embedSWF(swf, this.tagName + "_" + this.className + "_" + i , w, h, version, "/assets/swf/expressInstall.swf", flashvars, params, attributes);

	});
}

function doSearch(po)
{
	location.href="/gebitscontrole/zoek-een-dierenarts/" + po;
}

function doEnterSearch(evt, po)
{
	if (evt.keyCode == 13)
	{
		doSearch(po);
	}
}
