jQuery.noConflict();

function beginScroll(iteration) {
    twitterScroll = setInterval(function() {
        if (iteration > 9) {
            iteration = 1;
        }
        else {
            iteration++;
        }
        jQuery('li.atTop').removeClass('atTop');
        jQuery('#twitterBox #twitterContent').scrollTo('#twitterItem'+iteration, 1000);
        jQuery('#twitterItem'+iteration).addClass('atTop');
    }, 5000);
}
jQuery(document).ready(function() {
    if (jQuery('#twitterBox').length) {
        var iteration = 1;
        beginScroll(iteration);
        jQuery('#twitterBox').hover(function() {
            clearInterval(twitterScroll);
        },
        function() {
            iteration = parseInt(jQuery('li.atTop a.anchor').attr('rel'));
            beginScroll(iteration);
        });
    }
    jQuery('#categoryNavigation li.level1.active').children('a').children('span').addClass('purple');
    jQuery('#categoryNavigation li.level1').children('a').attr('href','#').click(function () {
        if (jQuery(this).parent().hasClass('active')) {
            jQuery(this).removeAttr('style');
            jQuery(this).parent().children('ul').slideUp(function () {
                jQuery(this).parent().removeClass('active');
            });
        }
        else {
            jQuery('#categoryNavigation ul.level0 li.active').children('a').removeAttr('style');
            jQuery('#categoryNavigation ul.level0 li.active').children('ul').slideUp(function () {
                jQuery(this).parent().removeClass('active');
            });
            jQuery(this).css('font-weight','bold');
            jQuery(this).parent().children('ul').slideDown(function () {
                jQuery(this).parent().addClass('active');
            });
        }
        return false;
    });
    if (jQuery('.trade').length) {
        jQuery('#store_section option[value=10]').attr('selected','selected');
    }
    else {
        jQuery('#store_section option[value=9]').attr('selected','selected');
    }
    jQuery('.viewWines button').click(function() {
        if (jQuery('.category-products').is(':visible')) {
            var URL = document.location.href.split("?")[0];
            document.location.replace(URL);
        }
        else {
            var URL = document.location.href.split("?")[0] + "?wines";
            document.location.replace(URL);
        }
        return false;
    });
    if (document.location.search) {
        jQuery('.category-image,.category-description').hide();
        jQuery('.category-products').show();
        jQuery('.viewWines button span').html('Winery details');
    }
    jQuery('.sort-by option[value*=order=position]').remove();
    jQuery('#brochure').change(function() {
        if (jQuery(this).is(':checked')) {
            jQuery('li#addressItem').show();
        }
        else {
            jQuery('li#addressItem').hide();
            jQuery('li#addressItem textarea').val('');
        }
    });
    jQuery('ul.products-grid li.item').hover(function() {
        jQuery(this).css('z-index','1');
        jQuery(this).append('<div class="tempPopup">We\'re busy writing tasting notes for this wine, please <a href="/contacts/">call us</a> to find out more.</div>');
    }, function() {
        jQuery(this).removeAttr('style');
        jQuery(this).children('.tempPopup').remove();
    });
    jQuery('li.item a.product-image,li.item h2.product-name a').click(function() {
        return false;
    });
});
