﻿function noError() {
    return true;
}
window.onerror = noError;


$(document).mouseup(function(e) {
	if($(e.target)("button_language").length==0) {
		$("div.language_menu").hide();
		$(".button_language").removeClass("menu-open");
	}
});

$(document).ready(function () {

    /*IMAGE SWAP*/
    var firstPath = $(".carousel_products p img.first").attr("src");
    var firstAlt = $(".carousel_products p img.first").attr("alt");
    var activeLi = $(".thumbs li.active");

    //    $(".thumbs li img").hover(function () {
    //        $(".thumbs li.active").removeClass("active");
    //        var largePath = $(this).attr("src");
    //        var largeAlt = $(this).attr("alt");
    //        $(".largeImg").attr({ src: largePath, alt: largeAlt });
    //    });

    $(".thumbs li img").click(function () {
        activeLi.removeClass('active');
        activeLi = $(this).parent();
        activeLi.addClass("active");
        firstPath = $(this).attr("src");
        firstAlt = $(this).attr("alt");
        $(".largeImg").attr({ src: firstPath, alt: firstAlt });
    });

    //    $(".thumbs li img").mouseout(function () {
    //        activeLi.addClass("active");
    //        $(".largeImg").attr({ src: firstPath, alt: firstAlt });
    //    });


    /*LANGUAGE CHOOSE PANEL*/
    $("body").click(function () {
        $(".language_menu").removeClass("Opened");
        $(".button_language").removeClass("menu-open");
    });

    $(".vraagt").click(function (e) {
        e.stopPropagation();
        e.preventDefault();
        $(".language_menu").toggleClass("Opened");
        $(".button_language").toggleClass("menu-open");
    });

    $(".language_menu").mouseup(function () {
        return false;
    });

    /*PRIVACY POPUP*/
    $("a.show-panel").click(function () {
        $(".lightbox, .lightbox-panel:eq(0)").fadeIn(200);
        return false;
    });
    $("a.close-panel").click(function () {
        $(".lightbox, .lightbox-panel").fadeOut(200);
        return false;
    });


    /*	$("a.show-panel2").click(function(){
    $(".lightbox2, .lightbox-panel2").fadeIn(200);
    return false;
    });
    $("a.close-panel2").click(function(){
    $(".lightbox2, .lightbox-panel2").fadeOut(200);  
    return false;
    });
    */

    /*LIGHT BOX GALLERIES INITIALIZATION*/
    var ppArray = new Array()
    $('a[rel^="prettyPhoto"]').each(function () {
        var det = 0;
        for (var i = 0; i < ppArray.length; i++) {
            if ($(this).attr('rel') == ppArray[i]) {
                det++;
            }
        }
        if (det == 0) {
            ppArray.push($(this).attr('rel'));
        }
    });

    var closeLabel = $('input[id*="hdfCloseButtonLabel"]').val();
    if (!closeLabel) {
        closeLabel = 'Close';
    }

    for (var i = 0; i < ppArray.length; i++) {
        $('a[rel="' + ppArray[i] + '"]').lightBox({
            containerBorderSize: 64,
            fixedNavigation: true,
            closeButtonText: closeLabel,
            overlayOpacity: 0.4
        });
    }

    $('#lightbox-secNav-btnClose').html(closeLabel);

    InitVideo(closeLabel);


    /*FORM DISAPPEARE TEXT*/
    $('input[type="text"], textarea').each(function () {
        if ($(this).attr('title') && fTrim($(this).val()).length === 0) {
            $(this).val($(this).attr('title'));
        }

        $(this).blur(function () {
            var sValue = fTrim(this.value);
            if (sValue.length === 0) {
                $(this).val($(this).attr('title'));
            }
        });

        $(this).focus(function () {
            var sValue = fTrim(this.value);
            if (sValue == $(this).attr('title')) {
                this.value = "";
            }
        });

    });



    /*UPLOAD BLOCK CUSTOMIZATION*/
    $(".UploadFileContainer .HiddenField input").change(function () {
        var fieldValue = $(this).val();
        var arr = fieldValue.split("\\");
        $(".UploadFileContainer input.Text").val(arr[arr.length - 1]);
    });


    /*SELECT BOX CUSTOMIZATION*/
    if ($('select').length) {
        //$('select').css('visibility', 'hidden');
        $('select').selectBox();
    }

    if ($(".scrollable").length) {
        $(".scrollable").scrollable();
    }

    //    if ($(".carousel_products").length) {
    //        $('.carousel_products').tinycarousel({
    //            pager: true,
    //            interval: true,
    //            intervaltime: 6000
    //        });
    //    }


    $(function () {
        $(".carousel_products .overview").cycle({
            fx: 'fade',
            speed: '2000',
            timeout: 2000,
            pager: '.carousel_products .pager ul',
            pagerAnchorBuilder: function (idx, slide) {
                // return selector string for existing anchor
                return '.carousel_products .pager ul li:eq(' + idx + ') a';
            }
        });
    });


    if ($('.CheckBoxClass').length) {
        $('.CheckBoxClass').each(function () {
            if ($(this).is(":checked")) {
                $(this).next("label").addClass("LabelSelected");
            }
            else {
                $(this).next("label").removeClass("LabelSelected");
            }
        });
        $('.CheckBoxClass').click(function () {
            console.log($(this));
            if ($(this).is(":checked")) {
                $(this).next("label").addClass("LabelSelected");
            }
            else {
                $(this).next("label").removeClass("LabelSelected");
            }
        });
    }
    /*ACCORDION INITIALIZATION*/
    registerAccordion(".accordion", "foldMenu", "openclose");
    registerAccordion(".accordion", "faq", "openclose02");

});



