// ============== peep ===============

function Peep(id)
{
	this.el=document.getElementById(id);
	if(!this.el) { return; }
	this.inital=70;
	this.final=0;
	this.pos=this.inital;
}

Peep.prototype.on=function()
{
	if(!this.el) return;
	if(this.pos==this.final) return;

	if(this.timer) clearInterval(this.timer);
	var keep_this=this;
	this.timer=setInterval(function() {
		var speed=(keep_this.final - keep_this.pos) / 4;

		keep_this.pos+=speed;

		if(keep_this.pos < keep_this.final) {
			keep_this.pos=keep_this.final;
			if(keep_this.timer) clearInterval(keep_this.timer);
			}
		keep_this.el.style.backgroundPosition='left '+keep_this.pos.toFixed()+'px';
		},40);
}

Peep.prototype.off=function()
{
	if(!this.el) return;
	if(this.pos==this.inital) return;

	if(this.timer) clearInterval(this.timer);
	var keep_this=this;
	this.timer=setInterval(function() {
		var speed=(keep_this.final - keep_this.pos) / 2;

		keep_this.pos-=speed;

		if(keep_this.pos > keep_this.inital) {
			keep_this.pos=keep_this.inital;
			if(keep_this.timer) clearInterval(keep_this.timer);
			}
		keep_this.el.style.backgroundPosition='left '+keep_this.pos.toFixed()+'px';
		},40);
}





// looking racks
var img32r=new Image();
img32r.src='32r.gif';
var img32ro=new Image();
img32ro.src='32ro.gif';

var img32l=new Image();
img32l.src='32l.gif';
var img32lo=new Image();
img32lo.src='32lo.gif';




function init()
{
// user ID
	window.user_id=getCookie('custid');


//SHOPPING CART
	window.cart=new Slider('right',100);
	document.getElementById('container').appendChild(window.cart.base);
	window.cart.base.className='cartslider';

	var iframe=document.getElementById('cart-frame');
	window.cart.base.appendChild(iframe);

	window.refresh_cart=function() { window.cart.on(); window.cart.base.firstChild.style.display="block"; }

//FLAG
	window.flag=new Slider('right',100);
	document.getElementById('container').appendChild(window.flag.base);
	window.flag.base.className='cartslider';
	window.flag.base.innerHTML="<A HREF='http://jeunesse-spb.ru/cgi-bin/shop.pl' ONCLICK='window.flag.off();' TARGET='cart-frame'><IMG SRC='flag.gif' BORDER=0></A>";
	window.flag.on();



// peeping boys
	window.boy_peep=new Peep('boy-peep');
	window.girl_peep=new Peep('girl-peep');
}


function getEl(evt)
{
	var event = (evt)?evt:(window.event)?window.event:'';
	var el=event.target || event.srcElement;
	return el;
}

function catalogPopup(evt)
{
	//kill prev pop
	if(typeof(window.pop_pane)!='undefined' && window.pop_pane) {
		window.pop_pane.off();
		window.pop_pane=null;
		}

	var event = (evt)?evt:(window.event)?window.event:'';
	var el=event.target || event.srcElement;

	while(el && (el.tagName ? el.tagName : el.nodeName) !='SPAN') el=el.parentNode;
	if(!el) return;

	window.pop_pane=new popPane(el,500,460,function(code){
			var newcode='';
			code.replace(/<IMG.*?NAME=["']?item-big-pic["']?.*?>/igm,function(str, p1, p2, offset, s){ newcode=str; });
			newcode=newcode.replace(/WIDTH=150/gi,'');
			newcode="<A HREF='javascript:void(0);' ONCLICK='window.pop_pane.off();window.pop_pane=null;'>"+newcode+"</A>";

			var namecode='';
			code.replace(/<FONT.*?CLASS=["']?shop-name["']?.*?>.*?<\/FONT>/igm,function(str, p1, p2, offset, s){ namecode=str; });

			var pipka="<DIV STYLE='position:absolute;right:6px;top:0px;'><A STYLE='font-family:Arial;text-decoration:none;font-size:20px;' HREF='javascript:void(0);' ONCLICK='window.pop_pane.off();window.pop_pane=null;'>X</A></DIV>";

			code=namecode+"<CENTER>"+pipka+newcode+"</CENTER>";
			return code;
		},
		function(node,progr){
			if(node.name=='item-big-pic') {
				if(progr>=LIMIT-1) node.removeAttribute('width');
				else node.width=150+progr*12;
				}
		});
}
