if (typeof($j)=="undefined") {var $j = jQuery.noConflict();}
$j(document).ready(function() { // footer startup
	$j('ul#hp_footer li a img').bind('mouseover mouseout',function() {
		i = this.src.split('/');
		id = $j(this).attr('id')+'-';
		i[i.length-1] = (i[i.length-1].charAt(i[i.length-1].indexOf('-')+2)=='f') ? id+'on.png':id+'off.png';
		this.src = i.join('/');
	});
 });
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

var po_reg	=/P\.?[O,0]\.?\s*Box\s?#?\d+/i;
var po_reg2	=/p(ost)?[.\s-]+o(ffice)?[.\s-]+box/i;
var address = [];
var objs 	= [];
var po_msg 	= 'Physical street address is required for shipping address.';

function checkIfPO(addr,isbilling) {
	if (typeof(isbilling) == 'undefined') isbilling = false;
	if (isbilling) return;
	objs.push(addr);
	address.push(addr.value);
	if (po_reg.test(addr.value) || po_reg2.test(addr.value)) {
		addr.value = '';
		alert(po_msg);
		return false;
	}
	return true;
}

/* only fired from customer edit address */
function checkObjIsPO(addr,obj) {
	objs.push(addr);
	address.push(addr.val());
	if (po_reg.test(addr.val()) || po_reg2.test(addr.val())) {
		addr.val('');
		alert(po_msg);
		obj.checked=false;
		return false;
	}
	return true;
}

function checkIfPOs(isbilling) {
	if (typeof(isbilling) == 'undefined') isbilling = false;
	if (isbilling) return;
	addr = (address[1] != null || address[1] == '') ? address.join(' '):address[0];
	if (po_reg.test(addr) || po_reg2.test(addr)) {
		alert(po_msg);
		for(i=0;i<objs.length;i++) objs[i].value='';
		address.length=0;
		return false;
	}
	return true;
}

/* updated to accept either sku or id */
function addProductToCart(product,qty) {
	if (typeof(qty) == 'undefined') qty = 1;
	pth = '/buy/ajaxlib/product/addtocart/p/'+product+'/q/'+qty+'?ref='+Math.floor(Math.random()*1000+1);
	$j.getJSON(pth,function(data){
		if (data.error) {
			alert(data.error);
			return false;
		} 
		if (data.success) {
			document.location='/buy/checkout/cart';
		}
	});
}

function checkPhone(v) {
	pn = v.value;
	filter = pn.split("");
 	result = new Array();
	for (x=0;x<filter.length;x++) {
		if (js_ctype_num(filter[x])) result.push(filter[x]);
	}
	area = result.join("").substr(0,3);
	if (result.length != 10 || !is_valid_areacode(area)) {
		v.value='';
		alert('Please enter a valid phone number.');
		return false;
	} else {
		v.value=result.splice(0,3).join("")+'-'+result.splice(0,3).join("")+'-'+result.join("");
		return true;
	}	
}
function js_ctype_num(a) {m = a.charCodeAt(0);return ((m > 47) && (m <  58));}

var areacodes=Array(201,202,203,205,206,207,208,209,210,212,213,214,215,216,217,218,219,224,225,227,228,229,231,234,239,240,248,250,251,252,253,254,256,260,262,267,269,270,272,274,276,281,283,301,302,303,304,305,307,308,309,310,312,313,314,315,316,317,318,319,320,321,323,325,327,330,331,334,336,337,339,341,347,351,352,360,361,364,369,380,385,386,401,402,404,405,406,407,408,409,410,412,413,414,415,417,419,423,424,425,430,432,434,435,440,442,443,445,447,458,464,469,470,475,478,479,480,484,501,502,503,504,505,507,508,509,510,512,513,515,516,517,518,520,530,531,534,539,540,541,551,557,559,561,562,563,564,567,570,571,573,574,575,580,582,585,586,601,602,603,605,606,607,608,609,610,612,614,615,616,617,618,619,620,623,626,627,628,630,631,636,641,646,650,651,657,659,660,661,662,667,669,678,679,681,682,689,701,702,703,704,706,707,708,712,713,714,715,716,717,718,719,720,724,727,730,731,732,734,737,740,747,754,757,760,762,763,764,765,769,770,772,773,774,775,779,781,785,786,801,802,803,804,805,806,808,810,812,813,814,815,816,817,818,828,830,831,832,835,843,845,847,848,850,856,857,858,859,860,862,863,864,865,870,872,878,901,903,904,906,907,908,909,910,912,913,914,915,916,917,918,919,920,925,928,929,931,935,936,937,938,940,941,947,949,951,952,954,956,959,970,971,972,973,975,978,979,980,984,985,989);

function is_valid_areacode(code) {
	for(x=0;x<areacodes.length;x++) {
		if (areacodes[x]==code) return true;
	} 
	return false;
}

function checkZip(v) {
	z=v.value;
	invalid_z = false;
	if (z.length != 5) {
		invalid_z=true;
	} else {
		for (n=0;n<z.length;n++) {
			if (!js_ctype_num(z[n])) invalid_z=true;
		}
	}
	if (invalid_z) {
		v.value="";
		alert('Please enter a valid 5 digit zip code.');
		return false;
	}
	return true;
}
	
function reviewCB() {
	$j.colorbox({
		width:540, 
		height:550,
		inline:true, 
		title:'Add a Review: '+$j('.product-name h1').html(),
		href:"#review_wrapper",
		onOpen: function() {
			$j('#cboxTitle').css({'top':'0','text-align':'left','font-weight':'bold','height':'20px','width':'500px'});
			$j('#review_wrapper').css({'margin-top':'28px','margin-bottom':'0px'}).show();
		}
	});
	
}

var m2 = Array('mai','lt','o:q','uest','ions','@l','ivin','gpr','oo','f.','co','m');
function efilter() {document.location.href=m2.join('');return false;}
	
