var maxw=300;
var begindex=1000;
function genDiv(x,y,w,h,id,inh)
{
	var mdiv = document.createElement("div");
	mdiv.setAttribute("id",id);
	mdiv.setAttribute("class","elemdiv");
	mdiv.className="elemdiv";
	mdiv.style.zindex=begindex;
	mdiv.style.top=y+'px';
	mdiv.style.left=x+'px';	
	mdiv.style.width=w+'px';
	mdiv.style.height=h+'px';		
	document.body.appendChild(mdiv);
	mdiv.innerHTML=inh;
	return(mdiv);
}


function flipper(id,increment)
{
	increment=increment/2;
	if (increment<6)increment=6
	incr=increment;
	upper=document.getElementById('upperimg'+id);
	divs=document.getElementById('upperdiv'+id);
//	alert(divs);
	w=GetWidth(upper);
	h=GetHeight(upper);
	poss=findPos(divs);
	w+=incr;
	h+=incr;
	xx=poss[0]-incr/2;
	yy=poss[1]-incr/2;
	divs.style.left=xx+'px';
	divs.style.top=yy+'px';
	upper.style.width=w+'px';
	upper.style.height=h+'px';	
	divs.style.width=(w+1)+'px';
	divs.style.height=(h+1)+'px';	
	if (w<maxw) setTimeout("flipper("+id+","+increment+")",20);
	
}

function flipup(id,addr)
{
	$(".elemdiv").each(function (i) {
		if(this.id!=('upperdiv'+id)) {flipdn2(this.id);}
    });
	img=document.getElementById('resimg'+id);
	minx=GetWidth(img);
	miny=GetHeight(img);
	poss=findPos(img);
	posx=poss[0];
	posy=poss[1];
	genDiv(posx,posy,minx,miny,'upperdiv'+id,"<a href='"+addr+"'><img src='"+img.src+"' width="+minx+" height="+miny+" id='upperimg"+id+"' onmouseout='flipdn("+id+")'"); // 
	flipper(id,40);
}

function flipup2(id,addr)
{
	img=document.getElementById('resimg'+id);
	minx=GetWidth(img);
	miny=GetHeight(img);
	poss=findPos(img);
	posx=poss[0];
	posy=poss[1];
	genDiv(posx,posy,minx,miny,'upperdiv'+id,"<a href=\"#\" onclick=\"ch_til('"+addr+"')\"><img src=\""+img.src+"\" width="+minx+" height="+miny+" id=\"upperimg"+id+"\" onmouseout=\"flipdn("+id+")\"></a>");
	flipper(id,40);
}


function flipdn(id)
{
	rem_element('upperdiv'+id);
}
function flipdn2(id)
{
	rem_element(id);
}
