//sabbe satta bhavantu sukhitatta
$(
	function()
	{
		var count = 0;
		var offset = 0;
		var speed = 5000;
	
		var maxdivs = $("#lma_category_blog_slider_boxes div.box").length;	
		var blog_width = $("#blog").width();
	
		var boxWidth = blog_width + 20;
		$("#lma_category_blog_slider_boxes").width( maxdivs * boxWidth + 'px' );
		$("#lma_category_blog_slider_boxes div.box").width( boxWidth + 'px' );
		
		function lma_category_blog_slider_show_next(count)
		{
			var ani_time = 500;
			if( count == 0 ) ani_time = 1000;
			offset = count * boxWidth;	
			$( "#lma_category_blog_slider_boxes" ).animate
			(
				{
					marginLeft:  + offset + 'px'
				}, 
				ani_time,
				function()
				{
					var current = $('li.move-to-tab[tab-id="' + (( -1 * count ) ) + '"]');
					$('.move-to-tab').removeClass('current');
					current.addClass('current');
				} 
			);
		}
		
		var tid = window.setInterval
		(
			function()
			{
				count--;
				if( count + (maxdivs ) == 0 )
				{
					count = 0;
				}
				lma_category_blog_slider_show_next(count);
			},
			speed
		);
		
		$('#blog').mouseenter(
			function()
			{
				window.clearInterval(tid);
			}
		)
		.mouseleave(
			function()
			{
				tid = window.setInterval
				(
					function()
					{
						count--;
						if( count + (maxdivs ) == 0 )
						{
							count = 0;
						}
						lma_category_blog_slider_show_next(count);
					},
					speed
				);
			}
		);
		
		$(".move-to-tab").click(
			function()
			{
				var tab_id = parseInt( $(this).attr("tab-id"), 10 );
				offset = -( boxWidth * tab_id );
				count = -(tab_id); 
				
				$(".move-to-tab").removeClass('current');
				$(this).addClass('current');
				
				$( "#lma_category_blog_slider_boxes" ).animate
				(
					{
						marginLeft:  + offset + 'px'
					}, 
					500
				);
			}
		);
	}
);


