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){
		prod.each(function(i,el){
			var u=jQ(el).find('.add-inf a').attr('href');
			jQ(el).find('h3, 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 utilVars={projName:'onlinepharmacytrusted.com'}, psWWWrsid;

function openSupportWindow(){ showWindow('support_window','/out/?id=live_support_url',550,560); }
function showCertificate(u){
	u=u||'out.php?id=certificates_url';
	showWindow('cert_window',u,500,350);
}
function showSpecialOffer(u){
	u=u||'out.php?id=special_offer_url';
	showWindow('spo_window',u,620,620);
}
function showWindow(id,u,w,h){
	if(!utilVars[id] || utilVars[id].closed){
		utilVars[id]=popItUp(u,id,w,h);
	}
	utilVars[id].focus();
}
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 reloadImageCode(){
	var img=document.getElementById('vcode_img');
	if(!utilVars.imgCodeUrl) utilVars.imgCodeUrl=img.src;
	img.src=utilVars.imgCodeUrl+'?'+Math.random();
}

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 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('about:blank','img_window',520,520);
	wnd.document.write(h);
	wnd.focus();
	return false;
}


//function showLiveSupport(){popItUp('out.php?id=livesupport',620,620)}


