/*
Author/Autor: 
	Carlos Andres Caballero Pino, Panama   2007
	version 2.0 2007
*/
var jsFX={
	fadeRefresh:30,
	init:function(){
		_(document.body);
		//setup FX objects
		if(window._ui){
			var wall=jsUIEventListener(document.createElement(jsLib.browserInfo.isBrowser('MSIE 6')?'iframe':'div'));
			this._wall_ptr=wall;		
			wall.setAttribute('scrolling','no');
			wall.setAttribute('frameborder','0');
			document.body.appendChild(wall);
			wall.setStyle({
						  'backgroundColor':'#000000',
						  'overflow':'hidden',
						  'top':'0px','left':'0px','border':0,
						  'position':'absolute','display':'none',
						  'width':(jsLib.window.resolution.x()+25)+'px',   //+25 to fix scroolbar size on safari
						  'height':(jsLib.window.resolution.y()+25)+'px'
						  }).setOpacity(jsLib.browserInfo.isBrowser('MSIE 6')?0:75);
			
			wall._kill_scrollbar=function(){
				if(jsLib.browserInfo.isBrowser('MSIE')){				
					document._old_padding=document.body.getStyle('paddingRight');
					document.body.setStyle('paddingRight','25px')  //fix scroolbar
					jsObject(document.getElementsByTagName('html')[0]).setStyle({
																				'overflow':'visible'																				
																				});
					document.body.setStyle('overflow','hidden')
	
					this.hack.setStyle('display','');
				}else{
					document.body.setStyle('overflow','hidden')
				}
				return true;
			}
			wall._enable_scroolbar=function(){
				document.body.setStyle('overflow','auto')
				if(jsLib.browserInfo.isBrowser('MSIE')){
					document.body.setStyle('paddingRight',document._old_padding)  //fix scroolbar
					jsObject(document.getElementsByTagName('html')[0]).setStyle({
																				'overflow':'scroll'
																				});
				}
				if(this.hack) this.hack.setStyle('display','none');
				return true;
			}		
			wall.uiEventAddListener('on_show','_kill_scrollbar',wall);
			wall.uiEventAddListener('on_hide','_enable_scroolbar',wall);
			
			if(jsLib.browserInfo.isBrowser('MSIE 6')){					
				wall.hack=jsObject(document.createElement('div'));
				wall.hack.frameBorder=0;
				wall._onorder=function(){
					this.hack.setStyle('zIndex',this.getStyle('zIndex')+1);
				}
				wall.uiEventAddListener('on_order','_onorder',wall);
				
				document.body.appendChild(wall.hack);
				
				wall.hack.setStyle({
						  'backgroundColor':'#000000',
						  'top':'0px',
						  'left':'0px',					
						  'position':'absolute',
						  'display':'none',
						  'width':(jsLib.window.resolution.x()+25)+'px',   //+25 to fix scroolbar size on safari
						  'height':(jsLib.window.resolution.y()+25)+'px'
						  }).setOpacity(75);
			}
		}
	},
	showWall:function(){
		return this._wall_ptr.show();
	},
	hideWall:function(){
		return this._wall_ptr.hide();
	},
	Table:{
		rowColorFromCell:function(cell,color){
			_(cell).getParent().setStyle('backgroundColor',color);
		}
	}
}
jsLib.onDomReady(function(){ jsFX.init()});

