// JavaScript Document

var t="";
var elem_photo;
var elem_photodiv;
var elem_mapheader;
var mm1=0;
var mm2=0;
var nnn=0;
var isIE=0;
var arrHistoryIds=new Array();
var arrHistoryTexts=new Array();
var imgs = new Array();

function setLastPosition(imgId, headText)
{

	if(arrHistoryIds.length>0)
	{
		if( (arrHistoryIds[(arrHistoryIds.length-1)]!=imgId) || (arrHistoryTexts[(arrHistoryIds.length-1)] != headText) )
		{
			arrHistoryIds[arrHistoryIds.length]=imgId;
			arrHistoryTexts[arrHistoryIds.length]=headText;
		}
	}
	else
	{
		arrHistoryIds[0]=imgId;
		arrHistoryTexts[0]=headText;
	}
	
}

function goToLastPosition()
{
	if( (arrHistoryIds.length>2) && (arrHistoryTexts.length>2) )
	{
		if(arrHistoryTexts[arrHistoryTexts.length-2].length>0)
		{
			LoadPhoto(arrHistoryIds[(arrHistoryIds.length-2)], 100, 0, arrHistoryTexts[(arrHistoryTexts.length-2)]);
		}
	}
}

function init_photochanger(lm_photo, lm_photodiv, lm_mapheader, lm_perehod)
{
	if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5)
	{
		isIE=1;
		elem_photo=document.all[lm_photo];
		elem_photodiv=document.all[lm_photodiv];
		elem_mapheader=document.all[lm_mapheader];
		elem_perehod=document.all[lm_perehod];
	}
	else
	{
		elem_photo=document.getElementById(lm_photo);
		elem_photodiv=document.getElementById(lm_photodiv);	
		elem_mapheader=document.getElementById(lm_mapheader);
		elem_perehod=document.getElementById(lm_perehod);			​
	}
	arrHistoryIds[0]=0;
	arrHistoryTexts[0]='0';
}


function setMapHead(hText)
{elem_mapheader.innerHTML=hText;}


function LoadPhoto(num, m1, m2, headText)
{
	nnn=num;
	mm1=m1;
	
	if(mm1==0)
	{
		mm2=m2+5;	
	}
	else
	{
		mm1=m1-5;
		mm2=0;
	}

	if(mm1>=95)
	{
		setLastPosition(nnn, headText);
		setMapHead(headText);
		FocusOnElement();
	}
	
	if(mm1==0)
	{
		elem_photo.src=imgs[nnn].src;
		if(mm2>=100)
		{	
			clearTimeout(t);
	    	t="";
		}
		else
		{
			setElementOpacity(elem_photodiv, mm2/100);
			setElementOpacity(elem_photo, mm2/100);
			clearTimeout(t);
			t = setTimeout('LoadPhoto('+nnn+', '+mm1+', '+mm2+', '+"'"+headText+"'"+')', 50);
		}
	}
	else
	{
		setElementOpacity(elem_photodiv, mm1/100);
		setElementOpacity(elem_photo, mm1/100);		
		clearTimeout(t);
		t = setTimeout('LoadPhoto('+nnn+', '+mm1+', '+mm2+', '+"'"+headText+"'"+')', 50);
	}
}

function getAbsPos(p)
{
	var s = { x:0, y:0 };
    while (p.offsetParent)
	{
    	s.x += p.offsetLeft;
        s.y += p.offsetTop;
        p = p.offsetParent;
    }
    return s;
}

function FocusOnElement()
{
	lm=getAbsPos(elem_perehod);
	lm_top=lm.y;
	lm_left=lm.x;

	window.scroll(lm_left,lm_top);
}


function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}
