/*
    Content Scroll Vertical
    
*/
	var pos, pos_initial, onmousewhell;
	var api;
	var timer, stopped = false;
	var types = ['DOMMouseScroll', 'mousewheel'];
	
	$.fn.startAnim = function(settings) {	
		
		var opts = $.extend({
			contentlist: 'newslist',
			autoplay: true,
			autopause: true,
			speed: 1,
			deltawheel: 30,
			scrolltimer: 20	
		}, settings);
		
		this.each(function () {			
			api=jQuery(this);			
			pos_initial = this.clientHeight;
			pos = pos_initial;
				
			// extend API			
			$.extend(api, {
					
				play: function() {

					// do not start additional timer if already exists
					if (timer) { return; }	
					
					stopped = false;
					
					// construct new timer
					timer = setInterval(api.anim, opts.scrolltimer);	
					api.anim();					
					
				},
			
				pause: function() {
					
					if (!timer) { return api; }	
					
					timer = clearInterval(timer);
					startTimer = clearInterval(startTimer);
		
				},
				
				// when stopped - mouseover won't restart 
				stop: function() {					
					api.pause();
					stopped = true;	
				},

				anim: function(fn) { //anim()
					var e = $("#"+opts.contentlist).get(0);
					e.style.visibility = 'visible';
					e.style.top = Math.floor(pos) + 'px';
					pos = pos - opts.speed;
					if(pos < -e.clientHeight) pos = pos_initial;
				},
				
				handle: function(delta) { //mousewheel
					var s = delta < 0 ? s=-1 : s=1 ;
					pos = pos + s*opts.deltawheel;
					api.anim();
					
				},
				
				wheel: function(event){
					var delta = 0;
					if (!event) // For IE.
							event = window.event;
					if (event.wheelDelta) { // IE/Opera. 
							delta = event.wheelDelta/120;
							if (window.opera)
									delta = -delta;
					} else if (event.detail) { // Mozilla case. 
							delta = -event.detail/3;
					}
					if (delta)
							api.handle(delta);
					if (event.preventDefault)
							event.preventDefault();
					event.returnValue = false;
				}
			});
			
			if (opts.autoplay) {
				starTimer = setTimeout(api.play, opts.scrolltimer);				
			} else {
				api.stop();	
			};
			
			this.onmouseover = function() { api.stop();};
			this.onmouseout = function() { api.play();};
			
			// mousewheel
			var e = $("#"+opts.contentlist).get(0);
			if (e.addEventListener)			
			/** DOMMouseScroll is for mozilla. */
			e.addEventListener('DOMMouseScroll', api.wheel, false);
			/** IE/Opera. */
			e.onmousewheel = document.onmousewheel = api.wheel;

		});
	};
	

