var IE = document.all?true : false;
var highlight;
var scroll_delay = 2500;
var command_id = 0;

/*         ___
 *        /  /
 *       /__/
 *      ___________   _______    _______   ________
 *     /     __   /| /  __  /|  /  __  /| /  __   /|
 *    /  /  /_/  / //  /_/ / / /  / / / //  /_/  / /
 *   /  /  _____/ //     _/ / /  / / / //  _____/ /
 *  /  /  /|____|//  /\  \|/ /  /_/ / //  /|____|/
 * /_____/ /     /__/ /\__\ /______/ //__/ /
 * |_____|/      |__|/ |__| |______|/ |__|/ services
 *                                    
 *
 *      http://www.ipropservices.com
 */

////////////////////////////////////////////////////CONTAINER////////////////////////////////////////////
var started = false
var image_container = new Class({
	initialize : function(_args){
		this.img = _args[0];
		this.frame = _args[1];
		this.img.addEvent('click',_args[2]);
		this.img.injectInside(this.frame);
		this.img.addEvent('mouseenter',function(e){
			e = new Event(e).stop();
			this.img.setStyle('border-color','#586cfe');
			if(document.all){
				kar0us3l.tips.hide.delay(2500,kar0us3l.tips);
				this.img.setStyle.delay(2500,this.img,['border-color','#FFFFFF']);
			}
		}.bind(this));
		this.img.addEvent('mouseleave',function(e){
			e = new Event(e).stop();
			this.img.setStyle('border-color','#FFFFFF');
			
		}.bind(this));
		if(kar0us3l.containers.length > kar0us3l.images.length-10 && !started){
			kar0us3l.start_fx();
			started = true;
		}
	},
	shuffle : function(end_l){
		this.img.injectInside(this.frame);
		kar0us3l.car_frame.scrollLeft = 5;
	}
});

//////////////////////////////////////////////////INITIALIZATION///////////////////////////////////////
var kar0us3l = {
	init : function(car_frame,images,functions,tips){
		this.active;
		var i = images.length;
	  	if ( i == 0 ) return false;
	  	while ( --i ) {
	   		var j = Math.floor( Math.random() * ( i + 1 ) );
	     	var tempi = images[i];
	     	var tempj = images[j];
	     	images[i] = tempj;
	     	images[j] = tempi;
	   	}
		this.images = images;
		this.functions = functions;
		this.car_frame = car_frame;
		this.containers = []
		var counter = 0;
		this.j = 1;
		this.scroll_fx = new Fx.Scroll(car_frame,{
			duration:0,
			wait:false,
			transition:Fx.Transitions.linear,
			onComplete : function(){
				counter++;
				if(counter >= this.images.length-10){
					$('indicator').remove();
					car_frame.effect('opacity',{duration:500,wait:false}).start(1);
					this.scroll_fx = new Fx.Scroll(car_frame,{
						duration:scroll_delay,
						wait:false,
						transition:Fx.Transitions.linear,
						onComplete : this.next_effect.bind(kar0us3l)
					});
				}
				this.next_effect()
			}.bind(kar0us3l)
		});
		this.images.each(function(el,i){
			var _args = [el,this.car_frame,this.functions[el.getProperty('src')]];
			this.containers.extend([new image_container(_args)])
		}.bind(this))
		window.onmousewheel = document.onmousewheel = function(e){
			e = new Event(e).stop();
			kar0us3l.scroll_fx.toElement.delay(100,kar0us3l.scroll_fx,kar0us3l.containers[kar0us3l.j].img)
		}
		window.addEvent('mousewheel',function(e){
			e = new Event(e).stop();
			kar0us3l.scroll_fx.toElement(kar0us3l.containers[kar0us3l.j].img)
		});
		this.car_frame.addEvent('mousemove',function(e){
			e = new Event(e).stop();
			return;
		});
		this.tips = new Tips($$('.toolTipImg'));
	},
	start_fx : function(){
		this.scroll_fx.toElement(this.car_frame.getElements('img')[1]);
	},
	next_effect : function(){
		if(this.j == 0){
			this.containers[this.containers.length-1].shuffle();
		}else{
			this.containers[this.j-1].shuffle();
		}
		if(this.j == this.containers.length-1){
			this.scroll_fx.toElement(this.containers[0].img);
			this.j = 0;
		}else{
			this.scroll_fx.toElement(this.containers[this.j+1].img);
			this.j++;
		}
	}
}