// Uses $j to prevent scriptaculus conflicts
var $j = jQuery.noConflict();
// On Document Ready
 $j(document).ready(function(){ 
	// Submenu
    $j('#submenu ul ul').hide();
	// Append ribbon
	$j('ul.level0').append('<strong class="ribbon"></strong>'); 
	// Show hide submenu items
	$j('.firstlevel a:not( li li a)').not('#brands a').click(function() {
		var checkElement = $j(this).next('ul');
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {				
        	$j('ul.level0').hide();
        	checkElement.show();			
      	} else {
	  		checkElement.hide();		 
	  	}  
		return false;
	});
    // Correct styles and allbrands links to return to normal behaviour
	$j('ul.firstlevel li.last a').css('border-bottom', '0');
	
	// Submenu tabs
	// Set blocks 	
 	var dataContainers = $j('#submenu .tabcontent');  	 
	// Takes block id from link hash   
    $j('#tabs-block a').click(function () {   		
    	dataContainers.hide().filter(this.hash).show();  
    	$j('#tabs-block a').removeClass('active');
    	$j(this).addClass('active');	
    	return false;	
	}).filter(':first').click();
	
	
	//Activities content slider
	$j('.postTitle.act h3 a').toggle(function() {
		$j(this).parent('h3').parent('div').next('.postContent.act').slideDown(200);
	}, function() {
		$j(this).parent('h3').parent('div').next('.postContent.act').slideUp(200);
	});
	
	// Home Cycle         
	$j('#featured').cycle({
    	fx: 'fade',
		speed: 700,
	    delay: 1,
	    timeout: 5000,		
	    prev: '#prev',
	    next: '#next',
	 	after: onAfter			
    }); 
   	function onAfter(curr,next,opts) {
		var caption = (opts.currSlide + 1) + '/' + opts.slideCount;
		$j('.count').html(caption);
	}
	
	// Toggle coupon module
	$j('#coupon').hide();
	$j('.coupon-btn').toggle(function() {
		$j('#coupon').slideDown(200);
	}, function() {
		$j('#coupon').slideUp(200);
	});
	

	
});
