/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://www.jugbit.com/jquery-vticker-vertical-news-ticker/
*/
(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 900,
		pause: 7000,
		showItems: 4,
		animation: 'fade',
		mousePause: true,
		isPaused: false,
		mayAnimate: 2,
		direction: 'up',
		height: 115
	};

	var options = $.extend(defaults, options);

	switchVticker = function(obj2){
		options.speed = 300;
		if(options.mayAnimate >= 2)
			moveUp(obj2,options);
		options.speed = 900;
		options.mayAnimate = 0;
	};
	moveUp = function(obj2, options){



		
		if(options.isPaused || options.mayAnimate < 2)
			return;
		

	
		var obj = obj2.children('ul');
		
	
		
    	var clone = obj.children('li:first').clone(true);
		height = obj.children('li:first').height()+10;

    	obj.animate({top: '-=' + height  + 'px'}, options.speed, function() {
        	$(this).children('li:first').remove();
        	$(this).css('top', '0px');
        	options.mayAnimate ++;
        });
        
        
		
		if(options.animation == 'fade')
		{
			obj.children('li:first').fadeOut(options.speed);
			if(options.height == 0)
			{
			obj.children('li:eq(' + options.showItems + ')').hide().fadeIn(options.speed).show();
			}
			
		}

		

    	clone.appendTo(obj);


		
		
      	
    	var i = -1;		
    	var s;
		var height = 0;
		
		obj2.children('ul').children('li').each(function(){
			
			if(i < options.showItems && i > -1){ 
				height = height + $(this).height() + 10;
			
			}

			i++;

		});

		
		   obj2.animate({height: height + 'px'}, options.speed, function() {
		   		options.mayAnimate ++;
    
        });
		
    			

	};
	

	return this.each(function() {
		var obj = $(this);
		var maxHeight = 0;
		

		obj.css({overflow: 'hidden', position: 'relative', height:'130px'})
			.children('ul').css({position: 'absolute', padding: 0})
			.children('li').css({});


		
    	var interval = setInterval(function(){ 
	
				moveUp(obj, options); 

		}, options.pause);
		
		if(options.mousePause)
		{
			obj.bind("mouseenter",function(){
				options.isPaused = true;
			}).bind("mouseleave",function(){
				options.isPaused = false;
			});
		}
	});
	

};
})(jQuery);
