// events
function addmouseEvent( target, functionName ) 
{
    try {
            if ( Br.IE ) 		eval('target.onmouseleave=functionName');
            else                target.addEventListener( 'mouseout' , functionName , false );
        }
    catch(e) {}
}
function anim(Xmax, Ymax, Yimgmax, sClassnameTop, bEnabled )
{
    if (!Br.IE) Ymax = Ymax-7;
    var seval       = 'this.max={X:' + Xmax + ',Y:' + Ymax +'};';
    eval(seval);
    this.YmaxImg = Yimgmax; this.startPos = {X:20,Y:0};
    this.increase = {X:35,Y:40}; this.koef = 71/69;
    this.timer = null; this.timerfadeout = -1;
    this.timerStop = false; this.bCanResize = true;
    this.div = getE('animtemplate'); this.source     = null;
    this.classnameTop = sClassnameTop;
    
    this.name = ''; this.url = ''; this.desc = ''; this.price1 = ''; this.price2 = ''; this.price3 = ''; this.attribute  = '';
    this.image = ''; this.speed = 5; this.zoomStart  =true; this.opacity = {timer:-1,step:20}; this.Disabled = (bEnabled==0); this.tAutoClear = 0;
}
anim.prototype.Start = function(name, url, desc, price1, price2, price3, attribute, image, e)
{
    if (this.div == null) return false;
    this.source = (window.event)? window.event.srcElement : e.target;
    this.name = name; this.url  = url; this.desc = desc;
    this.price1 = price1; this.price2 = price2; this.price3 = price3;
    if (attribute != '') this.attribute = '/img/'+attribute;
    else                 this.attribute = '/imgadmin/empty.gif';
    this.image = image;
    this.init();
}
anim.prototype.Stop = function(e) { this.zoomStart = false; this.zoomOff(); }

anim.prototype.init = function()
{
    var src = this.source;
    this.zoomStart = true;
    clearTimeout(this.tAutoClear);
    this.tAutoClear = 0;   
    this.minimizeDiv();
    this.startPos.X = 50; this.startPos.Y = 7;
    while (src)
	{
		this.startPos.X += src.offsetLeft;
		this.startPos.Y += src.offsetTop;
		if (src.id == this.classnameTop) break;
		src = src.offsetParent;
	}
    if (getE('imgTmp'))        
    { 
        getE('imgTmp').src = this.source.src; getE('imgTmp').style.width = '0px'; getE('imgTmp').style.height = '0px'; getE('imgTmp').style.display = 'block';
        this.onStart();
    }
}

