/*
		$$__HQMatics__$$
	
		Modified: 2010.03.09 14:01:48
		
		Class: none
		File: hqimagefader.js
		
		Description: fades images in given ul>li
*/

var HQUlScroller = Class.create();

HQUlScroller.prototype = {
    mouseover: false,
	initialize: function(thelist) {
        
        $(thelist).observe('mouseover', function(){ this.mouseover = true; }.bind(this));
        $(thelist).observe('mouseout', function(){ this.mouseover = false; }.bind(this));
        
		this.listitems = $$('#'+thelist+' li');

		if (this.listitems.size() > 1) {
			this.curitem = this.listitems.size() - 1;
			for (i = 0; i < this.curitem; i++) {
				this.listitems[i].hide();
				
			}
			this.listitems[this.curitem].show();
		}
	},
	
	applyLinks: function() {
		if (this.listitems.size() > 1) {
			for (i = 0; i < this.listitems.size(); i++) {
				var mylinks = $A(this.listitems[i].getElementsByTagName('a'));
				if (mylinks.size() > 0) {
					this.listitems[i].observe('click', this.itemClicked);
					this.listitems[i].style.cursor = 'pointer';
				}
			}
		}
	},
	itemClicked: function(event) {
		var mylinks = $A(this.getElementsByTagName('a'));
		if (mylinks.size() > 0) {
			document.location = mylinks[mylinks.size() - 1].href;
		}
	},
	
	start: function() {
		this.pe = new PeriodicalExecuter(this.fadenow.bind(this), 6);
	},
	
	fadenow: function() {
	   if (this.mouseover) {
	       return;
	   }
		var shownitem = this.curitem;
		
		this.curitem++;
		if (this.curitem >= this.listitems.size()) this.curitem = 0;
		
		if (this.curitem > shownitem) {
			this.listitems[this.curitem].appear({ duration: 0.5 });
			this.listitems[shownitem].fade({ duration: 0.5 });
		}
		else {
			this.listitems[this.curitem].appear({ duration: 0.5 });
			this.listitems[shownitem].fade({ duration: 0.5 });
		}
	}
	
	
};

