	
	var $D = YAHOO.util.Dom;
	var $ = $D.get;
	var $E = YAHOO.util.Event;
	var $d = document;
	
	/* ----( NEWS TICKER )---- */
	
	var NewsTicker = function () {
	}
	NewsTicker.prototype.init = function () {
		this.news_items = $D.getElementsByClassName('teaser_news_item','div','teaser_news');
		for ( var i = 0 ; i < this.news_items.length ; i++ ) {
		}
		this.current_news_item = 0;
		$D.setStyle ( this.news_items [0] , 'display' , 'block' );
		var self = this; setInterval( function () { self.next(); } , 10000 );
	}
	NewsTicker.prototype.next = function () {
		
		var prev = this.news_items[this.current_news_item];
		this.current_news_item ++; if ( this.current_news_item == this.news_items.length ) this.current_news_item = 0;
		var next = this.news_items[this.current_news_item];
		
		if (prev) {
			var fade = new YAHOO.util.Anim( prev , { opacity: { to: 0 } }, .7, YAHOO.util.Easing.easeOut);
			fade.onComplete.subscribe( function () {
				$D.setStyle(prev,'display','none');
				$D.setStyle(prev,'opacity','1');
				$D.setStyle(next,'display','block');
			}); 
			fade.animate ();
		} else {
			$D.setStyle(next,'display','block');
		}
	}
	
	/* ----( INIT )---- */
	
	var newsTicker = new NewsTicker ();
		
	$E.on ( window , 'load' , function () {
		
		newsTicker.init();
		
		// ----( make lists hoverable for IE )----
		
		var els = $d.getElementsByTagName ('li');
		for ( var i = 0 ; i < els.length ; i++ ) {
			$E.on ( els[i] , 'mouseover' , function (ev,el) {
				$D.addClass ( el , 'hover' );
			} , els[i] );
			$E.on ( els[i] , 'mouseout' , function (ev,el) {
				$D.removeClass ( el , 'hover' );
			} , els[i] );
		}
	
		var els = $D.getElementsByClassName  ( 'newwindow' , 'a' );
		for ( var i = 0 ; i < els.length ; i++ ) {
			$E.on ( els[i] , 'click' , function (ev,el) {
				window.open (el.getAttribute('href'),'popup');
				$E.stopEvent (ev);
			} , els[i]);
		}
	
	} );
					
	ImageWindow = function ( el , userConfig ) {
		
		if ( ! userConfig ) userConfig = {};
		//userConfig.effect = {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5};
		userConfig.close = true;
		userConfig.visible = false;
		userConfig.constraintoviewport = true;
		userConfig.modal = true;
		userConfig.fixedcenter = true;
		userConfig.underlay = 'none';
		userConfig.zIndex = 99999;
		userConfig.width = '800px';
		//userConfig.height = '600px';
		
		if ( arguments.length > 0 ) ImageWindow.superclass.constructor.call ( this , el , userConfig );
	
	}
	
	YAHOO.extend ( ImageWindow , YAHOO.widget.Panel );
	
	ImageWindow.prototype.render = function ( appendToNode ) {
		
		/* render footer */
		if ( this.imageArray.length > 1 ) {
			var slider = document.createElement('div');
			slider.className = 'slider';
			for ( i = 0 ; i < this.imageArray.length ; i++ ) {
				var img = document.createElement('img');
				img.src = this.prependSmall + this.imageArray[i];
				img.large = this.prependSmall + this.imageArray[i];
				img.width = 80 ; img.height = 50;
				img.imgIndex = i;
				$E.on(img,'click',function (evt) {
					this.img.src = $E.getTarget(evt).large;
					this.currentImage = $E.getTarget(evt).imgIndex;
				},this,true)
				slider.appendChild (img);
				slider.style.left = 400 - ( (80*this.imageArray.length) /2 ) + 'px';
			}
			this.setFooter(slider);
			this.cfg.setProperty ('height','600px');
		} else {
			this.cfg.setProperty ('height','510px');
		}
		
		/* render body */
		this.img = document.createElement('img');
		this.img.id = 'img';
		this.img.src = this.prependLarge + this.imageArray[this.currentImage];
		$E.on(this.img,'click',function (evt) {
			if ( this.imageArray.length < 2 ) {
				this.hide();
			} else {
				this.currentImage ++;
				if ( this.currentImage == this.imageArray.length ) this.currentImage = 0;
				this.img.src = this.prependLarge + this.imageArray[this.currentImage];
			}
		},this,true),
		this.setBody(this.img);
		
		ImageWindow.superclass.render.call ( this , appendToNode );
	}
	ImageWindow.prototype.setImages = function ( imageArray , prependSmall , prependLarge , currentImage ) {
		if ( ! imageArray ) imageArray = [];
		if ( ! prependSmall ) prependSmall = '';
		if ( ! prependLarge ) prependLarge = '';
		if ( ! currentImage ) currentImage = 0;
		this.imageArray = imageArray;
		this.prependSmall = prependSmall;
		this.prependLarge = prependLarge;
		this.currentImage = currentImage;
	}
	
	LightBox = function ( el , userConfig ) {
		if ( arguments.length > 0 ) LightBox.superclass.constructor.call ( this , el , userConfig );
	}
	
	YAHOO.extend ( LightBox , YAHOO.widget.Panel );
	
	LightBox.prototype.show = function () {
		LightBox.superclass.show.call(this);
		this.setImage();
	}
	
	LightBox.prototype.setHeader = function (el) {
		var hd = $d.createElement('div');
		hd.style.padding = '0px 10px';
		hd.innerHTML = el;
		LightBox.superclass.setHeader.call(this,hd);
	}
	
	LightBox.prototype.init = function(el, userConfig) {
		LightBox.superclass.init.call(this, el); 
		
		this.beforeInitEvent.fire(LightBox);
		YAHOO.util.Dom.addClass(this.element, 'LightBox');
		
		if (userConfig) {
			this.cfg.setProperty('width','250px');
			this.cfg.setProperty('height','150px');
			this.cfg.setProperty('draggable',true);
			this.cfg.setProperty('zIndex',999999);
			this.cfg.applyConfig(userConfig, true);
		}
		
		this.img = $d.createElement('img');
		this.setBody(this.img);
		
		var ft = $d.createElement('div');
		ft.style.padding = '0px 10px';
		ft.style.textAlign = 'center';
		
		if ( this.cfg.getProperty("accparams") ) {
			
			$D.addClass(this.innerElement,'acc');
			this.cfg.setProperty('height','220px');
			
			var accparams = this.cfg.getProperty("accparams");
			
			ft.style.padding = '10px 10px';
			
			var desc = $d.createElement('div');
			$D.setStyle(desc,'textAlign','left');
			$D.setStyle(desc,'lineHeight','14px');
			desc.innerHTML = accparams.title + ' ' + accparams.description;
				
		/*	var accerror = $d.createElement('img');	
			accerror.src = '/images/accerror.png';
			accerror.style.verticalAlign = 'middle';
			accerror.style.display = 'none';
			this.accerror = accerror;
		*/		
			var accerror = $d.createElement('div');	
			accerror.innerHTML = accparams.lang == 'fr' ? 'choississez une option' : 'Kies een optie';
			accerror.style.display = 'none';
			accerror.style.color = '#CC0000';
			accerror.style.padding = '0px 0px 4px 2px';
			this.accerror = accerror;
				
			var right = $d.createElement('div');
			$D.setStyle(right,'float','right');
			$D.setStyle(right,'lineHeight','100%');
			$D.setStyle(right,'textAlign','left');
			$D.setStyle(right,'paddingLeft','10px');
			right.style.width = '150px';
			right.style.borderLeft = '1px solid silver';
			
			right.appendChild(accerror);
			
			if ( accparams.options.length > 0 ) {
				
				var select = $d.createElement('select');
				select.style.width = '150px';
				var option = $d.createElement('option');
				select.appendChild(option);
				option.innerHTML = accparams.lang == 'fr' ? 'choississez une option' : 'Kies een optie';
				for ( i in accparams.options ) {
					var option = $d.createElement('option');
					option.value = accparams.options[i].value;
					option.innerHTML = accparams.options[i].value + ' - ' + accparams.options[i].label;
					select.appendChild(option);
				}
				
				right.appendChild(select);
				right.appendChild($d.createElement('br'));
			}
			
			var btn = $d.createElement('img');
			btn.src = '/images/acccart.png';
			btn.style.cursor = 'pointer';
			btn.sel = select;
			btn.accid = accparams.id;
			btn.style.verticalAlign = 'middle';
			$E.on (btn,'click',function(evt){
				
				var sel = $E.getTarget(evt).sel;
				var val;
				if ( sel ) {
					
					if ( sel.selectedIndex == 0 ) {
						this.accerror.style.display = 'inline';
//						alert(accparams.lang == 'fr' ? 'choississez une option' : 'Kies een optie');
						return;
					}
					
					val = sel.options[sel.selectedIndex].value;
				} else {
					val = "";
				}
				
				var url = '/index.php/' + accparams.lang + '/accessoires/ajax/?id=' + $E.getTarget(evt).accid + '&opt=' + val + '&model=' + accparams.model;
				
				var callback =
				{
				  success: function(o) {
					eval ('var json = '+o.responseText +';');
					if (json.result == 1) {
						var div = $d.createElement('div');
						div.style.padding = '0px 10px 10px 10px';
						div.style.fontWeight = 'bold';
						div.style.color = '#cc0000';
						div.innerHTML = json.msg
						o.argument.setFooter(div);
						setTimeout(function(){
							o.argument.destroy();
						},1200);
					} else {
						alert('failure');
					}
				  },
				  failure: function(o) { alert('failure'); },
				  argument: this 
				}
				var transaction = YAHOO.util.Connect.asyncRequest('GET', url , callback);
				
				
			},this,true);
			
			right.appendChild(btn);
			
			ft.appendChild(right);
			ft.appendChild(desc);
			
		} else if ( this.cfg.getProperty("images") ) {
			
			var images = this.cfg.getProperty("images");
			
			if ( images.length > 1 ) {
			
				this.prev = $d.createElement('a'); this.prev.innerHTML = '<img src="/images/prev.png"/>';
				ft.appendChild(this.prev);
				$E.on (this.prev,'click',this.prevImage,this,true);
				
				this.next = $d.createElement('a'); this.next.innerHTML = '<img src="/images/next.png"/>';
				ft.appendChild(this.next);
				$E.on (this.next,'click',this.nextImage,this,true);
				
			}
			
		}
		
		this.setFooter(ft);
	//	console.log(this);
		
		this.loading = $d.createElement('img');
		this.loading.src = '/images/icon_small_waiting.gif';
		this.loading.className = 'loading';
		
		this.innerElement.appendChild(this.loading);
		
		this.initEvent.fire(LightBox);
		
	}
	
	LightBox.prototype.initDefaultConfig = function() {
		LightBox.superclass.initDefaultConfig.call(this);
		this.cfg.addProperty("images", { 
			handler:this.configImages, 
			suppressEvent:true 
		});
		this.cfg.addProperty("currentImage", { 
			handler:this.configCurrentImage, 
			suppressEvent:true 
		});
		this.cfg.addProperty("accparams", { 
			handler:this.configaccparams, 
			suppressEvent:true 
		});
	}
	
	LightBox.prototype.configaccparams = function(type, args, obj) {
		//
	}
	
	LightBox.prototype.configImages = function(type, args, obj) {
		var images = args[0];
		if ( images ) {
			this.images = [];
			for ( i=0; i<images.length; i++ ) {
				this.images[this.images.length] = images [i];
			}
		}
		if ( this.images.length <= 1) {
			//this.setFooter('');
		}
	}
	
	LightBox.prototype.configCurrentImage = function(type, args, obj) {
		if ( args[0] ) {
			this.currentImage = args[0];
		} else {
			this.currentImage = 0;
		}
		//console.log(args);
		//.log(this.currentImage);
	}
	
	function scrolltop () {
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
		return document.all? iebody.scrollTop : pageYOffset;
	}
	
	LightBox.prototype.resizeTo = function (width,height) {
		if ( width < 250 ) {
			width = 450;
		}
		var anim = new YAHOO.util.Anim (this.innerElement, {
			width: {
				to: width+20, unit: 'px'
			},
			height: {
				to: height+30 + parseInt($D.getStyle(this.footer,'height')), unit: 'px'
			}
		}, 1, YAHOO.util.Easing.easeOut );
		var anim2 = new YAHOO.util.Anim (this.element, {
			left: {
				to: $D.getClientWidth()/2-width/2, unit: 'px'
			},
			top: {
				to: $D.getViewportHeight()/2-(height+30 + parseInt($D.getStyle(this.footer,'height')))/2+ scrolltop(), unit: 'px'
			}
		}, 1, YAHOO.util.Easing.easeOut );
		anim.onComplete.subscribe(this.showImage,this,true);
		anim.animate();
		anim2.animate();
	}
	
	LightBox.prototype.nextImage = function () {
		this.currentImage ++;
		if ( this.currentImage == this.images.length ) this.currentImage = 0;
		this.setImage ();
	}
	
	LightBox.prototype.prevImage = function () {
		this.currentImage --;
		if ( this.currentImage == -1 ) this.currentImage = this.images.length-1;
		this.setImage ();
	}
	
	LightBox.prototype.setImage = function () {
		//this.img.style.display = 'none';
		
		this.loading.style.visibility = 'inherit';
		this.img = $d.createElement('img');
		this.img.style.visibility = 'hidden';
		this.setBody(this.img);
		$E.on ( this.img , 'load' , function (evt) {
			this.resizeTo(this.img.width,this.img.height);
		}, this, true);
	//	.log(this.images[this.currentImage]);
			if ( this.images[this.currentImage].src ) {
				this.img.src = this.images[this.currentImage].src;
				this.setHeader(this.images[this.currentImage].caption)
			} else {
				this.img.src = this.images[this.currentImage];
			}
	}
	
	LightBox.prototype.showImage = function () {
		this.img.style.display = 'inline';
		this.loading.style.visibility = 'hidden';
		this.img.style.visibility = 'inherit';
	}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		