jQuery(document).ready(function() {
	/* Fix for IE */
    	if (jQuery.browser.msie && jQuery.browser.version >= 9) {
		 jQuery.support.noCloneEvent = true;
		}
	/* End fix for IE */

	/* Load scripts */
        if(jQuery('.lightbox').length) {
                        jQuery(".lightbox").fancybox({
                                        'opacity'		: true,
                                        'overlayShow'	: true,
                                        'transitionIn'	: 'elastic',
                                        'transitionOut'	: 'elastic'
                                });
                }


        if (jQuery('ul#myRoundabout').length) {
                        jQuery('ul#myRoundabout').roundabout({
                                        btnNext: '#next',
                                btnPrev: '#previous'
                                });
                }



        if (jQuery('#carousel').length) {
            
            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            var autoscrolling = true;

            jQuery('#carousel').infiniteCarousel().mouseover(function () {
                autoscrolling = false;
            }).mouseout(function () {
                autoscrolling = true;
            });

            setInterval(function () {
                if (autoscrolling) {
                    jQuery('#carousel').trigger('next');
                }
            }, 4000);

        }

	/* End load scripts*/

        /* setup RHS product filters as dropdowns */
        jQuery('.filters-menu select').change(function() {
            window.location = jQuery(this).val();
        });
	/* End setup RHS product filters as dropdowns */

        /* focus for enews input */
        jQuery('#enews-subscribe').focus(function() {
            jQuery('#enews-subscribe').val('');
        });

        /* Product view tabs */

	//When page loads...
	jQuery(".tab_content-2").hide(); //Hide all content
	jQuery("ul.tabs-2 li:first").addClass("active").show(); //Activate first tab
	jQuery(".tab_content-2:first").show(); //Show first tab content

	//On Click Event
	jQuery("ul.tabs-2 li").click(function() {

		jQuery("ul.tabs-2 li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content-2").hide(); //Hide all tab content

		var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		jQuery(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

	/* End product view tabs */

	/* Hover */
	jQuery('.top-cart').hover(function(){
			jQuery(this).find('.block-title a').addClass('active');
			jQuery('#topCartContent').stop().fadeTo(500, 1).addClass('active');
		}, function(){
				jQuery(this).find('.block-title a').removeClass('active');
				jQuery('#topCartContent').fadeTo(400, 0).removeClass('active');
	});
	/* Hover */


	/*  */
	jQuery('.cart .totals table td:first-child').addClass('totals-title')
	jQuery ('.block-height').equalHeightColumns();
	/*  */
});
/* RHS filter by menus as dropdowns */
/**
* Set "odd", "even" and "last" CSS classes for list items
* @see decorateGeneric()
*/
function decorateOl(list) {
    list = $(list);
    if (list) {
        decorateGeneric(list.select('ol'), ['odd', 'even', 'last']);
    }
}
/* End RHS filter by menus as dropdowns  */

/**
 * Add classes to specified elements.
 * Supported classes are: 'odd', 'even', 'first', 'last'
 *
 * @param elements - array of elements to be decorated
 * [@param decorateParams] - array of classes to be set. If omitted, all available will be used
 */
function decorateGenericAppendClearfix(elements, decorateParams)
{
    var allSupportedParams = ['odd', 'even', 'first', 'last'];
    var _decorateParams = {};
    var total = elements.length;

    if (total) {
        // determine params called
        if (typeof(decorateParams) == 'undefined') {
            decorateParams = allSupportedParams;
        }
        if (!decorateParams.length) {
            return;
        }
        for (var k in allSupportedParams) {
            _decorateParams[allSupportedParams[k]] = false;
        }
        for (var k in decorateParams) {
            _decorateParams[decorateParams[k]] = true;
        }

        // decorate elements
        // elements[0].addClassName('first'); // will cause bug in IE (#5587)
        if (_decorateParams.first) {
            Element.addClassName(elements[0], 'first clearfix');
        }
        if (_decorateParams.last) {
            Element.addClassName(elements[total-1], 'last clearfix');
        }
        for (var i = 0; i < total; i++) {
            if ((i + 1) % 2 == 0) {
                if (_decorateParams.even) {
                    Element.addClassName(elements[i], 'even clearfix');
                }
            }
            else {
                if (_decorateParams.odd) {
                    Element.addClassName(elements[i], 'odd clearfix');
                }
            }
        }
    }
}
