// JQUERY
$(document).ready(function() {
    //	$('#contentAnimatieBanner').cycle({
    //		fx: 'fade',
    //		timeout: 3000
    //	});

    //	$('#contentAnimatieBanner2').cycle({
    //		fx: 'fade',
    //		timeout: 3000
    //	});

    if (jQuery.browser.msie)
        showMenu("show");
    else
        showMenu("fade");

    $('#postcode').bind("keypress", function(e, keyCode) {
        keyCode = keyCode || e.keyCode;
        if (keyCode == "13") {
            doPostcodeSearch();
            return false;
        }
    });

    $(document).pngFix();

    /* HOMEPAGE BLOKS */
    $('div.blok').parent().hover(function() {
        $(this).children("div.blok").addClass("selected");

        var im = $(this).attr("image");
        var bg = $('#homeBannerBack').css("background-image");
        if (bg.indexOf(im) < 0) {
            //$('#homeBannerBack').stop().fadeTo("fast", 0, function() {
            $('#homeBannerBack').css("background-image", "url(images/homesfeer/" + im + ")");
            //$(this).fadeTo("fast", 0, function() {
            //	$(this).fadeTo("fast", 1);
            //});
            //});
        }
        if (im == "") {
            $('#scroll1').show();
            $('#homeBannerBack').css("background-image", "url(images/homesfeer/Blok1.jpg)");
        }
        else {
            $('#scroll1').hide();
        }
    }, function() {
        $(this).children("div.blok").removeClass("selected");

        var im = $(this).parent().attr("image");
        var bg = $('#homeBannerBack').css("background-image");
        if (bg.indexOf(im) < 0) {
            //$('#homeBannerBack').stop().fadeTo("fast", 0, function() {
            $('#homeBannerBack').css("background-image", "url(images/homesfeer/" + im + ")");
            //$(this).fadeTo("fast", 0, function() {
            //	$(this).fadeTo("fast", 1);
            //});
            //});
        }
        if (im == "") {
            $('#scroll1').show();
            $('#homeBannerBack').css("background-image", "url(images/homesfeer/Blok1.jpg)");
        }
        else {
            $('#scroll1').hide();
        }
    });

    /* COLLECTIE BLOKS */
    $(".contentCollectie").hover(function() {
        $("#collectie1detail, #collectie2detail, #collectie3detail, #collectie4detail").children(".contentCollectieInfo").hide();
        $("#collectie1detail, #collectie2detail, #collectie3detail, #collectie4detail").children(".contentCollectieGroepWrapper").show();
        $("#" + this.id + "detail").children(".contentCollectieGroepWrapper").hide();
        $("#" + this.id + "detail").children(".contentCollectieInfo").show();
        sIFR.replace(arialbold, {
            selector: '.contentCollectieInfo .content h6'
				, wmode: 'transparent'
				, css: [
					'.sIFR-root { color: #000000; font-size: 12px; font-weight:bold; text-transform:uppercase; }'
				, '.sIFR-root a { color: #000000; text-decoration:none; }'
				, '.sIFR-root a:hover { color: #000000; text-decoration:undeline; }'
				]
				, filters: {
				    DropShadow: {
				        distance: 1
						 , color: '#000000'
						 , strength: 0.5
				    }
				}

        });
    }, function() {
        void (0);
    });
    $("#collectie1detail, #collectie2detail, #collectie3detail, #collectie4detail").children(".contentCollectieInfo").hover(function() {
        void (0);
    }, function() {
        $(this).parent().children(".contentCollectieGroepWrapper").show();
        $(this).hide();
    });

    /* IMAGE FADERS  */
    var imagesToFade = ".contentCollectieGroep img, .middleBottom1Foto img"; /* Komma gescheiden toevoegen */
    $(imagesToFade).fadeTo("fast", 0.7);
    $(imagesToFade).hover(function() {
        $(this).stop();
        $(this).fadeTo("medium", 1);
    }, function() {
        $(this).stop();
        $(this).fadeTo("medium", 0.7);
    });

    /* WINKELS TOOLTIPS */
    if (jQuery.browser.msie) {
        $("#kaartnaam").hide();
    }
    else {
        $("#kaartnaam").fadeTo("fast", 0, function() {
            $(this).show();
        });
    }
    $("#kaartnl a").hover(function() {
        var left = $(this).css("margin-left");
        var top = $(this).css("margin-top");
        left = left.replace("px", "") - "";
        top = top.replace("px", "") - "";
        left = left + 5;
        top = top - 35;
        $("#naamTekst").text($(this).attr("name"));
        $("#kaartnaam").css("margin-left", left);
        $("#kaartnaam").css("margin-top", top);
        busy = true;
        if ($("#kaartnaam").is(":animated"))
            if (jQuery.browser.msie)
            $("#kaartnaam").stop().show();
        else
            $("#kaartnaam").stop().fadeTo("medium", 1);
        else
            if (jQuery.browser.msie)
            $("#kaartnaam").show();
        else
            $("#kaartnaam").fadeTo("medium", 1);
    }, function() {
        if ($("#kaartnaam").is(":animated"))
            if (jQuery.browser.msie) {
            $("#kaartnaam").stop().hide();
            doResetVestiging();
        }
        else
            $("#kaartnaam").stop().fadeTo("medium", 0, doResetVestiging);
        else
            if (jQuery.browser.msie) {
            $("#kaartnaam").hide();
            doResetVestiging();
        }
        else
            $("#kaartnaam").fadeTo("medium", 0, doResetVestiging);
    });

    function doResetVestiging() {
        $("#naamTekst").text("");
        $("#kaartnaam").css("margin-left", "25px");
        $("#kaartnaam").css("margin-top", "0px");
    }
    $("#kaartnl a").bind("click", function() {
        $(".vestigingen").hide();
        $("#contact").hide();
        $("#vestiging" + $(this).attr("vid")).fadeIn("slow");
    });

    $("#middleTopPrijsRood").hover(function() {
        $('#prijsPopup').show();
    }, function() {

    });
    $("#prijsPopup").hover(function() {

    }, function() {
        $(this).hide();
    });

    if (false) {
        var bannersToClick = ".bannerHolderGroen, .bannerHolderRood, .bannerHolderOranje, .bannerHolderGrijs, .bannerHolderGrijs2"; /* Komma gescheiden toevoegen */
        $(bannersToClick).bind("click", function() {
            var link = $(this).find("a").attr("href");
            if (link != undefined)
                location.href = link;
        });
    }
});

