
// Open / close a case
jQuery(document).ready(function() {

	currentOpenFaq = null;

	// Close all narrow cases
	jQuery("ul.faq div.answer").hide();

	jQuery("ul.faq a.expand").click(function(e) {
		var childElements = jQuery(jQuery(e.target).parent("li").get(0)).children();
		if (jQuery(e.target).hasClass("collapse")) { // Close current
			jQuery(e.target).removeClass("collapse");
			jQuery(childElements[1]).hide();
			currentOpenFaq = null;
		} else { // Open new
			jQuery(childElements[1]).show();
			jQuery(e.target).addClass("collapse");
			if (currentOpenFaq != null) {
				var oldChilds = jQuery(jQuery(currentOpenFaq.target).parent("li").get(0)).children();
				jQuery(oldChilds[1]).hide();
				jQuery(currentOpenFaq.target).removeClass("collapse");
			}
			currentOpenFaq= e;
		}
		e.preventDefault();
	    return false;
	});

	jQuery("ul.faq a.expand").click(function(e) {
		var childElements = jQuery(jQuery(e.target).parent("li").get(0)).children();
		if (jQuery(e.target).hasClass("collapse")) { // Close current
			jQuery(childElements[1]).css({ visibility:"visible"});
			jQuery(childElements[2]).hide();
			jQuery(e.target).removeClass("collapse");
			currentOpenFaq = null;
		} else { // open new
			jQuery(childElements[1]).css({ visibility:"hidden"});
			jQuery(childElements[2]).show();
			jQuery(e.target).addClass("collapse");
			if (currentOpenFaq != null) {
				var oldChilds = jQuery(jQuery(currentOpenFaq.target).parent("li").get(0)).children();
				jQuery(oldChilds[2]).hide();
				jQuery(oldChilds[1]).css({ visibility:"visible"});
				jQuery(currentOpenFaq.target).removeClass("collapse");
			}
			currentOpenCaseWide = e;
		}
		e.preventDefault();
	    return false;
	});
	
	/*
	$("div#menu .subContentBottom").each(
			function() 
			{ 
				$(this).css("width", $(this).parent().width() + "px");
			}
		);
	*/
	// Menu functions
	$("div#menu > ul > li").hover(
		function()
		{
			var padding = 0;
			if ($(this).position().left > $("div#menu").outerWidth() - $(this).find(".subContent").outerWidth())
			{
				var leftPos = $(this).position().left + $(this).outerWidth() - $(this).find(".subContent").outerWidth();
				$(this).addClass("activeSub").find(".subContent").css("left", leftPos + "px").show();
			}
			else
			{
				$(this).addClass("activeSub").find(".subContent").css("left",($(this).position().left - padding) + "px").show();
			}
		}
		,
		function()
		{
			$(this).removeClass("activeSub").find(".subContent").hide();
		}
	);
});
function openWindow(myurl) {
	window.open(myurl,'mywindow','width=380,height=370');
}