function registerAccordion(containerSelector, classPrefix, triggerClass) {
	var openClass = classPrefix + "Open";
	var closedClass = classPrefix + "Closed";
	$(containerSelector + " a." + triggerClass).click(function() {
		var current = $(this).parent();
		if (!current.hasClass(openClass) && !current.hasClass(closedClass)) {
			current = current.parent();
		}
		var current = $(this).parents("[class^=" + classPrefix + "]");
		if (current.hasClass(openClass)) {
			current.removeClass(openClass).addClass(closedClass);
		}
		else {
			current.parents(containerSelector).children("." + openClass).removeClass(openClass).addClass(closedClass);
			current.removeClass(closedClass).addClass(openClass);
		}
	});
}

function ChooseCountry(){
    $(".lightbox, .lightbox-panel3").fadeIn(200);
    $("a.close-panel3").click(function(){
		$(".lightbox, .lightbox-panel3").fadeOut(200);
		return false;
	});
}

function ShowVideo(element, url, width, height, leaveHeight, autoplay) {

    if (url.indexOf("youtube.com") != -1) {
        if (!width) {
            width = 578;
        }
        if (!height) {
            height = 370;
        }
        $(element).html("<iframe title='YouTube video player' width='" + width + "' height='" + height + "' src='" + url + "' frameborder='0'> </iframe>");
    } else {
        $(element).height(370);
        $f($(element).get(0), "/include/babyart/f/flowplayer.commercial-3.2.6.swf", {
            wmode: 'opaque',
            key: flowPlayerKey,
            clip: {
                url: url, //"http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-700.flv",
                autoPlay: autoplay,
                autoBuffering: true,
                onStart: function (clip) {
                    if (width) {
                        var wrap = jQuery(this.getParent());
                        var w = width; // $(element).parent().width();
                        if (!leaveHeight) {
                            var h = (clip.metaData.height * w / clip.metaData.width);
                            $(element).parent().height(h + 30);
                            wrap.css({ width: w, height: h });
                        }
                    }
                }
            },
            plugins: {
                controls: {
                    // location of the controlbar plugin
                    url: '/include/babyart/f/flowplayer.controls-3.2.4.swf'
                }
            }
        }).ipad();
    }
}



function fTrim(s) {
    return s.replace(/^\s*(.*?)\s*$/, "$1");
}

function ShowVideoPopup(url, title) {


    $(".pp-videotitle").html(title);
    $(".lightbox, .lightbox-panel").fadeIn(200);
    ShowVideo($("div.videoContainer").get(0), url, 578);

    return false;
}

function InitVideo(closeLabel) {
    // Player links
    $(".vidPlayer").each(function () {
        ShowVideo($(this).parent(), $(this).attr("href"), 456, 344, true, true);
    });

    // video links
    $(".vidLink").each(function () {
        var url = $(this).attr("href");
        $(this).attr("href", "#");
        $(this).click(function () {
            ShowVideoPopup(url, $(this).html());
        });
    });

    // video links with image inside
    $(".vidImageLink").each(function () {
        var url = $(this).attr("href");
        $(this).attr("href", "#");
        $(this).click(function () {
            ShowVideoPopup(url, "&nbsp;");
        });
    });

    //video popup close button
    $("a.close-panel").click(function () {
        $(".lightbox, .lightbox-panel").fadeOut(200);
        /*$f($("div.videoContainer")).stop();*/
        if ($("div.videoContainer").flowplayer(0)) {
            $("div.videoContainer").flowplayer(0).stop();
        }

        $("div.videoContainer").html("");
        return false;
    });
    $("a.close-panel").html(closeLabel);
}
