// nadefinujeme si funkci pro hledani v jQuery objektech
jQuery.fn.indexOf = function(item, i) {
    i || (i = 0);
    var length = this.length;
    if(i < 0) i = length + i;
    for(; i < length; i++)
        if(this[i] === item[0]) return i;
    return -1;
};
var Multiswitch = {
	activeClassName:'active',
	initialize:function(elm,timeout){
		this.timeout = (timeout || 3) * 1000;
		this.elm = jQuery(elm);
		this.items = jQuery(elm).find('li');
		this.items.bind('mouseenter', function(){Multiswitch.mouseenter(this);}).bind('mouseleave', function(){Multiswitch.mouseleave(this);});
		this.showNext();
	},
	showNext:function(){
		var itemPosition = this.items.indexOf(this.elm.find('li.' + this.activeClassName)) + 1;
		if(itemPosition >= this.items.length || itemPosition < 0) itemPosition = 0;
		this.activate(this.items[itemPosition]);
		this.timerStart();
	},
	activate:function(element){
		jQuery(this.elm.find('li.' + this.activeClassName)).removeClass(this.activeClassName);
		jQuery(element).addClass(this.activeClassName);
	},
	mouseenter:function(evt){
		this.timerStop();
		this.activate(evt);
	},
	mouseleave:function(evt){
		this.timerStart();
	},
	timerStart:function(){
		this.timer = setTimeout('Multiswitch.showNext()', this.timeout);
	},
	timerStop:function(){
		clearTimeout(this.timer);
	}
};
