Cufon.replace('#left h3, #home_promo h3, #footer_nav h3, #news_signup_btn, #shop_nav a, #header_shop_by, #right h4, #notice h4, .btn_link', { hover:'true', fontFamily: 'Akzidenz' });
Cufon.replace('#home_featureWrapper p', { fontFamily: 'Tiasco', fontSize: '15px' });
Cufon.replace('#right h1, #right h2, #right h6, #notice h3, #v65-productDescription h1', { fontFamily: 'Tiasco' });


var loadingGraphic = '<img src="/assets/images/loading.gif">';

$(document).ready(function(){
						   
	productSearch.clearData();
	emailSubscribe.clearData();
	emailSubscribe.processForm();
	
	//Homepage transparent background
	var textHeight = $('#home_featureWrapper p').css("height");
	$('#home_featureTextBackground').css("height",textHeight+20);
	
	// FIND PAGE
	/*$("#findWines").change(function(){
		if($(this).val() != "")
		{
			location.href = "/find.php?region=" + $(this).val();
		}
		return false;
	});*/
	
	// SEARCH WINES
	/*$("#search_filter").change(function(){
		location.href = "/products/" + this.getAttribute("rel") + $(this).val() + "/";
		return false;
	});*/
	
	// BROWSE WINES
	/*$("#browse_varietal").change(function(){
		if($(this).val() != "")
		{
			location.href = "/products/varietal/" + $(this).val() + "/";
		}
		return false;
	});*/
	
	// WINE CLUB SIGNUP
	/*$("#signup_form #wc_billing_state").val($("#signup_form #wc_billing_state").attr("rel"));
	$("#signup_form #wc_shipping_state").val($("#signup_form #wc_shipping_state").attr("rel"));
	$("#signup_form #cc_type").val($("#signup_form #cc_type").attr("rel"));
	$("#signup_form #copy_address").click(function(){
		$("#signup_form #wc_shipping_first_name").val($("#signup_form #wc_billing_first_name").val());
		$("#signup_form #wc_shipping_last_name").val($("#signup_form #wc_billing_last_name").val());
		$("#signup_form #wc_shipping_address1").val($("#signup_form #wc_billing_address1").val());
		$("#signup_form #wc_shipping_address2").val($("#signup_form #wc_billing_address2").val());
		$("#signup_form #wc_shipping_city").val($("#signup_form #wc_billing_city").val());
		$("#signup_form #wc_shipping_state").val($("#signup_form #wc_billing_state").val());
		$("#signup_form #wc_shipping_zip").val($("#signup_form #wc_billing_zip").val());
		$("#signup_form #wc_shipping_phone").val($("#signup_form #wc_billing_phone").val());
		
		return false;
	});*/
	
	// VIEW CART
	/*$("#form_cart .view_cart_update").click(function(){
		$("#form_cart #action").val("update");
		$("#form_cart").submit();
	});
	$("#form_cart #checkout_button").click(function(){
		$("#form_cart #action").val("checkout");
		$("#form_cart").submit();
	});
	$(".removeItem").click(function(){
		return confirm("Are you sure you want to remove this product from your cart?");
	});*/
	
	// CHECKOUT
	/*$(".update_shipping_method").change(function(){
		location.href = "/checkout.php?shipping_method_id=" + this.value;
	});
	$("#checkout_place_order_button").click(function(){
		$("#checkout_place_order").hide("fast");
		$("#checkout_processing").show("fast");
		$("#form_checkout").submit();
		return false;
	});
	$("#apply_promo_code").click(function(){
		$("#form_promo_code").submit();
		return false;
	});	
	$("#form_checkout #gift").click(function(){
		if($("#form_checkout #gift").is(':checked'))
		{
			$("#form_checkout #gift_message_wrapper").show();
		} else {
			$("#form_checkout #gift_message_wrapper").hide();
		}
	});	*/
	
	// PRODUCT IMAGE ZOOM
	/*$(".colorBox").click(function(){
		_href = $(this).attr("href");
		$.fn.colorbox({open:true, inline:true, href:_href, opacity: "0.75"});
		return false;
	});
	
	$("a.zoom").click(function(){
		var _href = $(this).attr("href");
		$.fn.colorbox({open:true, href: _href, opacity: "0.75"});
		return false;
	});*/
	
	
	
	// TERM DEFINITION BOXES
	$(".moreInfo_box").addClass("boxStyle").hide();
		
	$(".moreInfo").css("cursor","help").each(function(){
		var _el = $(this).attr("id");
		_el = _el.replace("link_", "#");
		var _pos = $(this).position();
		var _posTop = _pos.top;
		var _posLeft = _pos.left;
		var _linkWt = $(this).width();
		var _ht = $(_el).height();
		var _wt = $(_el).width();
		var _top = _posTop - _ht - 3 + "px";
		var _left = _posLeft - _wt/2 + _linkWt/2 + "px";
		
		$(_el).css({
			position:"absolute",
			zIndex:"100",
			top:_top,
			left:_left
		});
		
		$(this).hover(function(){
			$(_el).fadeIn();
		}, function() {
			$(_el).hide();
		});
	});
	
	$(".moreInfo").click(function(){ return false; })
	
	
	
	// TRADE & MEDIA PREVIEWS
	$('a.preview').imgPreview({
	    imgCSS: {
	        // Limit preview size:
	        width:150
	    },
		preloadImages:false,
		distanceFromCursor:{
			top:-80,
			left:-195
		},
		onShow: function(link){
	        // Reset image:
	        $('img', this).stop().css({opacity:0});
		 },
	    onLoad: function(){
	        // Animate image
	        $(this).animate({opacity:1}, 300);
	    }
	});
	
	// VINEYARD INFO
	$("ul#estate_vineyards_nav a").click(function(){
		var theID = "#" + $(this).attr("class");
		theID = theID.replace(" active", "");
		var theList = theID + "_vineyard";
		$("#zeferino_vineyard, #coquina_vineyard, #potrero_vineyard").not("p#vin_intro").hide();
		$("p#vin_intro:visible").hide();
		$(theList).slideDown();
		$("ul#estate_vineyards_nav a").removeClass("active");
		$(this).addClass("active");
		return false;
	});
	$("#zeferino_vineyard, #coquina_vineyard, #potrero_vineyard").hide();

	//TRADE TABLES
	$("table.media tr:even").addClass("oddRow");
	
	// MISC
	$(".print_this").click(function(){
		window.print();
		return false;
	});
	$(".go_back").click(function(){
		history.go(-1);
		return false;
	});
});


