var J = jQuery.noConflict();

J(document).ready(function ($) {
    if (window.location.href.indexOf("storelocator.aspx") > -1) {
        $('select').selectbox();
    }
    Cufon.set('fontFamily', 'royal').replace('.details H2')('.details .back', { hover: true })('.wrap H1')('#content .story-content H2')('.post h2')('A.navt', { hover: true })('#content .story-content H3')('.sidebar h3')('#content .story-content .history UL LI SPAN.year')('.world-of-heading');
    $('.rotator UL LI IMG').animate({ opacity: 1.0 }, { complete: function () { $(this).removeAttr('style'); } });
    $('#rotator').cycle({
        fx: 'zoom',
        easing: 'bouncein',
        delay: -4000
    });
    $('.rotator-bollman UL LI IMG').animate({ opacity: 1.0 }, { complete: function () { $(this).removeAttr('style'); } });
    $('#rotator-bollman').cycle({
        fx: 'zoom',
        easing: 'bouncein',
        delay: -4000
    });
    if ($('#content .story-content .main-pic-cont ul').length > 0) {
        $('#content .story-content .main-pic-cont ul').cycle({
            fx: 'fade'
        });
    }

    $('INPUT.auto-hint').each(function (i, el) {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
        $(el).focus(function () {
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }
        });
        $(el).blur(function () {
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
    });

    if ($('body').hasClass('home')) {
        //        var imagePath;
        //        var bgNum = Math.round(Math.random() * 3)

        //        bgSel = new Array(4);
        //        bgSel[0] = "/layout/images/bg/bg_1.png";
        //        bgSel[1] = "/layout/images/bg/bg_2.png";
        //        bgSel[2] = "/layout/images/bg/bg_3.png";
        //        bgSel[3] = "/layout/images/bg/bg_4.jpg";

        //        imagePath = bgSel[bgNum];

        //        $(document).bgStretcher({
        //            images: [imagePath],
        //            imageWidth: 2700, imageHeight: 1280, slideShowSpeed: 0
        //        });


        $(document).bgStretcher({
        images: ['/HTMLEditorImages/whitebg.jpg', '/HTMLEditorImages/whitebg.jpg', '/HTMLEditorImages/whitebg.jpg', '/HTMLEditorImages/whitebg.jpg'],
            imageWidth: 1668, imageHeight: 1035, nextSlideDelay: 3000, slideShowSpeed: 4000
        });
    } else if ($('body').hasClass('story')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/bg-story.jpg'],
            imageWidth: 1475, imageHeight: 1180, slideShow: false
        });
    } else if ($('body').hasClass('blog')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/bg-blog.jpg'],
            imageWidth: 1475, imageHeight: 1066, slideShow: false
        });
    } else if ($('body').hasClass('stores')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/bg-stores.jpg'],
            imageWidth: 1475, imageHeight: 1069, slideShow: false
        });
    } else if ($('body').hasClass('world-of')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/world-of.jpg'],
            imageWidth: 1475, imageHeight: 1188, slideShow: false
        });
    } else if ($('body').hasClass('contact')) {
        $(document).bgStretcher({
            images: ['/images/contactBG.jpg'],
            imageWidth: 1475, imageHeight: 972, slideShow: false
        });
    } else if ($('body').hasClass('videos')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/myaccount-bg.png'],
            imageWidth: 818, imageHeight: 471, slideShow: false
        });
    } else if ($('body').hasClass('feedback')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/feedback-bg.png'],
            imageWidth: 1206, imageHeight: 595, slideShow: false
        });
    } else if ($('body').hasClass('login')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/myaccount-bg.png'],
            imageWidth: 818, imageHeight: 471, slideShow: false
        });
    } else if ($('body').hasClass('starbucks')) {
        $(document).bgStretcher({
            images: ['/layout/images/bg/starbucks.jpg'],
            imageWidth: 1244, imageHeight: 995, slideShow: false
        });
    } else if ($('body').hasClass('projects')) {
        var imagePath;
        if (window.location.pathname == "/mark_borthwick.html")
            imagePath = "/layout/images/bg/mark_borthwick.jpg";
        else if (window.location.pathname == "/martin_greenfield.html")
            imagePath = "/layout/images/bg/martin_greenfield.jpg";
        else if (window.location.pathname == "/bollman_hat.html")
            imagePath = "/layout/images/bg/bollman.jpg";
        else if (window.location.pathname == "/denim.html")
            imagePath = "/layout/images/bg/bg-inside.jpg";

        $(document).bgStretcher({
            images: [imagePath],
            imageWidth: 1474, imageHeight: 1116, slideShow: false
        });
    } else {
        $(document).bgStretcher({
            imageWidth: 1474, imageHeight: 1116, slideShow: false
        });
    }

    /* Scroll */
    if ($('.history').length > 0) {
        var w_scroll = 0;
        $('.history UL LI').each(function () {
            if ($(this).parent().parent().hasClass('history')) {
                if ($(this).hasClass('first')) w_scroll += 30; else w_scroll -= 60;
                w_scroll += parseInt($(this).width());
            }
        });
        if (w_scroll != 0) $('.history UL.history-scroll').css('width', w_scroll + 'px');

    }

    var width = 0;
    var w = 0;
    $('.scrollableArea .item').each(function (i) {
        w = $(this).width();
        width = width + w;
    });
    $('.scrollableArea').css('width', width);
    if ($('#flexcroll').length > 0) {
        $('div#flexcroll').smoothDivScroll({ visibleHotSpots: "always", startAtElementId: "startId" });
    }

    $('A.tab-link').click(function () {
        if ($($(this).attr('href')).hasClass('active')) return false;
        $('#content .tabs .active').removeClass('active');
        $($(this).attr('href')).addClass('active');
        return false;
    });

    $('.thumbnails UL LI A').click(function () {
        $('#main-img').attr('src', $(this).attr('href'));

        return false;
    });

    $('INPUT.auto-hint').each(function (i, el) {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
        $(el).focus(function () {
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }
        });
        $(el).blur(function () {
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
    });

    $(".filter-box A.filter-by").click(function () {
        if ($(this).hasClass('close')) {
            $(".color-list").slideDown('normal');
            $(this).removeClass('close').addClass('open');
        } else {
            $(".color-list").slideUp('normal');
            $(this).removeClass('open').addClass('close');
        }
        return false;
    });
    $(".filter-box2 A.filter-by").click(function () {
        if ($(this).hasClass('close')) {
            $(".color-list2").slideDown('normal');
            $(this).removeClass('close').addClass('open');
        } else {
            $(".color-list2").slideUp('normal');
            $(this).removeClass('open').addClass('close');
        }
        return false;
    });

    $(document).ready(function () {
        if (window.location.href.indexOf("storelocator.aspx") > -1 || window.location.href.indexOf("contact.html") > -1 || $('body').hasClass('home') || $('body').hasClass('videos') || window.location.href.toLowerCase().indexOf("collection_vip.aspx") > -1 || window.location.href.toLowerCase().indexOf("collectionlist.aspx") > -1 || window.location.href.toLowerCase().indexOf("martin_greenfield.html") > -1) {
            $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square', animationSpeed: 'fast' });
        } else if (window.location.href.indexOf("denim.html") > -1) {
            $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square', animationSpeed: 'fast', default_width: 660 });
        }
    });

});
