jQuery(document).ready(function(){


	jQuery("#add_inside_text").click(function () {
		jQuery("#inside_text_fields").slideToggle("slow");
	});

	jQuery("#matching_cc").click(function () {
		jQuery("#calling_card_text_fields").slideToggle("slow");
	});

	jQuery("#rsvp_status").click(function () {
		jQuery("#rsvp_cards_fields").slideToggle("slow");
	});

	jQuery("#gift_wrap").click(function () {
		 jQuery("#gift_wrap_message").toggle();
	});

	jQuery("#spiral_notebook").click(function () {
		 jQuery("#matching_notebook_message").toggle();
	});

	jQuery("#add_custom_rsvp_cards").click(function () {
		jQuery("#rsvp_cards_fields").slideToggle("slow");
	});

	jQuery("#ship_to_bill").click(function () {
		jQuery("#shipping_form_address_fields").slideToggle("slow");
	});

	jQuery(".seotxt > p:first-child").click(function () {
		jQuery(".seotxt > p").toggle();
		jQuery(this).show();
	});

	jQuery("#gift_certificate_value").click(function () {
		var value 	= jQuery(this).val();
		var image 	= '/wp-content/themes/fab/images/gift_certificates/giftcert-'+value+'.jpg';
		jQuery("#img-main").attr("src",image);
		jQuery("#graphic_image").attr("value",image);
		jQuery("#unit_price").attr("value",value);
		jQuery("#price").attr("value",value);
	});

	jQuery(".card_shop_ajaxadd").submit(function (event) {


		var ajaxurl = '/wp-admin/admin-ajax.php';
		var options = { 
				//beforeSubmit:  	showRequest,  // pre-submit callback 
				url: 			ajaxurl,
				type: 			'POST',
				success:		showAjaxAlert,
				data:			{action: 'vervecart_addtocart'}
				
		}
		jQuery(this).ajaxSubmit(options);
		
		return false;

	});

	function showRequest(formData, jqForm, options) { 

		var queryString = jQuery.param(formData); 
		alert('About to submit: \n\n' + queryString); 
		return true; 
		
	} 

	function showAjaxAlert(responseText, statusText, xhr, $form) { 

		//alert(responseText);
		//alert(statusText);

		var response = 'Item added.<br /><a href="/shopping-cart/">View cart &raquo;</a>';
		jQuery("#ajax-alert-box").show().html(response).delay(3500).fadeOut(2000);
		//jQuery("#ajax-alert-box").show().html(response); 
		
	} 

	jQuery(".color-option").click(function () {
		var ajaxurl 	= '/wp-admin/admin-ajax.php';
		var itemid		= jQuery(this).attr("alt");
		//alert(itemid);
		var data = {
			action: 'switch_color',
			itemid: itemid
		};
		jQuery.post(ajaxurl, data, function(item) {
        		//alert('inside function data');
				//alert('inside jquery each');
				//alert(item.product_image);
				jQuery("#img-main").attr("src",item.product_image);
				jQuery("#itemid").attr("value",item.itemid);
				
				if(item.sale_price>0){
					var product_title = item.product_title + ' <span class="price"><strike>$' + item.base_price + '</strike></span> <span class="sale-price">$'+item.sale_price+'</span>';
				}else{
					var product_title = item.product_title + ' <span class="price">$' + item.base_price + '</span>';
				}
				jQuery("#product_title").html(product_title);
				//jQuery("#product_description").html(item.product_description);
				jQuery("#heartme").attr("title",item.itemid);
				jQuery("#item_name").attr("value",item.item_name);
				jQuery("#item_color_tag").attr("value",item.item_color_tag);
				jQuery("#item_design_tag").attr("value",item.item_design_tag);
				jQuery("#graphic_image").attr("value",item.product_image);
				jQuery("#base_price").attr("value",item.base_price);
				jQuery("#sale_price").attr("value",item.sale_price);
				jQuery("#unit_price").attr("value",item.unit_price);
				jQuery("#matching_cc_itemid").attr("value",item.matching_cc_itemid);
				jQuery("#matching_cc_image").attr("value",item.matching_cc_image);
				jQuery(".matching_cc_url").attr("href",item.matching_cc_url);
				jQuery("#img-cc").attr("src",item.matching_cc_image);
				jQuery("#img-notebook").attr("src",item.product_image);
				jQuery("#img-matching-notecard").attr("src",item.matching_notecard_image);
				jQuery("#img-matching-notecard").attr("alt",item.matching_notecard_itemid);
				jQuery(".matching-notecard-url").attr("href",item.matching_notecard_url);
        },'json');
	});


	
	jQuery(".case-uc").keyup(function(){
		jQuery(".case-uc").val().toUpperCase();
	});
	jQuery(".case-lc").keyup(function(){
		jQuery(".case-lc").val().toLowerCase();
	});
	jQuery(".case-uppercase").keyup(function(){
		jQuery(".case-uppercase").val().toUpperCase();
	});
	jQuery(".case-lowercase").keyup(function(){
		jQuery(".case-lowercase").val().toLowerCase();
	});

		
	jQuery("li.carttab.front").click(function (e) {
		 e.preventDefault;
		 jQuery("li.carttab").removeClass("active");
		 jQuery("div.cart-selection-specs-content").hide();
		 jQuery(this).addClass("active");
		 jQuery("div.cart-selection-specs-content.front").fadeIn("slow");
		 //jQuery.scrollTo(this);
	});
	
	jQuery("li.carttab.return").click(function (e) {
		 e.preventDefault;
		 jQuery("li.carttab").removeClass("active");
		 jQuery("div.cart-selection-specs-content").hide();
		 jQuery(this).addClass("active");
		 jQuery("div.cart-selection-specs-content.return-address").fadeIn("slow");
		 //jQuery.scrollTo(this);
	});

	jQuery("li.carttab.inside").click(function (e) {
		 e.preventDefault;
		 jQuery("li.carttab").removeClass("active");
		 jQuery("div.cart-selection-specs-content").hide();
		 jQuery(this).addClass("active");
		 jQuery("div.cart-selection-specs-content.inside-text").fadeIn("slow");
		 //jQuery.scrollTo(this);
	});

	jQuery("li.carttab.rsvp").click(function (e) {
		 e.preventDefault;
		 jQuery("li.carttab").removeClass("active");
		 jQuery("div.cart-selection-specs-content").hide();
		 jQuery(this).addClass("active");
		 jQuery("div.cart-selection-specs-content.rsvp-text").fadeIn("slow");
		 //jQuery.scrollTo(this);
	});

	jQuery("li.carttab.options").click(function (e) {
		 e.preventDefault;
		 jQuery("li.carttab").removeClass("active");
		 jQuery("div.cart-selection-specs-content").hide();
		 jQuery(this).addClass("active");
		 jQuery("div.cart-selection-specs-content.options").fadeIn("slow");
		 //jQuery.scrollTo(this);
	});
	
	jQuery("input[name='shipping_method']").click(function(){
		var values = jQuery(this).attr("value").split(":");
		//alert(values[1]);
		var currentSubtotal 	= jQuery("input[name='subtotal']").attr("value");
		var currentCoupon 		= jQuery("input[name='coupon_value']").attr("value");
		var currentCertificate 	= jQuery("input[name='certificate_value']").attr("value");
		var currentCredit 		= jQuery("input[name='order_send_credit_value']").attr("value");
		var currentTax 			= jQuery("input[name='tax_value']").attr("value");
		var shippingCharge 		= parseFloat(values[1]);
		var newOrderTotal		= parseFloat(currentSubtotal) - 
								  parseFloat(currentCoupon) -
								  parseFloat(currentCertificate) -
								  parseFloat(currentCredit) +
								  parseFloat(currentTax) +
								  parseFloat(shippingCharge);
		//alert(newOrderTotal);
		jQuery("#updatable-order-total").html(newOrderTotal.toFixed(2));
		jQuery("#tr-total").effect("highlight", {}, 2000);
	
	});
	
	jQuery(".heartme").click(function (e) {
		e.preventDefault;
		var itemid = jQuery(this).attr("title");
		jQuery.get("/wp-content/themes/fab/ajax/favorites.php", { itemid: itemid },
		function(data){
			//alert(data);
			jQuery(".canfavorite").hide();
			jQuery(".isfavorite").show();
		});
	});


	jQuery("select[name=country]").click(function () {
		var country = jQuery(this).val();
		if( country == 'US' || country == 'CA' ){
			jQuery("#domestic-state").show();
			jQuery("#international-state").hide();
		}else{
			jQuery("#domestic-state").hide();
			jQuery("#international-state").show();
		}
	});
	
	jQuery("select[name=shipping_country]").click(function () {
		var country = jQuery(this).val();
		if( country == 'US' || country == 'CA' ){
			jQuery("#domestic-shipping-state").show();
			jQuery("#international-shipping-state").hide();
		}else{
			jQuery("#domestic-shipping-state").hide();
			jQuery("#international-shipping-state").show();
		}
	});
	
	jQuery("#form_login").validationEngine({ 
		inlineValidation: false, 
		success :  false
	});
	
	jQuery("#form_customer_data").validationEngine({ 
		inlineValidation: false, 
		success :  false
	});
	
	jQuery("#form_order_totals").validationEngine({ 
		inlineValidation: false, 
		success :  false
	});
	
	jQuery("#form_edit_selection").validationEngine({ 
		inlineValidation: false, 
		success :  false
	});
	
	
	jQuery(".color-filter").click(function () {
		var color = jQuery(this).attr("href");
			color = color.replace('#','');
		var items_to_show = '.category-product-image.'+color;
		if(color == 'all'){
			jQuery(".category-product-image").show();
		}else{
			jQuery(".category-product-image").hide();
			jQuery(items_to_show).show();
		}
		jQuery(".color-filter").removeClass("selected");
		jQuery(this).addClass("selected");
	});

	jQuery(".occasion-filter").click(function () {
		var occasion = jQuery(this).attr("href");
			occasion = occasion.replace('#','');
		var items_to_show = '.category-product-image.'+occasion;
		if(occasion == 'all'){
			jQuery(".category-product-image").show();
		}else{
			jQuery(".category-product-image").hide();
			jQuery(items_to_show).show();
		}
		jQuery(".occasion-filter").removeClass("selected");
		jQuery(this).addClass("selected");
	});


	jQuery("ul#menu-personalized-cards > li > ul.sub-menu > li#menu-item-17708 > ul.sub-menu").hover(
		function () {
			jQuery('li#menu-item-17708 > a').addClass('active');
		}, 
		function () {
			jQuery('li#menu-item-17708 > a').removeClass('active');
		}
	);

	jQuery("ul#menu-personalized-cards > li > strong > ul.sub-menu > li#menu-item-17708 > ul.sub-menu").hover(
		function () {
			jQuery('li#menu-item-17708 > strong > a').addClass('active');
		}, 
		function () {
			jQuery('li#menu-item-17708 > strong > a').removeClass('active');
		}
	);


	jQuery("ul#menu-1-greeting-card-shop > li > ul.sub-menu").hover(
		function () {
			jQuery('li#menu-item-19062 > a').addClass('active');
		}, 
		function () {
			jQuery('li#menu-item-19062 > a').removeClass('active');
		}
	);

	jQuery("ul#menu-1-greeting-card-shop > li > strong > ul.sub-menu").hover(
		function () {
			jQuery('li#menu-item-19062 > strong > a').addClass('active');
		}, 
		function () {
			jQuery('li#menu-item-19062 > strong > a').removeClass('active');
		}
	);


// 	jQuery("div.special-offer-discount > a").hover(
// 		function(){
// 			jQuery(this).children(".special-offer-description").fadeIn(500);
// 		},
// 		function(){
// 			jQuery(this).children(".special-offer-description").fadeOut(100);
// 		}
// 	);	

// 	jQuery("div.special-order-notice").toggle(
// 		function(){
// 			jQuery(this).children(".special-order-hover-box").fadeIn(500);
// 		},
// 		function(){
// 			jQuery(this).children(".special-order-hover-box").fadeOut(100);
// 		}
// 	);


});
// $j(document).ready(function(){
// 	
// 	$j('ul.fab_product_views').show();
// 
// 	$j('ul.fab_product_views').galleria({
// 		history   : false, 
// 		clickNext : true, 
// 		insert    : '#main-image'
// 	});
// 
// });

