function urlEncode(str)
{
    regular = new RegExp("/","g");
    val = escape(str);
    val = val.replace(regular,"%2F");
    return val;
}

$(document).ready(function() {

    $('#slider').nivoSlider({ effect: 'fade', captionOpacity: 1 });

    $(".menuBox li a").mouseover(function() {
        $(this).parent().find("ul.subMenu").slideDown('fast').show();

        $(this).parent().hover(function() {
        }, function() {
            $(this).parent().find("ul.subMenu").slideUp('fast');
        });
    });

    $("#searchButton").click(function() {
        var value = $("#searchTerm").val();
        window.location = "/search/" + urlEncode(value);
        return false;
    });

    $("#searchForm").submit(function() {
        var value = $("#searchTerm").val();
        window.location = "/search/" + urlEncode(value);
        return false;
    });

    $("#searchTerm").blur(function() {
        if (this.value == '')
            this.value = 'waar zoek je naar?';
    });

    $("#searchTerm").focus(function() {
        if (this.value == 'waar zoek je naar?')
            this.value = '';
    });

    $(".newTab").click(function() {
        $(".newContent").each(function() {
            this.style.display = "none";
        });
		$(".newTab").removeClass("selected");

		$(this).addClass("selected");
        var id = this.id.substring("newTab".length);
		console.log(id);
		document.getElementById("newTabContent" + id).style.display = "block";
        return false;
    });
    
    $(".featuredTab").click(function() {
        $(".featuredBlockContent").each(function() {
            this.style.display = "none";
        });
		$(".featuredTab").removeClass("selected");

		$(this).addClass("selected");
        var id = this.id.substring("featuredTab".length);
		document.getElementById("featuredTabContent" + id).style.display = "block";
        return false;
    });

	$("a[rel=fancybox]").fancybox({
		'autoScale'			: true,
		'type'				: 'iframe'
	});
    
	$("a[rel=login]").fancybox({
		'autoDimensions'	: true,
		'href'				: '/user/login?referer='+escape(document.location),
		'width'				: 600,
		'height'			: 550,
		'type'				: 'iframe',
		'showNavArrows'		: false
	});
});  

