// The next line enables jQuery IntelliSense in Visual Studio:
///<reference path="/common/js/IntelliSense/jquery-1.3.1-vsdoc.js" />


$(document).ready(function() {

    Cufon.replace('h1.custom', { fontFamily: 'Bell Gothic Std' });
    Cufon.replace('h2.custom', { fontFamily: 'Bell Gothic Std' });
    Cufon.replace('h3.custom', { fontFamily: 'Bell Gothic Std' });
    Cufon.replace('.shopname', { fontFamily: 'Franklin Gothic Demi' });
    Cufon.replace('.extension', { fontFamily: 'Franklin Gothic Demi' });
    Cufon.now();

    $('a#ShowLoginForm').click(function() {
        $('#LoginForm').slideToggle('slow');
		$('#LoginLink').hide();
    });

    $('#Login').click(function() {
        $('#LoginFormKassa').slideToggle('slow');
    });


    $(".kenmerk").tooltip({
        track: true,
        delay: 0,
        showURL: false,
        opacity: 1,
        fixPNG: true,
        showBody: "&#187;",
        textAlign: 'left'
    });

    if ($('#bestelling_controleren input:radio:checked').val() == 'iDEAL') {
        $("#question-iDEAL_Bank").show("slow");
        $(".btnBestellingControlereniDEAL").attr("style", "visibility:visible");
        $(".btnBestellingControleren").attr("style", "visibility:hidden");
    } else {
        $("#question-iDEAL_Bank").hide("slow");
        $(".btnBestellingControlereniDEAL").attr("style", "visibility:hidden");
        $(".btnBestellingControleren").attr("style", "visibility:visible");
    }

    $('#question-BetalingsMethode').click(function() {
        if ($('#bestelling_controleren input:radio:checked').val() == 'iDEAL') {
            $("#question-iDEAL_Bank").show("slow");
            $(".btnBestellingControlereniDEAL").attr("style", "visibility:visible");
            $(".btnBestellingControleren").attr("style", "visibility:hidden");
        } else {
            $("#question-iDEAL_Bank").hide("slow");
            $(".btnBestellingControlereniDEAL").attr("style", "visibility:hidden");
            $(".btnBestellingControleren").attr("style", "visibility:visible");
        }
        if ($('#bestelling_controleren input:radio:checked').val() == 'rembours') {
            $('#lblRembourskosten').attr("style", "display:block")
            $('#valRembourskosten').attr("style", "display:block")
            $('#valBTWRembours').attr("style", "display:block")
            $('#valTotaalRembours').attr("style", "display:block")
            $('#valBTW').attr("style", "display:none")
            $('#valTotaal').attr("style", "display:none")
        } else {
            $('#lblRembourskosten').attr("style", "display:none")
            $('#valRembourskosten').attr("style", "display:none")
            $('#valBTW').attr("style", "display:block")
            $('#valTotaal').attr("style", "display:block")
            $('#valBTWRembours').attr("style", "display:none")
            $('#valTotaalRembours').attr("style", "display:none")
        }
    });

    $(".lnkAfleverAdres").click(function() {
        $(".afleveradres").slideToggle("slow");
    });

    if ($("#question-KlantAfleverVoornaam input").val() != '' || $("#question-KlantAfleverAchternaam input").val() != '' || $("#question-KlantAfleverStraat input").val() != '' || $("#question-KlantAfleverHuisnummer input").val() != '' || $("#question-KlantAfleverPostcode input").val() != '') {
        $(".afleveradres").attr("style", "display:block");
    }

    $(".thumbimage").click(function() {
        // Display big image
        var id = $(this).attr('name');
        $('.ProductDetailFoto').attr('style', 'display:none');
        $('#' + id).attr('style', 'display:block');

        // Change selected item in kleur dropdown
        var arrKleurId = id.split("_");
        $("#question-OrderRegelProductKleurId option[value='" + arrKleurId[1] + "']").attr('selected', 'selected');
    });

    // Change big image by kleur dropdown
    $('.question-OrderRegelProductKleur').change(function() {
        var id = $('#question-OrderRegelProductKleurId :selected').val();
        if ($('#foto_' + id).length > 0) {
            $('.ProductDetailFoto').attr('style', 'display:none');
            $('#foto_' + id).attr('style', 'display:block');
        }
    });

    // Set default selected kleur in dropdown by first image
    $('#question-OrderRegelProductKleurId').ready(function() {
        $("#question-OrderRegelProductKleurId option[value='" + $('#FirstImageColor').val() + "']").attr('selected', 'selected');
    });

    $(".single_image").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $('#keyword').focus(function() {
        if (this.value == this.defaultValue) {
            this.value = '';
            this.style.color = "#000000";
        }
        if (this.value != this.defaultValue) {
            this.select();
        }
    });

    $("#keyword").autocomplete({
        source: "/json/GetArtikelen/",
        minLength: 2,
        focus: function(event, ui) {
            $("#keyword").val(ui.item.Naam);
            return false;
        },
        select: function(event, ui) {
            window.location = ui.item.Url;
        }
    }).data("autocomplete")._renderItem = function(ul, item) {
        if (item.Naam == 'readmore') {
            return $("<li></li>")
				.data("item.autocomplete", item)
                .append("<a><div style='text-align:center;color: #666666;margin: 20px;text-align: center;text-decoration: underline;'><strong>Toon alle resultaten</strong></div></a>")
                .appendTo(ul);
        } else {
            return $("<li></li>")
				.data("item.autocomplete", item)
                .append("<a><div class='image-small' style='background: #FFF url(" + item.Image + ") no-repeat 50% 50%;'><img height='30' width='30' alt='' src='/images/overlay.gif' /></div><h2>" + item.Naam + "</h2><h4>" + item.Code + "</h4><h4>" + item.Price + " excl. btw</h4></a>")
                .appendTo(ul);
        }
    };

    $("a#lnkVoorwaarden").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $('#question-OrderRegelProductMaatId').ready(function() {
        if ($.trim($('#question-OrderRegelProductMaatId :selected').text()).length == 0) {
            $('#question-OrderRegelProductMaatId').attr('style', 'display:none');
        }
    });

    $("a#toon-alleshops").click(function() {
        $('#full-list').slideToggle('fast', function() {
            // Animation complete.
        });

        if ($(this).hasClass('clicked')) {
            $(this).removeClass("clicked");
        } else {
            $(this).addClass("clicked");
        }

    });

    $(".product-rollover-effect").hover(
	  function() {
	      $(this).addClass("product-hover");
	  },
	  function() {
	      $(this).removeClass("product-hover");
	  }
	);

    $(".slideshow").cycle({
        fx: 'scrollRight',
        timeoutFn: calculateTimeout
    });

    /* Disable submit button after submit order*/
    $('form#bestelling_controleren button.submit').removeAttr('disabled');
    $('form#bestelling_controleren').submit(function() {
        $('form#bestelling_controleren button.submit').attr("disabled", true);
    });

    if (showFeedbackRequest == "True") {
        $('#feedback-question-box').slideDown(1000);
    }

    $("a.fancybox-toggle").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 550,
        'frameHeight': 500,
        'padding': 5
    });


    $("button#hide-feedback-question-box").click(function() {
        $('#feedback-question-box').slideUp();
    });


});

function confirmdelete(vraag, link) {
    var retVal = confirm(vraag);
    if (retVal == true) {
        window.location = link
        return true;
    } else {
        return false;
    }
}

function calculateTimeout(currElement, nextElement, opts, isForward) {
    var myTimeOut = 20000;
    var index = opts.currSlide;

    return myTimeOut;
} 
