jQuery(document).ready(function($ecco) {

    // Fancybox (normal content)
    if ($ecco("a.fancybox").length > 0) {
        $ecco("a.fancybox").fancybox({
            'padding': 30,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'hideOnContentClick': false
        });
    }
    // Fancybox (iframe content)
    if ($ecco("a.fancybox.iframe").length > 0) {
        $ecco("a.fancybox.iframe").fancybox({
            'padding': 5,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 600,
            'height': 600,
            'hideOnContentClick': false
        });
    }
    // Fancybox (iframe content product picture)
    if ($ecco("a.fancybox.iframe.picture").length > 0) {
        $ecco("a.fancybox.iframe.picture").fancybox({
            'padding': 5,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 600,
            'height': 600,
            'hideOnContentClick': true
        });
    }
    // Fancybox (iframe content modal window)
    if ($ecco("a.fancybox.iframe.modal").length > 0) {
        $ecco("a.fancybox.iframe.modal").fancybox({
            'padding': 5,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 797,
            'height': 600,
            'autoScale': false
        });
    }
    // Fancybox (iframe rotate)
    if ($ecco("a.fancybox.iframe.rotate").length > 0) {
        $ecco("a.fancybox.iframe.rotate").fancybox({
            'padding': 10,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 1000,
            'height': 760,
            'scrolling': 'no',
            'onComplete': function() {
                
            }
        });
    }
    // Fancybox (iframe video)
    if ($ecco("a.fancybox.iframe.video").length > 0) {
        $ecco("a.fancybox.iframe.video").fancybox({
            'padding': 10,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 640,
            'height': 430,
            'hideOnContentClick': false
        });
    }
    // Fancybox (forgotpassword)
    if ($ecco("a.fancybox.iframe.forgotpassword").length > 0) {
        $ecco("a.fancybox.iframe.forgotpassword").fancybox({
            'padding': 10,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'overlayShow': true,
            'overlayOpacity': .8,
            'width': 405,
            'height': 200,
            'hideOnContentClick': false
        });
    }
    //Frontpage slideshow
    if ($ecco(".slideshow").length > 0) {
        $ecco(".slideshow").show();
        $ecco(".slideshow > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 6000, false);
    }

    // Splashes fadeid
    //$ecco('.campaignSplashesRegular').find('.box, .whitebox').find('img').hide();

    // JOB VACANCY ROLLOVER
    $ecco(".jobList .row").mouseover(function() {
        $ecco(this).css('background-color', '#FAFAFA');
    }).mouseout(function() {
        $ecco(this).css('background-color', '#ffffff');
    });

    //Navigation sliders
    $ecco(function() {
        $ecco('.slides').slides({
            preload: false,
            preloadImage: '/Gfx/Slides/loading.gif',
            hoverPause: true
        });
    });

    //TIPTIP
    $ecco(function() {
        $ecco(".icon").tipTip({ defaultPosition: "top" });
        $ecco(".techInfo").tipTip();
        $ecco(".heelHeight").tipTip();
        $ecco(".beltWidth").tipTip();
    });

    //TOOLBAR (SIGN IN BAR)
    $ecco(".toolbarContent").css({ width: $ecco(".tbList").width() });
    $ecco(".tbList li span").click(function() {
        if ($(this).is('.tbShopOnline') || $(this).is('.tbLocation') || $(this).is('.nolayer'))
            return;

        $(this).parent().addClass("selected");
        $(this).parent().siblings().removeClass("selected");
        $(this).parent().find(".toolbarContent").css('display', 'block');
        $(this).parent().siblings().find(".toolbarContent").css('display', 'none');
        $(this).parent().find(".toolbarContent").css('display', 'block');
        //        $(this).parent().parent().find(".tbLast").css('height','32px');
        //        $(this).parent().parent().find(".tbLast").css('overflow','hidden');

    });
    $ecco(".toolbarContent .closeBtn").click(function() {
        $(".tbList li").siblings().removeClass("selected");
        $(".tbList li").siblings().find(".toolbarContent").css('display', 'none');
        //        $(".tbList li").parent().find(".tbLast").css('height','auto'); 
        //        $(".tbList li").parent().find(".tbLast").css('overflow','auto');
    });

    //	$ecco(".toolbarcontent").each( function () {
    //		if ($(this).css('display') != 'none') {
    //			$(".tblist li").parent().find(".tblast").css('height','32px'); 
    //            $(".tblist li").parent().find(".tblast").css('overflow','hidden');
    //		}
    //	});

    $ecco(".footerSignIn").click(function() {
        $('html, body').animate({ scrollTop: 0 }, 'fast');
        $ecco(".tbList li").removeClass("selected");
        $ecco(".tbList li").find(".toolbarContent").css('display', 'none');
        $ecco(".tbList li .tbSignIn").parent().addClass("selected");
        $ecco(".tbList li .tbSignIn").parent().find(".toolbarContent").css('display', 'block');
    });

    //FOOTER
    $ecco("li.jqfooter").hover(handlerIn, handlerOut);
    function handlerIn() {
        $ecco("li.selected .content").css('display', 'none');
        $ecco(this).find('.content').css('display', 'block');

    }
    function handlerOut() {
        $ecco(this).find('.content').css('display', 'none');
        $ecco("li.selected .content").css('display', 'block');
    }

    $ecco(".icon").mouseover(function() {
        $ecco(this).css('background-position', '0px -44px');
    }).mouseout(function() {
        $ecco(this).css('background-position', '0px 0px');
    });

    //FAQ
    $ecco(".faq .item").click(function() {
        if ($(this).find('.head').css('display') == 'block') {
            $(".faq").find('.head').css('display', 'block');
            $(".faq").find('.text').css('display', 'none');
            $(this).find('.head').css('display', 'none');
            $(this).find('.text').css('display', 'block');
        } else {
            $(".faq").find('.head').css('display', 'block');
            $(".faq").find('.text').css('display', 'none');
        }

    });

    //MY ORDERS
    $ecco(".ohOpenBtn").click(function() {
        $(this).parent().parent().parent('.ohRow').find('.ohRowContent').css('display', 'block');
        $(this).parent().parent().parent('.ohRow').find('.ohCloseBtn').css('display', 'inline-block');
        $(this).css('display', 'none');
    });
    $ecco(".ohCloseBtn").click(function() {
        $(this).parent().parent().parent('.ohRow').find('.ohRowContent').css('display', 'none');
        $(this).parent().parent().parent('.ohRow').find('.ohOpenBtn').css('display', 'inline-block');
        $(this).css('display', 'none');
    });

    //JOBDESCRIPTION
    $ecco(".applybtn").click(function() {
        $ecco(this).css('display', 'none');
        $ecco(".apply").css('display', 'block');
    });

    //GALLERY
    $ecco(".ecco_gallery .smallImages li").click(function() {
        $ecco('.ecco_gallery .smallImages li .img img').css({ opacity: 1 });
        $ecco(this).find('.img img').css({ opacity: 0.5 });
        $ecco(".ecco_gallery li").removeClass('selected');

        var tempNum = $ecco(this).attr('class').charAt(3);

        $ecco(".ecco_gallery li").each(function() {
            if ($ecco(this).attr('class').charAt(3) == tempNum) {
                $ecco(this).addClass('selected');
            }
        });
    });

    //make sure that the first image has opacity set on page load
    $ecco(".ecco_gallery .smallImages ul li.selected .img img").css({ opacity: 0.5 });


    $ecco('.productAvailabilityCountry select').each(function() {
        if (this.options.length > 0) {
            var option = this.options[this.selectedIndex];
            var val = $(this).val();
            var text = $(option).text();
            if (val == undefined || val == '')
                val = text;

            $ecco(this).parent().find('.optiontext').text(text);

            $ecco(this).bind('change', function() {
                var option = this.options[this.selectedIndex];
                var val = $ecco(this).val();
                var text = $ecco(option).text();
                if (val == undefined || val == '')
                    val = text;

                var listToShow = ".sizes_" + val;
                $ecco(".sizeList").hide();
                $ecco(listToShow).show();

                $(this).parent().find('.optiontext').text(text);
            });
        }
    });


});

function fadeCampaignSplash() {
    jQuery('.campaignSplashesRegular').find('.box, .whitebox').find('img').hide().fadeIn(1000);
}
