(function($)
{
var intervalId = 0;
$.fn.MyTicker = function(options){
	
	var defaults = 
        {
			speed: 700,
			pause: 4000,
			showItems: 1,
			animation: '',
			mousePause: true,
			isPaused: false
        };
	var opts = $.extend(defaults, options);
	
	if(intervalId > 0)
	{
	    clearInterval(intervalId);
	}
	

	var contentBox = $(this);
	//how much items per page to show
	var show_per_page = opts.showItems; 
	//getting the amount of elements inside content div
	var number_of_items = $(contentBox).children().size();
	//calculate the number of pages we are going to have
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
	
	//set the value of our hidden input fields
	var _currentPage = document.createElement('input');
	_currentPage.type = 'hidden';
	_currentPage.id = $(contentBox).attr('id') + '_current_page';
	_currentPage.value = 1;
	
	var _showPerPage = document.createElement('input');
	_showPerPage.type = 'hidden';
	_showPerPage.id = $(contentBox).attr('id') + '_show_per_page';
	_showPerPage.value = show_per_page;
	
	
		
	var Fngo_to_page = function(page_num){
	
		if(opts.isPaused)
				return;
		//get the number of items shown per page
		var show_per_page = parseInt($(_showPerPage).val());
		
		//get the element number where to start the slice from
		start_from = page_num * show_per_page;
		
		//get the element number where to end the slice
		end_on = start_from + show_per_page;
		
		//hide all children elements of content div, get specific items and show them
		$(contentBox).children().animate({ height: "hide" }, "normal").slice(start_from, end_on).animate({ height: "show" }, "normal");
		
		//update the current page input field
		page_num = parseInt(page_num) + 1;
		if(page_num >= number_of_pages)
		{
			page_num = 0;
		}
		$(_currentPage).val(page_num);
	};
	
	/* 
	what are we going to have in the navigation?
		- link to previous page
		- links to specific pages
		- link to next page
	*/
	
	//hide all the elements inside content div
	$(contentBox).children().css('display', 'none');
	
	//and show the first n (show_per_page) elements
	$(contentBox).children().slice(0, show_per_page).animate({ height: "show" }, "normal");
	
	intervalId = setInterval(function(){ Fngo_to_page($(_currentPage).val()); }, opts.pause);
			
	if(opts.mousePause)
	{
		$(contentBox).bind("mouseenter",function(){
			opts.isPaused = true;
		}).bind("mouseleave",function(){
			opts.isPaused = false;
		});
	}
	
}
})(jQuery);


