/* 	public area scripts
 *	AIP Solutions Ltd'2005
 *	www.aip-solutions.com
 *	mod version : 0.8.1.0
 *	mod date	: 2005-12-01
 */

ns6=(document.all)? 0:1;
	
//dl.load.push('video.init();');

/* library functions */
evt=function(el,evt,obj){(ns6)?el.addEventListener(evt,obj,false):el.attachEvent('on'+evt,obj)}
noevt=function(el,evt,obj){(ns6)?el.removeEventListener(evt,obj,false):el.detachEvent('on'+evt,obj)}

/* debug functionality */
document.onkeyup=function(e)
{	if(!e) e=event;
	if(e.altKey&&e.ctrlKey&&e.keyCode==68)	// press Ctrl-Alt-D to visualize debug info
	{	log.push('--- dynlite log end ---');
		var err=log.join('<br>');
			err=err.replace(/#([^<]+)</gi,'<b class="debug"># $1</b><'); // status messages
			err=err.replace(/\!([^<]+)</gi,'<em class="debug">! $1</em><'); // error messages
		var el=obj("debug");
			el.innerHTML=err;
			el.on();
			el.onclick=function(){this.off()}
	}
};

/* div popup class */
function divPopup(id,cont,img)
{	this.id=id;
	this._img=new Image();
	this._contName=cont;
	this._imgName=img;
	this.cont=0;
	this.img=0;
}
/* div popup methods */
/* private */
_dp=divPopup.prototype;
_dp._show=function(pos)
{	if(this.time)
	{	clearTimeout(this.time);
	}
	this.img.src=this._img.src;
	this.cont.style.width=this._img.width;
	this.cont.style.height=this._img.height;

	(ns6)? this.cont.style.MozOpacity="1":this.cont.filters.alpha.opacity="100";
	setTimeout("obj('enlargeBottom').on()",450);
}
/* public */
_dp.show=function(src,pos)
{	if(!this.cont) this.cont=obj(this._contName);
	if(!this.img) this.img=obj(this._imgName);
	this._img.defsrc=this.img.getAttribute("defsrc",false);
	this._img.src=src+'B.jpg';
	this._img.onload=function(){dp._show(pos)};
	this.time=setTimeout("dp._show()",100);
	obj('enlargeBottom').off();
	this._selectable('on');
	this.cont.on();
	posY=pos.offsetTop+this._img.height+100
	contY=obj('content').offsetHeight;
	this.cont.style.top=(posY>contY)?pos.offsetTop-220:pos.offsetTop;
	//if(ns6) this.cont.addEventListener('mousedown',dp.drag,false);
}
_dp._selectable=function(mode)
{	if(document.all)
		for(i in document.all)
			document.all[i].unselectable=mode;
}

_dp.close=function()
{	this.cont.off();
	this.img.src=this._img.defsrc;
	(ns6)? this.cont.style.MozOpacity=".7":this.cont.filters.alpha.opacity="70";
	this._selectable('off');
}
_dp.drag=function(e)
{	if(!ns6) e=event;
	this.offsetY=e.clientY-this.cont.offsetTop;
	this.offsetX=e.clientX-this.cont.offsetLeft;
	evt(document,'mousemove',dp_move);
	evt(document,'mouseup',dp_stop);
}
function dp_move(e)
{	if(!ns6) e=event;
	dp.cont.style.top=e.clientY-dp.offsetY;
	dp.cont.style.left=e.clientX-dp.offsetX;
}
function dp_stop(e)
{	noevt(document,'mousemove',dp_move);
}

/* static object creation */
dp=new divPopup('dp','enlarge','enlargePic');

/* tabs */
var oldVar=1;
function tab(newVar)
{	obj('tabButton'+oldVar).on();
	obj('tabButtonA'+oldVar).off();
	obj('tab'+oldVar).off();
	obj('tabButtonA'+newVar).on();
	obj('tabButton'+newVar).off();
	obj('tab'+newVar).on();
	//alert(oldVar+'->'+newVar)
	oldVar=newVar;
}

/* randdom img - fade*/
var filterStep=(ns6)?(5/100):5;
var filterMax=(ns6)?1:100;
var mozOp=0;
var clr=null;
var clrTime=0;
var currEl=0;
var randNum=0;

function chngImg()
{	nextEl=randNum;
	while (nextEl==randNum)
		nextEl=Math.floor(Math.random()*5);
	randNum=nextEl;
	img=document.getElementsByTagName('IMG')
	for(i in img)
		if(img[i].id && img[i].getAttribute('el')=='yes')
			currEl=img[i].id.replace(/middleLeftBanner/, "");
	fade();
}
function fade()
{	filtrCurrEl=(ns6)?obj("middleLeftBanner"+currEl).style.MozOpacity:obj("middleLeftBanner"+currEl).filters.alpha.opacity;
	filtrnextEl=(ns6)?obj("middleLeftBanner"+nextEl).style.MozOpacity:obj("middleLeftBanner"+nextEl).filters.alpha.opacity;
	clrTime=setTimeout('fade()',40);
	if(filtrCurrEl>0)
	{	if(ns6)obj("middleLeftBanner"+currEl).style.MozOpacity-=filterStep;
		else obj("middleLeftBanner"+currEl).filters.alpha.opacity-=filterStep;
	}
	else
	{	obj("middleLeftBanner"+currEl).style.display="none";
		obj("middleLeftBanner"+currEl).setAttribute('el','no');
	}
	obj("middleLeftBanner"+nextEl).style.display="block";
	obj("middleLeftBanner"+nextEl).setAttribute('el','yes')
	if(filtrnextEl<filterMax)
	{	if(ns6)
		{	mozOp+=filterStep;
			obj("middleLeftBanner"+nextEl).style.MozOpacity=mozOp;
		}
		else obj("middleLeftBanner"+nextEl).filters.alpha.opacity+=filterStep;
	}
	else
	{	mozOp=0;
		clearTimeout(clrTime)
	}
}

/* home page video funcionality */
video = {vid:'videoId', v:null, hid:'videoHead', head:null, fid:'videoFoot', foot:null, tmbs:[], scrlId:'scrlH', flashid:'videoFlashId', curr:0}
video.init = function(){
	this.v = dl.el(this.vid);
	this.head = dl.fx.el(this.hid);
	this.foot = dl.fx.el(this.fid);
	this.tmbs = this.foot.getElementsByTagName('IMG');
	//creating logical elemen.ts
	for(var i=0; i<this.tmbs.length; i++){
		this.tmbs[i].big = new Image(); 
  		this.tmbs[i].big.src = this.tmbs[i].src.replace(/Small/,'Big');
		if(this.curr==i){
			this.tmbs[i].big.onload=function(){ video.change(video.curr); }
			//IE:
			if(dl.is.ie && this.tmbs[i].big.complete)
				this.tmbs[i].big.onload();
		}
  		this.tmbs[i].parentNode.onclick=function(){ video.change(this.id.replace(/foot/,'')); }
	}
	//over efect
	dl.el(this.flashid).onmouseover=function(){ 
		video.head.fade(0);
		video.foot.fade(0);
	}
	//out efect
	dl.el(this.flashid).onmouseout=function(){
		video.head.fade(1);
		video.foot.fade(1);
	}
	
	if(this.foot.offsetWidth<dl.el(this.scrlId).scrollWidth)
		this.setScroll();
}
video.change = function(currId){//src,background,idNum
	var el = dl.el('foot'+currId);
	var background = this.tmbs[currId].big.src;//el.getElementsByTagName('img')[0].src.replace(/Small/,'Big');
	var title = this.tmbs[currId].title;
	var src = el.getAttribute('vsrc')||0;
	var flashBackground = dl.fx.el(this.flashid);
	
	if(this.curr!=currId){
		dl.el('head'+this.curr).off();
		dl.el('foot'+this.curr).className='';
		this.curr=currId;
	}

	flashBackground.fade(0);
	flashBackground.style.backgroundImage = "url('"+background+"')";
	flashBackground.title = title;
	flashBackground.opacity(0);
	//flashBackground.on();
	flashBackground.fade(1);
	
	dl.el('head'+this.curr).on();
	dl.el('foot'+this.curr).className='active';
	
	if(!dl.is.ie&&this.v){
		if(src) this.v.setAttribute('src',src);
		if(background) this.v.setAttribute('poster',background);
		this.v.load();
		this.v.play();
	}
}
video.setScroll = function(){
	this.foot.arrR=dl.dom.el('DIV', this.foot);
	this.foot.arrR.innerHTML='&gt;';
	this.foot.arrR.className='arrR';
	this.foot.arrL=dl.dom.el('DIV', this.foot);
	this.foot.arrL.innerHTML='&lt;';
	this.foot.arrL.className='arrL';
	this.foot.arrR.onmouseover = function(){ video.scrlOn(5); };
	this.foot.arrL.onmouseover = function(){ video.scrlOn(-5); };
	this.foot.arrR.onmouseout = this.foot.arrL.onmouseout = function(){ video.scrlOff(); };
}
video.scrlOn = function(i){
	var _this=this;
	step=i;
	_this.foot.timer = setInterval(function(){dl.el(_this.scrlId).scrollLeft+=step;},50);
}
video.scrlOff = function(){
	var _this=this;
	if (_this.foot.timer) clearInterval(_this.foot.timer);
}


