$(document).ready(function() { // init

	$(".feats_page").hide();
	$("#feats1").show();

	$(".brands_page").hide();
	$("#brands1").show();

	//$("div#left1").hide();
	//$("#top2").fadeIn(500);

	$top_page = 1;
	$feat_page= 1;
	
});

$(document).ready(function() {

	var $flip_top = setInterval(update_top, 5000);

});

function update_top(){

	if($top_page == 1){

		$top_page = 2;

		$('div#left1').fadeOut(500);
		$('div#left2').fadeIn(500);
	
	} else {
	
		$top_page = 1;
	
		$('div#left2').fadeOut(500);
		$('div#left1').fadeIn(500);
	
	}

}


//Brand Bar Scroll

$(document).ready(function() {

	$current_page = 1;
	$current_pos = 0;
	
	$page_width = $('div#cats').width();
	
	$total_width = 0;
	$('div#cats > a').each(function() { $total_width += $(this).outerWidth( true ) + 24; });
	
	$total_pages = Math.ceil($total_width / $page_width);
		
	$('div.cats_nav').click(function(event) { 

		if(event.target.id == 'cats_nav_left'){
		
			if($current_page - 1 >= 1){ $current_page--; $current_pos -= $page_width; $('div#cats').scrollTo($current_pos, 1000); }
		
		} else {
		
			if($current_page + 1 <= $total_pages){ $current_page++; $current_pos += $page_width; $('div#cats').scrollTo($current_pos, 1000); }
		
		}
		

	});

	

});


//Featured Products Navigation
$(document).ready(function() { 

	// Featured Products Auto-scroll
	var $flip_feat = setInterval(feat_next, 4500);

	$('div#featured').mouseover(function(event) { clearInterval($flip_feat); });
	$('div#featured').mouseout(function(event) {	$flip_feat = setInterval(feat_next, 3000); });


	$feat_current_page = 1;
	$feat_total_pages = $('div#featured').children().size() - 3;

	$('div.feat_nav').click(function(event) { 
	
		if(event.target.id == 'feat_nav_left'){
		
			feat_next();
		
		} else {
		
			$('#feats'+$feat_current_page).fadeOut(500);
			
			$feat_current_page++;
			if($feat_current_page > $feat_total_pages){ $feat_current_page = 1; }
			
			$('#feats'+$feat_current_page).fadeIn(1000);
		
		}

	});
	
	function feat_next(){
	
		$('#feats'+$feat_current_page).fadeOut(500);
		
		$feat_current_page--;
		if($feat_current_page == 0){ $feat_current_page = $feat_total_pages; }
		
		$('#feats'+$feat_current_page).fadeIn(1000);
	
	}

});


//Brands Navigation
$(document).ready(function() { 

	// Featured Products Auto-scroll
	var $flip_brand = setInterval(brand_next, 10000);

	$('div#brands').mouseover(function(event) { clearInterval($flip_brand); });
	$('div#brands').mouseout(function(event) { $flip_brand = setInterval(brand_next, 3000); });

	$brands_current_page = 1;
	$brands_total_pages = $('div#brands').children().size() - 3;

	$('div.brands_nav').click(function(event) { 
	
		if(event.target.id == 'brands_nav_left'){
		
			brand_next();

		
		} else {
		
			$('#brands'+$brands_current_page).fadeOut(500);
			
			$brands_current_page++;
			if($brands_current_page >= $brands_total_pages){ $brands_current_page = 1; }
			
			$('#brands'+$brands_current_page).fadeIn(1000);
		
		}

	});

	function brand_next(){
	
		$('#brands'+$brands_current_page).fadeOut(500);
		
		$brands_current_page--;
		if($brands_current_page == 0){ $brands_current_page = $brands_total_pages - 1; }
		
		$('#brands'+$brands_current_page).fadeIn(1000);	
	
	}

});


//Mars Hovers
$(document).ready(function() { 


});

function hideAll(){

	//$('#about_content').hide();

}

function clearSelection(){

	//$("#about").removeClass("selected");

}

