YUI().use('node','event','attribute', 'cookie', 'event-delegate', function(Y) {
	
	function init(){
		if(Y.one('#modal.products')){
			Y.delegate("click", toggleProductDetailModal, "#product-thumbs", "li");
			Y.on("click", closeProductDetailModal, ".closeButton");
		}
		Y.on("mouseover", openBrandPopUp, ".link-brands");
		Y.on("mouseout", closeBrandPopUp, ".link-brands");
	}
	
	function toggleProductDetailModal(e) {
		Y.one('#overlay').setStyle('height', document.body.scrollHeight);
		//Y.log(document.body.scrollHeight);
	
		var selectedProduct = e.currentTarget.one('a').getAttribute("productname");        
        Y.one('#overlay').removeClass('hide');
        Y.one('#modal.products .'+selectedProduct).removeClass('hide');
        e.preventDefault();
    }
    
    function closeProductDetailModal(e){
    	Y.one('#overlay').addClass('hide');
    	Y.all('#modal.products .productdetail').addClass('hide');
    	e.preventDefault();
    }
    
    function openBrandPopUp(e) {
    	Y.one('.sub-nav.brands').removeClass('hide');
    }
    
    function closeBrandPopUp(e) {
    	Y.one('.sub-nav.brands').addClass('hide');
    }
	
	//fires when page is done loading
    Y.on('domready', init);
});




function slideSwitch() {
    var $active = $('#slideshow li.active');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});



