// JavaScript Document

function toggleEvent(){
	$(".sectionHead").click(function(){
		$(this).next().slideToggle(500);
		
	});	
}

function initNav(){
	$('.logout_button').click(function(){
		$.post(siteUrl+"home/customer_logout/", { 
			   			'number' : 1
			   },
			   function(data){
				   		if(data.success == 1){
							window.location = siteUrl;
						} 
				   }, "json");
	});	
	
	$('.login_button').click(function(){
		window.location = siteUrl + "shop/cart/";
	});
	
	$('.shopping_cart_button').click(function(){
		window.location = siteUrl + "shop/cart/cart";
	});
	
	
	$('#submit_login_button').click(function(){
		var customer_email = $('#login_email').val();
		var customer_password = $('#login_password').val();
		
		$.post(siteUrl+"home/customer_login/", { 
			   			'customer_email' : customer_email,
						'customer_password' : customer_password
			   },
			   function(data){
				   
				   		if(data.success == 1){
							$.cookie("customer_session_id", data.customer_session_id, { expires: 365, path: '/'});
							$.cookie("customer_session_key", data.customer_session_key, { expires: 365, path: '/'});
							$('#login_message_box').css('color', 'green').html('Login Successful.').fadeIn(500).delay(2500).fadeOut(500, function(){window.location = siteUrl + "shop/cart/cart";});
							
						} else {
							$('#login_message_box').css('color', 'red').html('Login Failed.');
						}
				   }, "json");
	
	});
}
 
 
$(document).ready(function(){
	Cufon.replace('h1');
	Cufon.replace('h2');
	
	//$("#mastFooter").jixedbar();
	
	toggleEvent();
	$('#topSpacer').height($('#mastHead').height());
 
 	$('#button_shopping_cart').click(function(){
		window.location = siteUrl + "shop/cart";
	});
 	
	
	initNav();
	if($('#reset_password').size() > 0){
		$('#reset_password').validate();
	}
});

function clearcart(){ // resets cart
		shopping_cart_array = new Array();
		if(shopping_cart_array.length == 0){
				$('#cart_total h2').html('$0.00');
				$('.total_cart').html('$0.00');
				Cufon.replace('h1');
				$('#cart_list').html('');
				Cufon.replace('h2');
		}
		$.cookie("shop_cart", "", { expires: -1, path: '/' });
		$.cookie("shop_cart_total", '$0.00', { expires: 1, path: '/' });
		$('.total_cart').html('$0.00');
		$('#grand_total').html('$0.00');
		$('.table_line').remove()
		Cufon.replace('h1');
		shopping_cart_pointer = 0;
		
}



