$(document).ready(function() {
    if ($.browser.msie) {
        if ($.browser.version < 7) {
            DD_belatedPNG.fix('.png');
            
            $("#acties > tbody > tr > td > img.png").each(function(i, val) {
                var src = $(val).attr("src");
                src = src.replace(/.png/, ".jpg");
                $(val).attr("src", src);
            });
        }
    }

    menuInit();
    loadBackground();

    if (jQuery.browser.mozilla && jQuery.browser.version.substr(0, 3) != '1.9') { //firefox 2.0 flash background fix, must be done after inserting flash, written by Tom Vanassche :p
        $("#noFlash").attr("style", "z-index: -1;");
    }

    fixFlash();

    initRadioSpot();
    
    //initUpdatePanelCallback();
});

function initRadioSpot() {
    $(".btnRadiospot_nl").click(function() {

        //Show radiospot
        $('<div />').addClass('overlay').appendTo('body').show();
        $('body').append('<div class="radiospot"><div id="radiospot">No Flash Support</div><a href="#" id="closeRadiospot">Sluit</a></div>').show();
        swfobject.embedSWF("radiospot/RadioSpot.swf", "radiospot", "200", "100", "9.0.0", "radiospot/expressInstall.swf", { url: "radiospot/vilmorin_nl.mp3" }, { menu: "false", wmode: "transparent" });

        $(".overlay").click(function() {
            //Hide radiospot
            $('.overlay').remove();
            $('.radiospot').remove();

        });
        $("#closeRadiospot").click(function() {

            $('.overlay').remove();
            $('.radiospot').remove();
        });
    });
    $(".btnRadiospot_fr").click(function() {
        //Show radiospot
        $('<div />').addClass('overlay').appendTo('body').show();
        $('body').append('<div class="radiospot"><div id="radiospot">No Flash Support</div><a href="#" id="closeRadiospot">Ferm&#233;</a></div>').show();
        swfobject.embedSWF("radiospot/RadioSpot.swf", "radiospot", "200", "100", "9.0.0", "radiospot/expressInstall.swf", { url: "radiospot/vilmorin_fr.mp3" }, { menu: "false", wmode: "transparent" });

        $(".overlay").click(function() {
            //Hide radiospot
            $('.overlay').remove();
            $('.radiospot').remove();

        });
        $("#closeRadiospot").click(function() {

            $('.overlay').remove();
            $('.radiospot').remove();
        });
    });
}

function menuInit() {
    $(".mainUl ul").hide();
    
    $(".mainUl a").click(function() {
        $(".mainUl > ul").slideUp("slow");    
    });

    $(".mainUl a").toggle(
       function() {
           if ($(this).children("img")) {
               $(this).children("img").attr("src", siteUrl + "images/arrow-down.gif");
           };
           $(this).next("ul").slideDown("slow");
       },
       function() {
           if ($(this).children("img")) {
               $(this).children("img").attr("src", siteUrl + "images/arrow-right.gif");
           };
           $(this).next("ul").slideUp("slow");
       }
    );
}

function setHeightContent(iHeight) {
    if ($("#content2").length > 0) {
        $("#content2").attr("style", "height: " + (iHeight + 31) + "px;");
    }
}

function loadBackground() {
    if ($("#noFlash").length > 0) {
        var flashvars = {};
        flashvars.imageUrl = "" + siteUrl + $("#ctl00_hdnBackground").attr("value");
        var params = {};
        params.wmode = "transparent";
        var attributes = {};
        swfobject.embedSWF("" + siteUrl + "background.swf", "noFlash", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
    }    
}

function fixFlash() {
    if ($("#webnet4u").length > 0) {
        var strLink = document.getElementById("webnet4u").innerHTML;
        document.getElementById("webnet4u").innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"16\" height=\"19\" id=\"w-logo_WHITE\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"" + siteUrl + "webnet4u.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#000000\" /><embed src=\"" + siteUrl + "webnet4u.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#000000\" width=\"16\" height=\"19\" name=\"w-logo_WHITE\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object><br/>" + strLink;
    }
}

function showProductData(intProductId, intCategoryId, intLanguageId, strPagename) {
    $.ajax({
        type: "POST",
        url: strPagename + ".aspx/GetProductHTML",
        data: "{'intProductId': " + intProductId + ", 'intCategoryId': " + intCategoryId + ", 'intLanguageId': " + intLanguageId + "}", //{\count\:\" + count + \}
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $('#contentRight').html(msg.d);
            window.location.hash = 'top';
        }
    });
}
