var gl_cuim = 0;
var offsetfrommouse=[15,0] 
var displayduration=0 

var defaultimageheight = 350;	
var defaultimagewidth = 195;	

var timer;


var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
var icount = 0;

var curpage = '';
var imgphp = '';
var width1 = '';
var width2 = '';

var swchim1  = new Image();
var swchim2  = new Image();
var swchim3  = new Image();

function setpage(pa, val){
	curpage = pa;
	imgphp = val;
	
	swchim1.src = imgphp+'swch1.gif';
	swchim2.src = imgphp+'swch2.gif';
	swchim3.src = imgphp+'swch3.gif';
	}


function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {

elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}


function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",1);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 

		
		newHTML = '<div class="border_preview" style="width:400px;height:200px;"><div id="prevhead"><strong>'+title+'</strong></div><div id="loader_container">загрузка</div>';
		
		
    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="'+ imagename + '" border="0"></div>';
		newHTML = newHTML + '</div></div>'; 
		
			

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth - 30; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth - 30; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;

		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

// 2


var ProjectTitle = ['Особняк', 'Здание Аппеляционного Суда', 'Галерея ИТИС-Киев', 'Аппартаменты', 'Административное здание, ТМ Шустов', 'Дом Галереи-ИТИС', 'Отель Отрада', 'Галерея ИТИС-дввери'];



function chbg(objid){
	obj = document.getElementById(objid)
	obj.style.backgroundColor = "#ededed";
}

function chbgb(objidb){
	obj = document.getElementById(objidb);
	 if (obj.className != 'on') {
	obj.style.backgroundColor = "#ffffff";}
}

function cchbg(di){
	di.style.backgroundColor = "#ededed";
}

function cchbgb(di){
	 if (di.className != 'onm') {
	di.style.backgroundColor = "#ffffff";}
}

function setcontact(fi, nu){
	for ($i=1; $i<10; $i++){
		var id = 'ofcom'+$i;
		if (document.getElementById(id)) {
			document.getElementById(id).style.backgroundColor = "#ffffff";
			document.getElementById(id).className = '';
		}
	}
	
	fi.style.backgroundColor = "#ededed";
	fi.className = 'onm';
	
	document.getElementById('conimg1').src = imgphp+'off/'+nu+'.jpg';
	document.getElementById('conimg2').src = imgphp+'off/'+nu+'_big.jpg';
	}


function imgbg(pic){
	pic.style.borderLeft = "#EDEDED 10px solid";
	}

function imgbgb(pic, nu){
	var cpsub = document.getElementById('mainimgswch').src;
	var possub = cpsub.substring(cpsub.length - 6, cpsub.length - 5);
	
	if(nu != possub) {
	pic.style.borderLeft = "#ffffff 10px solid";}
	}
	
function swchover(pics){
	if (pics.src != swchim3.src){
	pics.src = swchim2.src;}
	}

function swchout(pics, nu){
	if (pics.src != swchim3.src){
	pics.src = swchim1.src;}
	}

function setfirst(){
	document.getElementById('im1').style.borderLeft = "#EDEDED 10px solid";
	}

function swchcl2(sm, nu, nu1,nu2){
	
	var imgpath;
	imgpath = imgphp+'news/1/'+nu+'_.jpg';
	imgpath = imgphp+nu1+'/'+nu2;
	
	var allin = 1;
		while(document.getElementById('im'+allin)) {
			var id = 'im'+allin;
			document.getElementById(id).style.borderLeft = "#FFFFFF 10px solid";
			allin++;
			}
	
	document.getElementById('loadercontainer2').style.visibility ='visible';
	newHTML = '<img src='+imgpath+' id="swchpiccont" onload="javascript:loadcomp2(this);" style="position:absolute; top:-1000px;">';
	document.getElementById("cconn").innerHTML = newHTML;
	document.getElementById('im'+nu).style.borderLeft = "#EDEDED 10px solid";

	}

function swchcl(pics, nu, pro, idp, pho){
	loaderf();
	gl_cuim = idp;
	var imgpathl;
	var projtit;
		var allin = 1;
		while(document.getElementById('swicher'+allin)) {
			var id = 'swicher'+allin;
			document.getElementById(id).src = swchim1.src;
			allin++;
			}
		
		
		
		var cid = 'swicher'+nu;
		document.getElementById(cid).src = swchim3.src;
	
	if (curpage == 'index' || curpage == '') {
			imgpath = imgphp+'proj/'+idp+'_'+pho+'.jpg';
			imgpathl = imgphp+'proj/'+idp+'_'+pho+'_big.jpg';
			projtit = ProjectTitle[(nu-1)];
			document.getElementById('projtitlcont').innerHTML = projtit;
		};

	if (curpage == 'project3') {
			imgpath = imgphp+'project/1/pr'+nu+'_.jpg';
			imgpathl = imgphp+'project/1/pr'+nu+'.jpg';
			};
			
			if(pro){
		imgpath = imgphp+'proj/'+idp+'_'+pho+'_big.jpg';
		imgpathl = imgphp+'proj/'+idp+'_'+pho+'.jpg';
		}
		

	newHTML = '<img src='+imgpath+' id="swchpiccont" onload="javascript:loadcomp(this, '+nu+');" style="position:absolute; top:-1000px;">';
	document.getElementById("cconn").innerHTML = newHTML;
	
	pics.src = swchim3.src;
	
	if(imgpathl){
		newHTML = '<img src='+imgpathl+' id="swchpiccontl" onload="javascript:loadcompl(this);" style="position:absolute; top:-1000px;">';
	document.getElementById("cconnl").innerHTML = newHTML;
		}
	}
	
function loadcomp(cupicas, nu){
	document.getElementById('mainimgswch').src = cupicas.src;
	document.getElementById('swicher'+nu).src = swchim3.src;
	loaderb();
	
	}	
	
function loadcomp2(cupicas){
	document.getElementById('loadercontainer2').style.visibility ='hidden';
	document.getElementById('mainimgswch').src = cupicas.src;
	
	}	
	
function loadcompl(cupicas){
	document.getElementById('mainimgswchl').src = cupicas.src;
	}	

function GotoProject(cuim){
	var curentpa = (document.getElementById('mainimgswch').src);
	var pos = curentpa.substring(curentpa.length - 6);
	var pagenumber = pos.substring(0, 1);
	//window.location.href = 'pro'+pagenumber+'.html';
	window.location.href = 'project/pro/'+gl_cuim;
	}

function loaderf(){
	timer = setInterval("move()", 5);
	}
	
function loaderb(){
	var obj = document.getElementById("projecttitle").style;
	var obj2 = document.getElementById("protitlred").style;
	
	icount = 135;
	 obj.width = 290+'px';
	 obj2.width = 10+'px';
	}


function move(){
	if (icount < 130){
	var obj = document.getElementById("projecttitle").style;
	var obj2 = document.getElementById("protitlred").style;
	
	 obj.width = 290 + icount+'px';
	 obj2.width = 10 + icount+'px';
	icount++;
	} else {clearInterval(timer);
			icount = 0;
				}
	}
	




	
