var jQ,ttVars={};
jQuery.noConflict();jQ=jQuery;

if(jQ.browser.msie && jQ.browser.version<7){try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}}

jQ(document).ready(function(){pageOnLoad();});


function pageOnLoad(){
	
	/* --- common --- */
	
	jQ('a.edit').click(function(){window.open(this.href,'edit','toolbar=0');return false;});
	jQ('.quicksearch a').click(function(){
		document.location.href=document.location.protocol+'//'+document.location.host+'/?search='+jQ('#search').val();
		return false;
	});
	jQ('.quicksearch input').click(function(){
		if(this.value==this.defaultValue)this.value=""}
	).blur(function(){
		if(this.value=="")this.value=this.defaultValue}
	);
	//jQ('form tfoot').find('a','button').click(fn_submit);
	jQ('a.bookmark').click(makeBookmark);
	jQ('#reload_vcode_img').click(function(){
		var i=jQ('#vcode_img');
		v.attr('src',v.attr('src')+'?');
		return false;
	});
	
	var crt=jQ('.cart');
	if(crt.length){
		crt.find('.checkout').click(function(){try{document.checkout.submit();}catch(ex){};return false});
		crt.find('.update').click(function(){try{document.cart.submit();}catch(ex){};return false});
		crt.find('.continue').click(function(){document.location.pathname='/';return false});
		//crt.find('img.photo').click(function(){return popImg('imgs/pills/blisters/'+jQ(this).attr('prod')+'.jpg');});
		crt.find('img.photo').click(popImg);
	}

	var crt=jQ('.product');
	if(crt.length){
		crt.find('img.photo').click(popImg);
	}
	
	/* --- site specific --- */
	
	jQ('#big_pic img').mouseover(function(){ jQ('#big_pic').css('background-image','url(imgs/'+this.id+'.jpg)') });
	var prod=jQ('table.prod');
	if(prod.length){
		var u=prod.find('a').attr('href');
		prod.find('h3','span','img').click(function(){location=u;});
	}
	
	//swfobject.embedSWF("imgs/trustt_1.swf", "flashcontent1", "510", "234", "7");
	swfobject.embedSWF("imgs/trustt_2.swf", "flashcontent2", "230", "214", "7");
	swfobject.embedSWF("out/?id=we_accept_banner", "we_accept", "235", "20", "8",null,null,{scale:'noscale',wmode:'transparent',salign:'l'});

}


/* ---- common utils ---- */

var psTT1rsid;
ttVars.projName='rxpartners';

function initSupportWindow(){
	var src=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+"/js/"+ttVars.projName+"/safe-standard.js?ps_h=TT1r\u0026ps_t="+new Date().getTime();
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', src);
	document.getElementById('live_support').appendChild(js);
}
function openSupportWindow(){
	if(psTT1rsid){
		if(!ttVars.support_window || ttVars.support_window.closed){
			ttVars.support_window=popItUp('http://messenger.providesupport.com/messenger/'+ttVars.projName+'.html?ps_s='+psTT1rsid+'&ps_mht='+psTT1rmht,'support_window',500,560);
		}else{
			ttVars.support_window.focus();
		}
	}else{
		popItUp('about:blank','support_window',500,560);
		initSupportWindow();
		var timer = setInterval(function(){
			if(psTT1rsid){
				clearInterval(timer);
				openSupportWindow();
			}
		}, 5);
	}
}
function reloadImageCode(){
	var img=document.getElementById('vcode_img');
	if(!ttVars.imgCodeUrl) ttVars.imgCodeUrl=img.src;
	img.src=ttVars.imgCodeUrl+'?'+Math.random();
}
function popItUp(u,n,w,h){
	var l=(screen.availWidth  - w) / 2, t=(screen.availHeight - h) / 2
	,op='toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',left='+l+',top='+t
	,n=n||'_blank';
	return window.open(u,n,op);
}
function showCertificate(u){
	u=u||'out.php?id=certificates_url';
	if(!ttVars.cert_window || ttVars.cert_window.closed){
		ttVars.cert_window=popItUp(u,'cert_window',500,350);
	}else{
		ttVars.cert_window.focus();
	}
}
function showSpecialOffer(u){
	u=u||'out.php?id=special_offer_url';
	if(!ttVars.spo_window || ttVars.spo_window.closed){
		ttVars.spo_window=popItUp(u,'spo_window',620,620);
	}else{
		ttVars.spo_window.focus();
	}
}

function popImg(){
	var u='imgs/pills/blisters/'+jQ(this).attr('prod')+'.jpg';
	var h='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
	+'<head><title></title>'
	+'<style>html,body,table{margin:0;padding:0;height:100%;width:100%;text-align:center}</style>'
	+'</head><body onclick="close();"><table><tr><td><img src="'+u+'" /></td></tr></table></body></html>';
	var wnd=popItUp('','img_window'+Math.random(),510,510);
	wnd.document.write(h);
	wnd.focus();
	return false;
}

function makeBookmark(){
	var host=document.location.host,
	u='http://'+host+'/';
	try{
		if (window.sidebar){
		window.sidebar.addPanel(this.title, u, '');
		}else if(document.all){
		window.external.AddFavorite(u, this.title);
		}
	}catch(ex){alert(ex.message)}
	return false;
}

function showLiveSupport(){popItUp('out.php?id=livesupport',620,620)}