// Jquery Sorting

	function doProductSortReset()
	{
		$("#containerMiddleBottom1 div.middleBottom1Product").children(".middleBottom1Foto, p:not([class=middleBottom1ProductTitel])").fadeTo("medium",1);
		var rows = [];
	
		$("#containerMiddleBottom1 div.middleBottom1Product").each(function(){
			//rows[rows.length] = [$(this).find("p.middleBottom1ProductTitel").html().toLowerCase(),this];
			rows[rows.length] = [$(this).attr("default").toLowerCase(),this];
		});

		$("#middleTop1Foto").html($(".hidOrgImage input").attr("value"));
		$("#middleTop1Tekst").html($(".hidOrgTekst input").attr("value"));

		sIFR.replace(arialbold, {
		    selector: 'h3'
	        , wmode: 'transparent'
	        , css: [
		        '.sIFR-root { color: #f39600; font-size: 18px; font-weight:bold; }'
	        ]
		});
		
		Sorting(rows);
	}
	
	function doProductSort(group, id){
		$("#containerMiddleBottom1 div.middleBottom1Product").attr("sort", "b").children(".middleBottom1Foto, p:not([class=middleBottom1ProductTitel])").fadeTo("medium", 0.2);
		$("#containerMiddleBottom1 div.middleBottom1Product[group*=|" + group + "|]").children(".middleBottom1Foto, p:not([class=middleBottom1ProductTitel])").fadeTo("fast", 1);
		$("#containerMiddleBottom1 div.middleBottom1Product[group*=|" + group + "|]").attr("sort", "a");

		var rows = [];
	
		$("#containerMiddleBottom1 div.middleBottom1Product").each(function(){
			rows[rows.length] = [$(this).attr("sort").toLowerCase(),this];
		});

		$("#middleTop1Foto").html($("#FOTO_" + id).html());
		$("#middleTop1Tekst").html($("#TEXT_" + id).html());
		
		sIFR.replace(arialbold, {
		    selector: 'h3'
	        , wmode: 'transparent'
	        , css: [
		        '.sIFR-root { color: #f39600; font-size: 18px; font-weight:bold; }'
	        ]
		});

		Sorting(rows);
	};
	
	function Sorting(rows)
	{
		rows.sort(function(a,b){
			if (a[0] < b[0])
				return -1
			else if (a[0] > b[0])
				return 1
			else
				return 0;
		});

		$.each(rows, function(){
			this[1].parentNode.appendChild(this[1]);
		});	
	}

