$(document).ready(function(){
	$(".tabs").tabs();

	$("#menu li").each(applyMenu);

	$("input[type='text']").each(maakTextBox);
	$("input[type='password']").each(maakTextBox);
	$("input.button").each(maakButton);
	$("input.button_pijllinks").each(maakButton);
	$("input.button_pijlrechts").each(maakButton);

	$(".textBox .links").each(function(i){
		if ($.browser.mozilla)
		{
			if (parseFloat($.browser.version.substr(0, 3)) >= 1.9)
			{ // FF3 en hoger
				$(this).css({ position: "relative", top: "-1px" });
			}
		}
	});

	$(".textBox .rechts").each(function(i){
		if ($.browser.mozilla)
		{
			if (parseFloat($.browser.version.substr(0, 3)) >= 1.9)
			{ // FF3 en hoger
				$(this).css({ position: "relative", top: "-1px" });
			}
		}
	});
});

$(window).resize(function(){
	$("#menu li").each(applyMenu);
});

var opened = new Array();
var c = 0;

function applyMenu(i)
{
		this.onmouseover = function()
		{
			var dw = $(document).width();

			if ($.browser["msie"])
			{
				if (this.id == "")
					this.id = "_ele" + (c++);
			}

			this.className += " hover";

			var w = $(this).find(".dropContent table").width();

			if (w < 250)
				w = 250;

			if (w < $(this).width() + 14)
				w = $(this).width() + 14;

			$(this).find(".dropContent").css({ width: w });

			$(this).find("iframe").css({ height: $(this).find(".dropContent").height()}); // Voor IE6 om de selectboxen weg te halen
			$(this).find("iframe").css({ width: $(this).find(".dropContent").width()}); // Voor IE6 om de selectboxen weg te halen
			$(this).find(".dropTop").css({ width: $(this).find(".dropContent").width() + 14 });

			if (this.id != "laatste")
				$(this).find(".dropTop .dropMidMid").css({ width: $(this).width() - 9});
			else
				$(this).find(".dropTop .dropMidMid").css({ width: $(this).width() - 14});

			$(this).find(".dropTop .dropMid").css({
				width: $(this).find(".dropContent").width() - 8 - $(this).find(".dropTop .dropMidMid").width() - 7 + "px"
			});
			$(this).find(".dropBottom").css({ width: ($(this).find(".dropContent").width() + 14) + "px" });
			$(this).find(".dropBottom .dropMid").css({ width: $(this).find(".dropContent").width() - 8 });

			if (dw < $(document).width() || this.className.indexOf("mirror") > -1)
			{
				if (this.className.indexOf("mirror") < 0)
					this.className += " mirror";

				if (this.id != "laatste")
					$(this).find(".drop").css({ left: -($(this).find(".drop").width() - $(this).width()) });
				else
					$(this).find(".drop").css({ left: -($(this).find(".drop").width() - ($(this).width() - 5)) });

				var a = $(this).find(".dropTop .dropMidMid").width();
				var b = $(this).find(".dropTop .dropMid").width();
				$(this).find(".dropTop .dropMidMid").css({ width: b });
				$(this).find(".dropTop .dropRightMid").css({ width: 20 });
				$(this).find(".dropTop .dropMid").css({ width: a - 10 });
			}

			if (($.browser["msie"]) && (opened[this.id] != true))
			{
				this.onmouseout();
				opened[this.id] = true;
				this.onmouseover();
			}
		}
		this.onmouseout = function()
		{
			this.className = this.className.replace(" hover", "");
			this.className = this.className.replace("hover", ""); //Firefox 3 voor als dit de enige class is.
		}
}

function maakTextBox(i)
{
	$(this).css({
			width: ($(this).width() - 10) + "px",
			borderLeft: "none",
			borderRight: "none"
		});
		$(this).wrap('<span class="textBox"></span>');
		$(this).before('<span class="links"></span>');
		$(this).after('<span class="rechts"></span>');

		if ($.browser.mozilla && (parseFloat($.browser.version.substr(0, 3)) < 1.9))
		{ // FF2 en lager
			$(this).css({ border: "1px solid black" });
		}
}

function maakButton(i)
{
    if ($(this).attr('type') == 'image')
        return;

    var w = $(this).width();
    var $this = $(this);
    
    var a = "";
    
    if ($(this).hasClass("button_pijllinks"))
    	a = " pijllinks";
    else if ($(this).hasClass("button_pijlrechts"))
    	a = " pijlrechts";
    
    $(this).wrap('<span class="roundButtom'+a+'" style="width: '+w+'px"></span>');
    $(this).before('<span class="links"></span>');
    $(this).after('<span class="rechts"></span>');
    
    if (w == 0)
    {
    	function setSize()
    	{
    		var w = $this.width();
    		if (w == 0)
    			setTimeout(setSize, 1000);
    		else
    			$this.parent().width(w);
    	}
    	
    	setSize();
    }
}

function openZoekBalk()
{
	$("#zoekbalk #uitgebreid").css({ display: "none" });
	$("#zoekbalk .extra").css({ display: "block" });
}

function sluitZoekBalk()
{
    $("#zoekbalk .extra").css({ display: "none" });
	$("#zoekbalk #uitgebreid").css({ display: "block" });
}

function openIntro(i)
{
	$("." + i + "").css({ display: "block" });
	$(".open" + i + "").css({ display: "none" });
	$(".sluit" + i + "").css({ display: "block" });


}

function sluitIntro(i)
{
	$("." + i + "").css({ display: "none" });
	$(".sluit" + i + "").css({ display: "none" });
	$(".open" + i + "").css({ display: "block" });

}

function openBookmarkPopup()
{
	$("#popup").css({ display: "block" });
	$("#popup").css({ visibility: "visible" });
}

function sluitBookmarkPopup()
{
    $("#popup").css({ display: "none" });
    $("#popup").css({ visibility: "hidden" });
}
