window.addEvent("domready",function(){
	
	$$('.gk_news_highlighter').each(function(el,i){	
		var module_id = el.getProperty("id");
		var $G = $Gavick["gk_news_highlighter"+module_id];
		var wrapper = el; 
		var next, prev = false;
		var item_anim = false;
		//
		if(el.getElement('.gk_news_highlighter_interface')){
		    next = wrapper.getElement('.next');	
		    prev = wrapper.getElement('.prev');
		}
		// one sliding
		if($G['animationType'] == 0){
			var wrapper2 = wrapper.getElement('.nowrap');
			var w = 0;
			wrapper.getElements('.nowrap span').each(function(elmt, i){w += elmt.getSize().size.x;});
			var time = (w/$G['animationSpeed']) * 1000;
			var timeOriginal = time;
			var effect = new Fx.Style(wrapper2,'margin-left',{duration: time, transition: Fx.Transitions.linear, onComplete: function(){
				effect.set(el.getSize().size.x);
				effect.start(el.getSize().size.x, -w);	
			}});

			if($G['mouseover']){
				wrapper2.addEvent("mouseenter", function(){
					effect.stop();
					time = ((w+wrapper2.getStyle('margin-left').toInt())/$G['animationSpeed']) * 1000;
					effect = new Fx.Style(wrapper2,'margin-left',{duration: time, transition: Fx.Transitions.linear, onComplete: function(){
						effect.options.duration = timeOriginal;
						effect.set(el.getSize().size.x);
						effect.start(el.getSize().size.x, -w);
					}});
				});
				
				wrapper2.addEvent("mouseleave", function(){effect.start(wrapper2.getStyle('margin-left').toInt(), -w);});
			}
			effect.set(el.getSize().size.x);
			effect.start(el.getSize().size.x, -w);
		}
		// Other animation types
		if($G['animationType'] != 0){		
			var items = el.getElements('.gk_news_highlighter_item');
			items.each(function(it){it.setStyle('display', 'block');});
			var effects1 = [];
			var effects2 = [];
			var actual = 0;
			var mouseIsOver = false;
			//
			var timer = (function(){
				if(mouseIsOver == false){
					effects1[actual].start(0);
					if($G['animationType'] == 2) effects2[actual].start(0,-24);
					else if($G['animationType'] == 3) effects2[actual].start(0,24);
					else if($G['animationType'] == 4) effects2[actual].start(0,780);	
					actual++;
					if(actual > items.length-1) actual = 0;
					effects1[actual].start(1);
					if($G['animationType'] == 2 || $G['animationType'] == 6) effects2[actual].start(24,0);
					else if($G['animationType'] == 3 || $G['animationType'] == 7) effects2[actual].start(-24,0);
					else if($G['animationType'] == 4 || $G['animationType'] == 5) effects2[actual].start(-780,0);
				}
			}).periodical($G['animationInterval']);
			//
			if(next){
				next.addEvent('click', function(e){
					new Event(e).stop();
					if(!item_anim){
						item_anim = true;
						(function(){item_anim = false;}).delay($G['animationSpeed']);
						effects1[actual].start(0);
						if($G['animationType'] == 2) effects2[actual].start(0,-24);
						else if($G['animationType'] == 3) effects2[actual].start(0,24);
						else if($G['animationType'] == 4) effects2[actual].start(0,780);	
						actual++;
						if(actual > items.length-1) actual = 0;
						effects1[actual].start(1);
						if($G['animationType'] == 2 || $G['animationType'] == 6) effects2[actual].start(24,0);
						else if($G['animationType'] == 3 || $G['animationType'] == 7) effects2[actual].start(-24,0);
						else if($G['animationType'] == 4 || $G['animationType'] == 5) effects2[actual].start(-780,0);
						$clear(timer);
						timer = (function(){
				    	    if(mouseIsOver == false){
						        effects1[actual].start(0);
						        if($G['animationType'] == 2) effects2[actual].start(0,-24);
						        else if($G['animationType'] == 3) effects2[actual].start(0,24);
						        else if($G['animationType'] == 4) effects2[actual].start(0,780);	
						        actual++;
						        if(actual > items.length-1) actual = 0;
						        effects1[actual].start(1);
						        if($G['animationType'] == 2 || $G['animationType'] == 6) effects2[actual].start(24,0);
						        else if($G['animationType'] == 3 || $G['animationType'] == 7) effects2[actual].start(-24,0);
						        else if($G['animationType'] == 4 || $G['animationType'] == 5) effects2[actual].start(-780,0);
				    	    }
			        	}).periodical($G['animationInterval']);
			        }
				});
				
				prev.addEvent('click', function(e){
					new Event(e).stop();
					if(!item_anim){
						item_anim = true;
						(function(){item_anim = false;}).delay($G['animationSpeed']);
							effects1[actual].start(0);
							if($G['animationType'] == 2) effects2[actual].start(0,-24);
							else if($G['animationType'] == 3) effects2[actual].start(0,24);
							else if($G['animationType'] == 4) effects2[actual].start(0,780);	
							(actual == 0) ? actual = items.length-1 : actual--;
							effects1[actual].start(1);
							if($G['animationType'] == 2 || $G['animationType'] == 6) effects2[actual].start(24,0);
							else if($G['animationType'] == 3 || $G['animationType'] == 7) effects2[actual].start(-24,0);
							else if($G['animationType'] == 4 || $G['animationType'] == 5) effects2[actual].start(-780,0);
							$clear(timer);
							timer = (function(){
				        		if(mouseIsOver == false){
					        		effects1[actual].start(0);
					        		if($G['animationType'] == 2) effects2[actual].start(0,-24);
					        		else if($G['animationType'] == 3) effects2[actual].start(0,24);
					        		else if($G['animationType'] == 4) effects2[actual].start(0,780);	
					        		actual++;
					        		if(actual > items.length-1) actual = 0;
					        		effects1[actual].start(1);
					        		if($G['animationType'] == 2 || $G['animationType'] == 6) effects2[actual].start(24,0);
					        		else if($G['animationType'] == 3 || $G['animationType'] == 7) effects2[actual].start(-24,0);
					       	 		else if($G['animationType'] == 4 || $G['animationType'] == 5) effects2[actual].start(-780,0);
				        		}
			        	}).periodical($G['animationInterval']);
					}
				});
			}
			//
			items.each(function(elm,j){
				elm.setStyle('z-index',items.length - j);
				effects1[j] = new Fx.Style(elm, 'opacity', {duration: $G['animationSpeed'], transition: $G['animationFun']});
				//
				if($G['animationType'] == 2 || $G['animationType'] == 3 || $G['animationType'] == 6 || $G['animationType'] == 7){		
				    effects2[j] = new Fx.Style(elm, 'top', {duration: $G['animationSpeed'], transition: $G['animationFun']});
				}else if($G['animationType'] == 4 || $G['animationType'] == 5){		
				    effects2[j] = new Fx.Style(elm, 'left', {duration: $G['animationSpeed'], transition: $G['animationFun']});	
				}
				//
				if(j != 0) effects1[j].hide();
				if($G['animationType'] > 1) effects2[j].set(0);	
			});
			//
			if($G['mouseover']){
				items.addEvent("mouseenter", function(){mouseIsOver = true;});
				items.addEvent("mouseleave", function(){mouseIsOver = false;});
			}
		}
	});
});