// JAVASCRIPT
function checkClearField(t, f, val)
{
	field = document.getElementById(f);
	if (field)
	{
		if (t == 1)
		{
			if (field.value == "")
			{
				field.value = val;
				field.style.color = "#8e8e8e";
			}
		}
		else if(t == 0)
		{
			if (field.value == val)
			{
				field.value = "";
				field.style.color = "";
			}
		}
	}
}

function showMenu(t)
{
	if (t == "fade") /* FADE IN/UIT MENU */
	{
		$('#topMenu li[hassub=nee]').hover(function(){
			$("ul.subMenu").hide();
		},function(){ 
			void(0); 
		});
		$('#topMenu li[hassub=ja]').hover(function(){
			$("ul.subMenu").fadeOut();
			$(this).attr("hassub","nee");
			$(this).children("a").removeClass("selected");						   
			$(this).children("ul.subMenu").fadeIn();						
		},function(){ 
			$(this).attr("hassub","ja"); 
		});
		
		$('ul.subMenu').hover(function(){
			$(this).attr("hassub","nee");
			$(this).parent().children("a").addClass("selected");						   
		},function(){
			$(this).attr("hassub","ja");
			$(this).parent().children("a").removeClass("selected");						   
			$(this).fadeOut();	
		});
	}
	else if(t == "show") /* SHOW/HIDE MENU */
	{
		$('#topMenu li[hassub=nee]').hover(function(){
			$("ul.subMenu").hide();
		},function(){ 
			void(0); 
		});
		$('#topMenu li[hassub=ja]').hover(function(){
			$("ul.subMenu").hide();
			$(this).attr("hassub","nee");
			$(this).children("a").removeClass("selected");						   
			$(this).children("ul.subMenu").show();						
		},function(){ 
			$(this).attr("hassub","ja"); 
		});
		
		$('ul.subMenu').hover(function(){
			$(this).attr("hassub","nee");
			$(this).parent().children("a").addClass("selected");						   
		},function(){
			$(this).attr("hassub","ja");
			$(this).parent().children("a").removeClass("selected");						   
			$(this).hide();	
		});
	}
}

function doPostcodeSearch() {
    var value = $("#postcode").attr("value");
    location.href = "default.aspx?content=75&postcode=" + value;

}

function highlight(pointer) {

    pointer.style.background = "#EEEEEE";
}

function lowlight(pointer) {
    pointer.style.background = "";
}

function showmodal(pid, target) {
    window.showModalDialog('/admin/webpages/algemeen/editpage.aspx?content=' + pid + '&target=' + target, '', 'dialogHeight: 500px; dialogWidth: 500px;');
    window.location.reload();
}