function jsImageSlider(name,target,imTime,pre_path,notify,notifyText){
	this.target=_(target);	
	this.notifyText=notifyText?notifyText:'image {cimg} of {total}';
	this.notify=_(notify);
	this.pre_path=pre_path;
	this.target_title=_(name+'_title');
	this.target_desc=_(name+'_description');
	this.name=name;
	this.images=new Array();
	this.imageTime=imTime;
	this.current=0;
	this.paused=false;
	this._timer=null;
	this.onUpdate=null;
	this.clearAll=function(){
		delete this.images;
		window.clearTimeout(this._timer);
		this.images=new Array();
	}
	this.onBeforeUpdate=null;
	if(this.target){		
		this.target.driver=this;
		this.target.onload=function(){
			if(!this.driver.paused){
				var dtg=this.driver;
				window.clearTimeout(this.driver._timer);
				this.driver._timer=setTimeout(function(){dtg.Next()},this.driver.imageTime);
			}
		}
	}
	this.addImage=function(url,title,desc,onclick){
		this.images.push([url,title,desc,onclick]);	
	}
	this.updateInfo=function(idx){
		if(this.onBeforeUpdate){
			this.onBeforeUpdate(this);
		}
		if(this.notify){
			notifytext=this.notifyText.replace(/{cimg}/,idx+1);
			notifytext=notifytext.replace(/{total}/,this.images.length);
			this.notify.innerHTML=notifytext;
		}
		this.target.src=(this.pre_path?this.pre_path:'')+this.images[idx][0];

		this.target.org_src=this.images[idx][0];
		if(this.images[idx][3]){
			this.target.setStyle('cursor',document.all?'hand':'pointer');
			this.target.onclick=this.images[idx][3];		
		}else{
			this.target.setStyle('cursor','normal');
			this.target.onclick=null;
		}
		if(this.target_title){
			this.target_title.innerHTML=this.images[idx][1];
		}
		if(this.target_desc){
			this.target_desc.innerHTML=this.images[idx][2];
		}
		if(this.onUpdate){
			this.onUpdate(this);
		}
	}
	this.Pause=function(pause){
		this.paused=pause?true:false;
		if(this.paused){
			window.clearTimeout(this._timer);
		}
	}
	this.Next=function(pause){
		if(this.images.length>0){
			this.Pause(pause)
			this.updateInfo(this.current);			
			this.current++;
			if(this.current>(this.images.length-1)){
				this.current=0;
			}
		}else{
			this.target.setStyle('display','none');
		}
	}
	this.Prev=function(pause){
		if(this.images.length>0){
			this.Pause(pause)
			this.updateInfo(this.current);
			
			this.current--;
			if(this.current<0){
				this.current=this.images.length-1;
			}
		}else{
			this.target.setStyle('display','none');
		}
	}
	this.Go=function(id){
		if(this.images.length>0){
			if(id<0)  id=0;
			if(id>(this.images.length-1)){
				id=this.images.length-1;
			}
			this.Pause(true)
			this.current=id;
			this.updateInfo(this.current);			
		}else{
			this.target.setStyle('display','none');
		}
	}	
	this.Execute=function(){
		if(this.target){
			if(this.images.length>0){
				this.Next();
			}else{
				this.target.setStyle('display','none');
			}
		}
	}
	this.getList=function(){
		if(this.images.length>0){
			return this.images;
		}else{
			return null;
		}
	}
}

function jsFade(obj,alpha,step,show,onFinish,fade_limit){
	var target=_(obj);
	target._fade_limit=fade_limit?fade_limit:100;
	if(onFinish){
		target.onFadeFinish=onFinish;		
	}
	_(target).setOpacity(alpha);
	target.current_alpha=alpha;
	if(show==true){
		if(alpha<target._fade_limit){
			alpha+=step;
			setTimeout(function(){jsFade(obj,alpha,step,true,null,fade_limit)},jsFX.fadeRefresh);
		}else{
			if(jsLib.isFunction(target.onFadeFinish)){
				target.onFadeFinish();
				target.onFadeFinish=null;
			}
		}
	}else{
		if(alpha>0){
			alpha-=step;
			setTimeout(function(){jsFade(obj,alpha,step,false)},jsFX.fadeRefresh);
		}else{
			if(jsLib.isFunction(target.onFadeFinish)){
				target.onFadeFinish();
				target.onFadeFinish=null;
			}
		}
	}	
}