jQuery.noConflict();

/*overstate*/
jQuery(document).ready(function() {
    jQuery(".menuoverstate").each(function(i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");

        jQuery(this).hover(
            function() {
                if (this.src.indexOf("_o.jpg") == -1) {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }

            },

            function() {
                this.src = this.src.replace("_o.jpg", ".jpg");

            });

    });

    loadMenus();

});

var TRANSITION_SPEED = 150;

function setOverstateOff(element) {
    jQuery(element).find("img").each(function() {
        var src = jQuery(this).attr("src");
        src = src.replace('_o.jpg', '.jpg');

        jQuery(this).attr("src", src);
    });
}

function setOverstateOn(element) {
    jQuery(element).find("img").each(function() {
        var src = jQuery(this).attr("src");
        if (src.indexOf('_s.jpg') == -1)
        if (src.indexOf('_o.jpg') == -1) {
            src = src.replace('.jpg', '_o.jpg');
            jQuery(this).attr("src", src);
        }
    
    });
}

function checkChildren(menu, menuChildren) {

    jQuery(menu).find(".subnav").each(function(subindex) {

        if (menuChildren[(subindex * 2) + 2] == false &&
            menuChildren[(subindex * 2) + 3] == false) {

            jQuery(this).slideUp(TRANSITION_SPEED);
            jQuery(this).prev().removeClass("current");
        }
    });

    var hideAll = true;
    for (var c in menuChildren) {
        if (menuChildren[c] == true)
            hideAll = false;
    }

    if (hideAll) {
        setOverstateOff(jQuery(menu).prev());
        jQuery(menu).slideUp(TRANSITION_SPEED);
    }
}

function loadMenus() {

    jQuery(".nav").children().each(function(i) {

        var menuChildren = [];

        var index = i;

        var children = jQuery(this).children();
        var childindex = 0;

        // the first child is the link itself
        menuChildren[childindex] = true;
        childindex++;

        // the second child is the dropdown list
        menuChildren[childindex] = false;
        childindex++;

        var menu = children[1];

        jQuery(children[1]).hover(function() {
            menuChildren[1] = true;
        },
        function() {
            menuChildren[1] = false;
            setTimeout(function() {
                checkChildren(menu, menuChildren);
            }, TRANSITION_SPEED);
        });

        jQuery(children[1]).children().each(function(i) {

            if (jQuery(this).children().length > 1) {
                var subindex = i;

                var children = jQuery(this).children();

                menuChildren[(subindex * 2) + 3] = false;
                menuChildren[(subindex * 2) + 2] = false;

                jQuery(children[1]).hover(function() {
                    menuChildren[(subindex * 2) + 3] = true;
                },
            function() {

                menuChildren[(subindex * 2) + 3] = false;

                setTimeout(function() {
                    checkChildren(menu, menuChildren);
                }, TRANSITION_SPEED);
            });

                jQuery(children[0]).hover(function() {

                    if (!jQuery(this).hasClass("current")) {
                        menuChildren[(subindex * 2) + 2] = true;
                        jQuery(this).addClass("current");
                        jQuery(this).next(".subnav").slideDown(TRANSITION_SPEED);
                    }
                },
                function() {
                    // moved off a subnav link item

                    menuChildren[(subindex * 2) + 2] = false;

                    setTimeout(function() {
                        checkChildren(menu, menuChildren);
                    }, TRANSITION_SPEED);
                });
            }
        });

        // do hovers for the main item link itself

        jQuery(children[0]).hover(function() {
            menuChildren[0] = true;
            setOverstateOn(jQuery(this));
            jQuery(this).next(".subnav").slideDown(TRANSITION_SPEED);

        },
        function() {
            // moved off the root link item

            menuChildren[0] = false;
            setTimeout(function() {
                checkChildren(menu, menuChildren);
            }, TRANSITION_SPEED);
        });
    });
}

/*---------------------slideshow---------------------------*/

function slideSwitch() {
    var jQueryactive = jQuery('#slideshow IMG.active');

    if (jQueryactive.length == 0) jQueryactive = jQuery('#slideshow IMG:last');

    var jQuerynext = jQueryactive.next().length ? jQueryactive.next()
        : jQuery('#slideshow IMG:first');

    jQueryactive.addClass('last-active');

    jQuerynext.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
    jQueryactive.removeClass('active last-active');
        });
}

jQuery(function() {
    setInterval("slideSwitch()", 7000);
});

function slideSwitchLeft() {
    var jQueryactive = jQuery('#slideshow-left IMG.active');

    if (jQueryactive.length == 0) jQueryactive = jQuery('#slideshow-left IMG:last');

    var jQuerynext = jQueryactive.next().length ? jQueryactive.next()
        : jQuery('#slideshow-left IMG:first');

    jQueryactive.addClass('last-active');

    jQuerynext.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
    jQueryactive.removeClass('active last-active');
        });
}

jQuery(function() {
    setInterval("slideSwitchLeft()", 10000);
});

jQuery(document).ready(function ()
{
jQuery(".products-wrapper").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 3
    });
});

    
    

