$(document).ready(function() {	
	/* Drop Down Menu */
	jQuery('ul.navigation').superfish();
	
	$("#select_category").change(function(){
		$.getJSON(
				BaseUrl + "/products/jsoncategory",
				{id: $(this).val(), name: $(this).attr("id"),  ajax: 'true'},				
				function(j){
					var options = '';
					$.each(j, function(index, value) { 
						options +='<option value="' + value.id + '">' + value.name + '</option>'; 
						});
					
					$("#select_products").html(options);
						
/*					for(var i = 0; i < j.length; i++){
						options +='<option value="' + j[i].id + '">' + j[i].name + '</option>';					
						
					}
					$("#select_products").html(options);			
*/		})	
		
	});
	$("#add_products").click(function(){		
		$.getJSON(
				BaseUrl + "/products/jsoncategory",
				{id: $("#select_products").val(), name: $("#select_products").attr("id"),  ajax: 'true'},				
				function(j){
					var options  = '<option value="' + j.id + '" selected="selected">' + j.name + '</option>';					
					
					$("#view_products").append(options);						
		})		
	});
	$(".info").click(function(){		
		$(this).parent().parent().addClass("active");
		$(this).parent().parent().prev().removeClass("active");
		$(".product_det_overview").css("display", "none");
		$(".product_det_info").css("display", "block");
	});
	$(".overview").click(function(){		
		$(this).parent().parent().addClass("active");
		$(this).parent().parent().next().removeClass("active");
		$(".product_det_overview").css("display", "block");
		$(".product_det_info").css("display", "none");
	});
	
	$(".thumbs a").click(function(){
		
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");		
				
		$("#largeImg").attr({ src: largePath, alt: largeAlt });
		return false;
	});
	
	$(".product_det_color a").click(function(){
		$(".product_det_color a").removeClass("active");
		//var colorRGB = $(this).attr("href");
		var colorName = $(this).attr("title");
		
		$(this).addClass("active");
		
		$("#choose_color").attr({ value: colorName});
		//$("#choose_color_name").attr({ value: colorName});
		$(".product_det_color_choose").html(colorName);
		return false;
	});
	$(".product_det_size a").click(function(){
		$(".product_det_size a").removeClass("active");
		var sizeName = $(this).attr("href");	
		
		$(this).addClass("active");		
		
		$("#choose_size").attr({ value: sizeName});
		$(".product_det_size_choose").html(sizeName);
		return false;
	});
	
	$("#same_as_billing").click(function(){
		
		if($('#same_as_billing').attr('checked')){
			
			var billing_first_name = $("#billing_first_name").attr("value");
			var billing_middle_name = $("#billing_middle_name").attr("value");
			var billing_last_name = $("#billing_last_name").attr("value");
			var billing_company_name = $("#billing_company_name").attr("value");
			var billing_address = $("#billing_address").attr("value");
			var billing_city = $("#billing_city").attr("value");
			var billing_state = $("#billing_state").attr("value");
			var billing_non_us_state = $("#billing_non_us_state").attr("value");
			var billing_zip = $("#billing_zip").attr("value");
			var billing_phone = $("#billing_phone").attr("value");
			var billing_work_phone = $("#billing_work_phone").attr("value");
			var billing_work_phone_ext = $("#billing_work_phone_ext").attr("value");
			var billing_fax = $("#billing_fax").attr("value");	
			
		}else{
			var billing_first_name = '';
			var billing_middle_name = '';
			var billing_last_name = '';
			var billing_company_name = '';
			var billing_address = '';
			var billing_city = '';
			var billing_state = '';
			var billing_non_us_state = '';
			var billing_zip = '';
			var billing_phone = '';
			var billing_work_phone = '';
			var billing_work_phone_ext = '';
			var billing_fax = '';	
			
		}
		
		$("#shipping_first_name").attr({ value: billing_first_name});
		$("#shipping_middle_name").attr({ value: billing_middle_name});
		$("#shipping_last_name").attr({ value: billing_last_name});
		$("#shipping_company_name").attr({ value: billing_company_name});
		$("#shipping_address").attr({ value: billing_address});
		$("#shipping_city").attr({ value: billing_city});
		$("#shipping_state").attr({ value: billing_state});
		$("#shipping_non_us_state").attr({ value: billing_non_us_state});
		$("#shipping_zip").attr({ value: billing_zip});
		$("#shipping_phone").attr({ value: billing_phone});
		$("#shipping_work_phone").attr({ value: billing_work_phone});
		$("#shipping_work_phone_ext").attr({ value: billing_work_phone_ext});
		$("#shipping_fax").attr({ value: billing_fax});		
		
	});
	
});


