var draggableobj,dragx,dragy,tempdragx,tempdragy,dragapproved;

function rotateimage(elem,imagelist,descriptionlist,current,next)
{

current=parseInt(current);
imagearray=imagelist.split(",");
descriptionarray=descriptionlist.split("|");
imagelength=imagearray.length;
imagelength--;
elem.src=imagearray[current];
elem.alt=descriptionarray[current];
elem.title=descriptionarray[current];
if (next=='next') {
elem.parentNode.lastChild.firstChild.style.display='block';
if (current==imagelength)
{elem.parentNode.lastChild.lastChild.style.display='none';}
}
if (next=='previous') {
elem.parentNode.lastChild.lastChild.style.display='block';
if (current==0)
{elem.parentNode.lastChild.firstChild.style.display='none';}

}
current--;
return current;

}

function changesource(elem,newsrc)
{elem.src=newsrc;
return false;
}
function scrollelement(elem,direction)
{
if (direction=="stop") {clearTimeout(timescrollinterval);}
else {
stopscroll=false;
upelem=elem.parentNode;
scrollspeed=6;
newscroll=parseInt(direction,10);
if (!isNaN(newscroll))
{if (newscroll>0) {direction="up";} else {direction="down";}
scrollspeed=Math.abs(newscroll);
stopscroll=true;
}
elemheight=getHeight(elem);
elemheight=parseInt(elemheight,10);
elemtop=(elem.style.top)?elem.style.top:elem.style.pixelTop;
elemtop=parseInt(elemtop,10);
upelemheight=getHeight(upelem);
upelemheight=parseInt(upelemheight,10);
elem.style.display="block";
elem.style.visibility="visible";
if (direction=='up')
{
if (elemtop<0)
	      {elemtop+=scrollspeed;
	      if (elem.firstChild.id=='hole') {elem.firstChild.style.marginTop=eval(0-elemtop)+"px";}
	      if (elemtop>0) {elemtop=0;elem.firstChild.style.marginTop="0px";stopscroll=true;}
	} else {stopscroll=true;}
	} else
	{
	if ((elemheight+elemtop)>=upelemheight)
	{elemtop-=scrollspeed;
	if (elem.firstChild.id=='hole') {elem.firstChild.style.marginTop=eval(0-elemtop)+"px";}
	if ((elemheight+elemtop)<upelemheight) {elemtop=upelemheight-elemheight;stopscroll=true;}
					       } else {stopscroll=true;}
					       }
					       if (elem.style.top) {elem.style.top=elemtop;} else if (elem.style.pixelTop) {elem.style.pixelTop=elemtop;}
					       if (!stopscroll) {var timeoutFunc = function () {scrollelement(elem,direction);};timescrollinterval=setTimeout(timeoutFunc,75);}}
					       return false;
					       }
					       var newdiv,middiv,middivtimeout;
					       var temptimeout,middivtimeout;
					       
					       
					       function showimage(imsrc,description)
					       {
					       imsrc=imsrc.replace('small','');
					       imsrc=imsrc.replace('medium','');
					       image_1 = new Image();
					       image_1.src = imsrc;
					       xwidth=700;
					       xheight=500;
					       xwindow=getInsideWindowWidth();
					       xwindow-=xwidth;
					       xwindow=xwindow/2;
					       ywindow=getInsideWindowHeight();
					       ywindow-=xheight;
					       ywindow=ywindow/2;
					       xwindow=Math.round(xwindow);
					       ywindow=Math.round(ywindow);
					       if (xwindow<10) {xwindow=10;}
							       if (ywindow<10) {ywindow=10;}
									       newdiv=document.createElement('div');
									       newdiv.style.border="2px solid #137CAE";
									       newdiv.style.left=xwindow;
									       newdiv.style.top=ywindow;
									       newdiv.style.display='block';
									       newdiv.style.position='absolute';
									       newdiv.style.zIndex=50+menuindex;
									       newimg=document.createElement('img');
									       newimg.src=image_1.src;
									       newimg.alt=description;
									       newimg.title=description;
									       newdiv.style.width=xwidth;
									       newdiv.style.height=xheight+18;
									       subdiv=document.createElement('div');
									       subdiv.style.width=xwidth;
									       subdiv.style.height=18;
									       subdiv.style.display="block";
									       subdiv.style.backgroundColor="#32ABE3";
									       subdiv.style.borderBottom="2px solid #137CAE";
									       subdiv.onmousedown=drags;
									       subdiv.style.cursor="hand";
									       subdiv.style.fontWeight="bold";
									       subdiv.style.color='white';
									       newdiv.style.backgroundColor="#FFFFFF";
									       newdiv.appendChild(subdiv);
									       newdiv.appendChild(newimg);
									       document.body.appendChild(newdiv);
									       subdiv.innerHTML+=description+"<a href='#' class='close' style='position:absolute;top:0px;right:0px;display:block;text-decoration:none;max-width:18px;cursor:hand' onclick=\"this.parentNode.parentNode.style.display='none';return false\" onmouseover=this.firstChild.src='images/site/sclose2.gif' onmouseout=this.firstChild.src='images/site/sclose.gif'><img src='images/site/sclose.gif' style='border:0px' /></a>";
									       tempfunction=function () {newdiv.style.width=image_1.width;newdiv.style.height=image_1.height+18;subdiv.style.width=image_1.width;}
									       image_1.onload=tempfunction;
									       }
									       
									       function showelement(id,type,xwidth,xheight,evt)
									       {
									       xwindow=getInsideWindowWidth();
									       xwindow-=xwidth;
									       xwindow=xwindow/2;
									       ywindow=getInsideWindowHeight();
									       ywindow-=xheight;
									       ywindow=ywindow/2;
									       xwindow=Math.round(xwindow);
									       ywindow=Math.round(ywindow);
									       if (xwindow<10) {xwindow=10;}
										if (ywindow<10) {ywindow=10;}
										newdiv=document.createElement('div');
										subdiv=document.createElement('div');
										middiv=document.createElement('div');
										postdiv=document.createElement('div');
										newdiv.style.border="2px solid";
										newdiv.style.borderColor="#137CAE";
										newdiv.style.backgroundColor="white";
										subdiv.style.width=xwidth;
										subdiv.style.height=20;
										postdiv.style.width=xwidth;
										postdiv.style.height=20;
										writestr="<table width='100%'><tbody><tr><td width='33%'><a href='#' class='close' style='margin-right:2em;display:block;max-width:6em;cursor:hand;' onclick=\"this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display='none';return false\" onmouseover=this.firstChild.src='images/site/sclose2.gif' onmouseout=this.firstChild.src='images/site/sclose.gif' ><img src='images/site/sclose.gif' style='cursor:hand;border:0px;margin-right:0.5em;vertical-align:middle' />Закрыть</a></td><td  width='33%'><a href='loadcontent.php?id="+id+"&global=1&menuindex="+menuindex+"&type="+type+"' class='close' target='_blank' style=margin-right:2em;display:block;max-width:12em;cursor:hand;' onmouseover=this.firstChild.src='images/site/vid2.gif' onmouseout=this.firstChild.src='images/site/vid.gif' ><img src='images/site/vid.gif' style='cursor:hand;border:0px;margin-right:0.5em;vertical-align:middle' />Подробнее</a></td>";
										if ((type=='hotel')||(type=='resthome')||(type=='sanatorium')) {writestr+="<td><a href='#' class='close' style='float:left;display:block;max-width:12em;cursor:hand;' onclick=\"showelement("+id+",'"+type+"reply',"+xwidth+","+xheight+")\" onmouseover=this.firstChild.src='images/site/otz2.gif' onmouseout=this.firstChild.src='images/site/otz.gif' ><img src='images/site/otz.gif' style='cursor:hand;border:0px;margin-right:0.5em;vertical-align:middle' />Оставить отзыв</a></td></tr></tbody></table>";} else {
										writestr+="</tr></tbody></table>";}
										postdiv.innerHTML=writestr;
										subdiv.onmousedown=drags;
										subdiv.style.backgroundColor="#32ABE3";
										subdiv.style.borderBottom="2px solid #137CAE";
										subdiv.style.position='relative';
										newdiv.style.left=xwindow;
										newdiv.style.top=ywindow;
										newdiv.style.display='block';
										newdiv.style.position='absolute';
										menuindex++;
										newdiv.style.zIndex=20+parseInt(menuindex,10);
										if ((type=='hotel')||(type=='resthome')||(type=='sanatorium')||(type=='article')||(type=='guide')) {newdiv.style.zIndex=22+parseInt(menuindex,10);}
										if ((type=='hotelreply')||(type=='gallery')) {newdiv.style.zIndex=24+parseInt(menuindex,10);}
										newdiv.onclick=function () {menuindex++;this.style.zIndex=20+parseInt(menuindex,10);}
										middiv.style.width=xwidth;
										middiv.style.height=xheight;
										middiv.innerHTML="Идет загрузка.....";
										newdiv.appendChild(subdiv);
										newdiv.appendChild(middiv);
										newdiv.appendChild(postdiv);
										document.body.appendChild(newdiv);
										subdiv.innerHTML+="<a href='#' class='close' style='position:absolute;top:0px;right:0px' onclick=\"this.parentNode.parentNode.style.display='none';return false\" onmouseover=this.firstChild.src='images/site/sclose2.gif' onmouseout=this.firstChild.src='images/site/sclose.gif'><img src='images/site/sclose.gif' style='border:0px' /></a>";
										postdiv.innerHTML+="<iframe name='loadcontent"+menuindex+"' id='loadcontent"+menuindex+"' src='loadcontent.php?id="+id+"&global=0&menuindex="+menuindex+"&type="+type+"&width="+xwidth+"&height="+xheight+"' onload=movecontent(this.parentNode.parentNode.childNodes[1],'loadcontent"+menuindex+"') style='width:0px;height:0px;border:0px;left:0px;top:0px;position:absolute'></iframe>";
										middivtimeout=setTimeout("movecontent(middiv,'loadcontent"+menuindex+"')",10000);
										return false;
										}
										
										function movecontent(toelem,fromelem)
										{clearTimeout(middivtimeout);
										if (toelem) {toelem.innerHTML=eval(fromelem).document.body.innerHTML;}
										}
										
										document.onmouseup=function () {dragapproved=false;}
										
										var dragapproved=false;
										var z,tempx,tempy;
										var timescrollinterval;
										
										function move(e){
										if (dragapproved){
										evt=(e)?e:((window.event)?window.event:null);
										X = parseInt((evt.clientX)?evt.clientX:evt.pageX,10);
										Y = parseInt((evt.clientY)?evt.clientY:evt.pageY,10);
										temporaryx=parseInt(temp1,10)+parseInt(X,10)-parseInt(tempx,10);
										temporaryy=parseInt(temp2,10)+parseInt(Y,10)-parseInt(tempy,10);
										if (temporaryy<-5) {temporaryy=0;}
										if (temporaryx) {z.style.left=temporaryx;}
										if (temporaryy) {z.style.top=temporaryy;}
										z.style.visibility="visible";
										return false;
										}
										}
										
										function drags(e){
										evt=(e)?e:((window.event)?window.event:null);
										var firedobj=(evt.srcElement) ? evt.srcElement : evt.target;
										dragapproved=true;
										z=firedobj.parentNode;
										menuindex++;z.style.zIndex=20+parseInt(menuindex,10);
										temp1=parseInt(z.style.left+0);
										temp2=parseInt(z.style.top+0);
										tempx = parseInt((evt.clientX)?evt.clientX:evt.pageX,10);
										tempy = parseInt((evt.clientY)?evt.clientY:evt.pageY,10);
										document.onmousemove=move;
										}
										
										function highlightstars(elem,parent,type)
										{
										if (type=='fill')
										{
										for (i=0;i<5;i++)
										{
										writestr='';
										if (elem.parentNode.parentNode.childNodes[0].value<=i)
										{writestr='images/site/hover.gif';} else
										{writestr='images/site/yellow.gif';}
										parent.childNodes[i].src=writestr;
										if (parent.childNodes[i]==elem) 
										{
										break;}		
										}
										writestr='';
										switch (i)
										{case 0:writestr='Плохо';
										break;
										case 1:writestr='Так себе';
										break;
										case 2:writestr='Нормально';
										break;
										case 3:writestr='Здорово';
										break;
										case 4:writestr='Отлично!';
										break;
										}
										elem.parentNode.parentNode.parentNode.childNodes[2].innerHTML=writestr;
										}
										if (type=='clear')
										{
										for (i=0;i<5;i++)
										{writestr='';
										if (elem.parentNode.parentNode.childNodes[1].value<=i)
										{writestr='images/site/white.gif';} else
										{writestr='images/site/gray.gif';}
										parent.childNodes[i].src=writestr;
										}
										
										}
										}
										
										function setstars(elem)
										{writestr='images/site/yellow.gif';
										for (i=0;i<5;i++)
										{elem.parentNode.childNodes[i].src=writestr;
										if (elem.parentNode.childNodes[i]==elem) {
										writestr='';
										switch (i)
										{case 0:writestr='Плохо';
										break;
										case 1:writestr='Так себе';
										break;
										case 2:writestr='Нормально';
										break;
										case 3:writestr='Здорово';
										break;
										case 4:writestr='Отлично!';
										break;
										}
										
										elem.parentNode.parentNode.parentNode.childNodes[2].innerHTML=writestr;
										elem.parentNode.parentNode.childNodes[0].value=eval(i+1);
										writestr='images/site/white.gif';
										}}
										
										}
										
										function setallstars(elem,evt)
										{
										evt=(evt)?evt:((window.event)?window.event:null);
										tg = (evt.srcElement) ? evt.srcElement : evt.target;
										while (tg.className!='stars' && tg.nodeName != 'BODY' && tg.nodeName!='#document')
										{tg= tg.parentNode}
										if (tg.className != 'stars') return true;
										reltg = (evt.relatedTarget) ? evt.relatedTarget : evt.toElement;
										if (reltg) {while (reltg!=tg && reltg.nodeName!='BODY' && reltg.nodeName!='#document')
										{if (reltg) reltg= reltg.parentNode;}
										if (reltg==tg) return true;}
										for (i=0;i<5;i++)
										{writestr='';
										if (elem.parentNode.childNodes[0].value<=i)
										{writestr='images/site/white.gif';} else
										{writestr='images/site/yellow.gif';} // если клавиша нажата - заполнить следующим
										elem.childNodes[i].src=writestr;
										}
										writestr='';
										switch (parseInt(elem.parentNode.childNodes[0].value))
										{case 0:writestr='';
										break;
										case 1:writestr='Плохо';
										break;
										case 2:writestr='Так себе';
										break;
										case 3:writestr='Нормально';
										break;
										case 4:writestr='Здорово';
										break;
										case 5:writestr='Отлично!';
										break;
										}
										elem.parentNode.parentNode.childNodes[2].innerHTML=writestr;
										
										
}