/* -- STATE VERIFICATION -- */

/*var _state;

var _cookie = readCookie('stateVerified');
if (_cookie) {
	_state = 1;
} else {
	$(function(){
		$("html, body, #wrapper").css("overflow","hidden");
		$("#noticeWrap").fadeIn();
	});
	_state = 0;
}*/

// WINE DETAIL - Share Item On Social Networking Sites -------- /
function fbs_click(u, t) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function twitter_click(t) {
	window.open('http://twitter.com/home?status='+encodeURIComponent(t));
	return false;
}

productSearch = {
	clearData: function() {
		$("#search_bar input").focus(function() {
			$(this).attr('value','');
		});
		$("#search_bar input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	}
},

emailSubscribe = {
	clearData: function() {
		$("#subscribeForm input").focus(function() {
			$(this).attr('value','');
		});
		$("#subscribeForm input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	},
	processForm: function() {
		$("#subscribeForm form").submit(function(){
			formLabelsAndValues=$("#subscribeForm form").serialize();
			$("#subscribeForm").html(loadingGraphic);
			$.post('/components/subscribe/process.cfm',formLabelsAndValues, function(response) {
				emailSubscribe.formResponse(response);
			});
			return false;
		});	
	},
	formResponse: function(response) {
		$("#subscribeForm").html(response);
		emailSubscribe.processForm();
	}
}
