Cufon.replace('h1.custom', { fontFamily: 'Myriad Pro' });
Cufon.replace('h2.custom', { fontFamily: 'Myriad Pro' });
Cufon.replace('h3.custom', { fontFamily: 'Myriad Pro' });
Cufon.replace('h4.custom', { fontFamily: 'Myriad Pro' });
Cufon.replace('label.custom', { fontFamily: 'Myriad Pro' });

$(document).ready(function () {

    $('.paymentmethod').click(function () {
        HandleRembours();
    });
    HandleRembours();

    $("a#toon-allemerken").click(function () {

        linkId = this.id;
        liClass = linkId.replace("toon-", "")

        $("li." + liClass).slideToggle('slow', function () {
            // Animation complete.
        });

    });

    $("a.remove").click(function () {
        id = this.id.replace('remove_', '');
        $("input#" + id).attr("value", 0);
        $("#cartform").submit();
    });


    $('#reactieformulier-tonen').click(function () {
        $('#reactieformulier').slideToggle('slow', function () {
            // Animation complete.
        });
    });


    $("#tabs").tabs();

    $("#tabs").children("div").each(
        function () {
            if ($(this).find(".field-validation-error").length > 0) {
                // There is a tab that has a validation error message
                var id = $(this).attr("id");
                // Make sure it is shown!
                $("#tabs").tabs('select', '#' + id);
            }
        }
    );

    $(".item-rollover").hover(
		function () {
		    $(this).addClass("item-hover");
		},
		function () {
		    $(this).removeClass("item-hover");
		}
	);

    $("a.zoom-image").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $("a.iframe").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $(".thumb-rollover").hover(
		function () {
		    myHref = this.href;
		    newImageSrc = myHref.replace("1000", "275");
		    newDivBackground = "url('" + newImageSrc + "') no-repeat scroll 50% 50% transparent";
		    objDiv = document.getElementById("main-image");
		    objDiv.style.background = newDivBackground;
		},
		function () {
		    objLink = document.getElementById("main-image-link");
		    newImageSrc = objLink.href.replace("1000", "275");
		    newDivBackground = "url('" + newImageSrc + "') no-repeat scroll 50% 50% transparent";
		    objDiv = document.getElementById("main-image");
		    objDiv.style.background = newDivBackground;
		}
	);



    $("select#SizeId").change(function () {
        mySelectedValue = this.options[this.selectedIndex].value;
        $(".price-hidden").hide();
        $("#price-" + mySelectedValue).fadeIn();
    });


    $("div.show-bigger-image-on-hover").tooltip({
        track: true,
        delay: 400,
        opacity: 0,
        top: 10,
        left: 10,
        showURL: false,
        bodyHandler: function () {
            var divId = this.id;
            var imageSrc = "/medialibrary/image/" + divId + "/0/250/previewImage.jpg";
            return $("<img/>").attr("src", imageSrc);
        }
    });

    $("a#show-sortlist").click(function () {
        $('#sortlist').slideToggle('fast', function () {
            // Animation complete.
        });
    });

    $("a#verzendkosten").hover(
		function () {
		    $("#verzendkosten-popup").fadeIn();
		},
		function () {
		    $("#verzendkosten-popup").fadeOut();
		}
	);

    $("#Cart_HasDistinctBillToAddress").change(
        function () {
            $("#BillToAddressSection").toggle("slow");
        }
    );


    $(".onmouseover-change-source").hover(
		function () {
		    currentSrc = this.src;
		    newSrc = currentSrc.substring(0, currentSrc.lastIndexOf(".")) + "_hover" + currentSrc.substring(currentSrc.lastIndexOf("."));
		    this.src = newSrc;
		},
		function () {
		    currentSrc = this.src;
		    newSrc = currentSrc.replace("_hover", "");
		    this.src = newSrc;
		}
	);

    $('.jQueryUIDatepicker').datepicker();


});

function HandleRembours() {
    if ($("input[name='paymentmethod']:checked").val() == 4) {
        $('.rembours').show('slow');
        $('.verzendkosten').hide();

        $('.totaalbedragRembours').show('slow');
        $('.totaalbedrag').hide();
    } else {
        $('.rembours').hide();
        $('.verzendkosten').show('slow');

        $('.totaalbedragRembours').hide();
        $('.totaalbedrag').show('slow');
    }
}

function doImageHover(objImage, newState) {

    var currentSrc = objImage.src;
    var positionOfDot = currentSrc.lastIndexOf(".");
    var firstPart = currentSrc.substring(0, positionOfDot);
    var extension = currentSrc.substring(positionOfDot + 1);

    var newSrc = "";

    if (newState == "on") {
        newSrc = firstPart + "_hover" + "." + extension;
    } else {
        newSrc = currentSrc.replace("_hover", "");
    }

    objImage.src = newSrc;

}
