var cgc_exec=false;
var carosuel_height = 290;
var carosuel_width = 910;
var wait_for = 7000;
var opacity = 100;
var lock = false;
var cur_pic = 1;
var last_pic = 1;
var interval;
var tp = 3;
var lang;
var cur_links = new Array('products/KR-8','products/PR-500.2','products/BR-14');
var gw = 162;
var tt = false;

function loader() {
	if (document.getElementById('footer')!=null && cgc_exec=='yes') init();
	else setTimeout("loader()", 100);
}

function init() {
	var m, i;
	
	if (obj('carosuel')) {
		interval = setInterval("goMove()", wait_for);
		
		m=getElementsByClass('car_but',obj('car_but_holder'),'div');
		for(i=0;i<m.length;i++){
			m[i].onclick=clickPic;
		}
		obj('carosuel').href="/"+lang+"/"+cur_links[0]+"/";
	}
	
	if (obj('gallery')) {
		obj('gs_l').onclick = moveGallery;
		obj('gs_r').onclick = moveGallery;
	}
}
function obj(id) {
	return document.getElementById(id);
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null ) node = document;
	if ( tag == null ) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	for (i = 0,j = 0; i < elsLen; i++) {
		if ( els[i].className.indexOf(searchClass)!=-1 ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
/*
function showTooltip(e) {
	tt=true;
	obj('tooltip').innerHTML = this.childNodes[0].innerHTML;
	
	O = this;
	tempX = 0;
	do {
		tempX += O.offsetLeft;
	} while (O = O.offsetParent);
	
	tempX -= 82;

 	obj('tooltip').style.left=tempX+'px';
 	obj('tooltip').style.display='block';
}
function hideTooltip(e) {
	obj('tooltip').innerHTML ='';
	obj('tooltip').style.display='none';
	tt=false;
}
*/
function fP(x) {
	if (x>=100) return x;
	else if (x>=10) {
		if (x%10==0) return "0."+(x/10);
		else return "0."+x;
	}
	else if (x>0) return "0.0"+x;
	else return 0;
}

function fadeIn() {
	o = obj('carosuel');
	if (opacity<100) {
		opacity+=2;
		o.style.opacity = fP(opacity);
		o.filter= "alpha(opacity="+opacity+")";
		
		setTimeout("fadeIn()", 10);
	}
	else {
		lock = false;
	}
}
function fadeOut(w) {
	o = obj('carosuel');
	if (opacity>0) {
		opacity-=2;
		o.style.opacity = fP(opacity);
		o.filter= "alpha(opacity="+opacity+")";
		
		setTimeout("fadeOut("+w+")", 10);
	}
	else movePicture(w);
}
function movePicture(w) {
	obj('carosuel').style.backgroundPosition="0px -"+((w-1)*carosuel_height)+"px";
	fadeIn();
	last_pic=w;
}
function goMove(w) {
	if (!lock) {
		lock = true;
		if (!w)	{
			if (cur_pic<tp) cur_pic++;
			else cur_pic = 1;
		}
		else {
			cur_pic = w;
			clearInterval(interval);
			interval = setInterval("goMove()", wait_for);
		}
		obj('carosuel').href="/"+lang+"/"+cur_links[cur_pic-1]+"/";
		fadeOut(cur_pic);
	}
}
function clickPic(e) {
	if (!lock) {
		num = this.id.replace(/car_but_(\d)+/g, "$1")
		
		goMove(num);
	}
	return false;
}

function moveGallery(e) {
	var dir = (this.id == 'gs_l') ? -4 : 4;
	if (pushthat+gw*dir>0) {
		pushthat -= gwidth;
		obj('galsl').style.marginLeft=pushthat+'px';
	}
	if (pushthat+gw*dir<-3*gwidth+832) {
		pushthat += gwidth;
		obj('galsl').style.marginLeft=pushthat+'px';
	}
	
	galMove(1, gw*dir)
}

function galMove(stage, h) {
	switch (stage) {
		case 1:
		case 2:
		case 9:
		case 10:
			pushthat += h/18;
			break;
		case 3:
		case 4:
		case 7:
		case 8:
			pushthat += h/9;
			break;
		case 5:
		case 6:
			pushthat += h/6;
			break;
	}
	obj('galsl').style.marginLeft=pushthat+'px';
	if (stage==10) return false;
	setTimeout('galMove('+(stage+1)+','+h+')', 30);
}

function sendForm() {
	var req = new Array('fname','lname','mail','text');
	var errors = false;
	
	for(i=0;i<req.length;i++) {
		if (obj('cf_'+req[i]).value=='') {
			obj('cf_'+req[i]).className='error';
			obj('cf_'+req[i]).onfocus=function() { this.className=''; };
			obj('cf_'+req[i]).onclick=function() { this.className=''; };
			errors = true;
		}
	}
	
	if (!errors) document.contact.submit();
	return false;
}

loader();