anim.prototype.onStart = function()
{
	this.div.style.left   = this.startPos.X + 'px'; this.div.style.top = this.startPos.Y + 'px';	
    this.div.style.width  = this.source.offsetParent.offsetWidth + 'px'; this.div.style.height = this.source.offsetParent.offsetHeight + 'px';
    this.div.style.width  = '0px';this.div.style.height  = '0px';
    if (getE('imgTmp'))             { getE('imgTmp').src=this.image;getE('imgTmp').height='0px';getE('imgTmp').width='0px'; getE('imgTmp').onload = ""; }     
    if (getE('productname'))        { getE('productname').innerHTML  = this.name; getE('productname').style.display='block'; } 
    if (getE('productattribute'))   { getE('productattribute').src = this.attribute; }
    if (getE('productattribute').src.toLowerCase() != '/imgadmin/empty.gif')   { getE('productattribute').style.display='block';} 
    if (getE('productdesc'))        { getE('productdesc').innerHTML  = this.desc; getE('productdesc').style.display='block'; } 
    if (getE('producturl'))         { getE('producturl').href  = this.url; getE('producturl').style.display='block'; } 
    if (getE('productprice1'))      { getE('productprice1').innerHTML = this.price1+' Kč'; getE('productprice1').style.display='block';} 
    if (getE('productprice2'))      { getE('productprice2').innerHTML = this.price2+' Kč'; getE('productprice2').style.display='block';} 
    if (getE('productprice3'))      { getE('productprice3').innerHTML = this.price3+' Kč'; getE('productprice3').style.display='block';} 
    if (Br.IE) {this.div.style.filter = 'alpha(Opacity="100")';} else if (Br.NS) {this.div.style.MozOpacity = 100;}
    this.div.style.display = 'block';
    this.timerStop  = false;
    this.zoomOn();
}
anim.prototype.zoomOn = function()
{
    if (cAnim==null) return false;
    var currsize = {X:0,Y:0};
    var imgsize  = {X:0,Y:0};
    Imageincrease   = {X:1,Y:10};
    currsize.X = this.div.offsetWidth; currsize.Y = this.div.offsetHeight;
    if (currsize.X + Math.round(this.increase.X) < this.max.X)     { currsize.X += Math.round(this.increase.X); }
    else                                                           { currsize.X  = Math.round(this.max.X); }
    this.div.style.width = currsize.X + 'px';
    if (currsize.Y + Math.round(this.increase.Y) < this.max.Y)     { currsize.Y += Math.round(this.increase.Y); }
    else                                                           { currsize.Y  = Math.round(this.max.Y); }
    this.div.style.height = currsize.Y + 'px';
    imgsize.Y = Math.round(getE('imgTmp').offsetHeight);
    if (imgsize.Y + Math.round(Imageincrease.Y) < this.YmaxImg)     { imgsize.Y += Math.round(Imageincrease.Y); }
    else                                                            { imgsize.Y  = this.YmaxImg; }
    imgsize.X  = 71;
    if (Math.round(imgsize.Y * this.koef) < imgsize.X)     { imgsize.X = Math.round(imgsize.Y * this.koef); }
    getE('imgTmp').style.width  = Math.abs(imgsize.X) + 'px';
    getE('imgTmp').style.height = Math.abs(imgsize.Y) + 'px';
    if (!this.timerStop && ( currsize.X < this.max.X || currsize.Y < this.max.Y || imgsize.X < 71 || imgsize.Y<this.YmaxImg )) { this.timer = setTimeout("cAnim.zoomOn()", this.speed); }
    else   { this.tAutoClear = setTimeout("cAnim.Stop(null)", 10000); }
 }
anim.prototype.zoomOff = function()
{
    this.timerStop=true;
    clearTimeout(this.timer);
    clearTimeout(this.tAutoClear);
    if (this.opacity.timer != -1 ) return;
    this.fadeout(this.opacity.step);
}
anim.prototype.fadeout = function(opacity)
{
    if (cAnim==null) return false;
    if (this.zoomStart) { clearTimeout(this.opacity.timer); this.opacity.timer = -1; return; }
    if (Br.IE) {this.div.style.filter = 'alpha(Opacity="'+Math.round(100 - opacity)+'")';}
    else       {this.div.style.MozOpacity = Math.round(100 - opacity);}
    opacity += this.opacity.step;
    if (opacity > 99) { clearTimeout(this.opacity.timer); this.opacity.timer = -1; this.minimizeDiv(); return; }
    this.opacity.timer =  setTimeout("cAnim.fadeout("+opacity+")", this.speed); 
}
anim.prototype.minimizeDiv = function()
{
    this.div.style.display= 'none';
    this.div.style.width='0px';this.div.style.height='0px';
    if (getE('imgTmp'))        { getE('imgTmp').src = '/imgadmin/empty.gif';}
    if (getE('imgTmp'))        { getE('imgTmp').style.display='none'; getE('imgTmp').style.width='0px'; getE('imgTmp').style.height='0px'; }     
    if (getE('productname'))   { getE('productname').style.display='none'; getE('productname').innerHTML='';   } 
    if (getE('productattribute'))   {getE('productattribute').src='/imgadmin/empty.gif';   } 
    if (getE('productattribute'))        { getE('productattribute').style.display='none'; }   
    if (getE('productdesc'))   { getE('productdesc').style.display='none'; getE('productdesc').innerHTML='';   } 
    
    if (getE('productprice1'))  { getE('productprice1').style.display='none'; getE('productprice1').innerHTML='';   } 
    if (getE('productprice2'))  { getE('productprice2').style.display='none'; getE('productprice2').innerHTML='';   } 
    if (getE('productprice3'))  { getE('productprice3').style.display='none'; getE('productprice3').innerHTML='';   } 
}



