var $timer;
$(document).ready(function(){



//	$("#promos").scrollable({ circular: true, size: 3, items: '#promos_cnt', next: '.navi_right'});

	$("#promos").scrollable();



	if ($('body').hasClass('page-template-home-php'))
	{
	//	homepage_banners(1);

		$('#boxes div.box').each(function(){
			$(this).addClass('pos_'+$('div.box').index(this));
		});

		$('div.navi').hover(
			function(){
				$(this).addClass('navi_hover');
			},
			function(){
				$(this).removeClass('navi_hover');
			});
	}


	$('#menu li').hover(
		function(){$(this).addClass('selected');},
		function(){$(this).removeClass('selected');}
	);


	$('div.entry h2').each(function(){
	    var $current_html =$(this).html();
		$(this).html('<span class="subtitle_cnt">'+$current_html+'</span>');
	});

});


function homepage_banners(x){
	n = $('#promos div.promo').length;
	current_banner = '#promos div.pos'+x;
	if (x<=n)
	{
		$('#promos div.promo').fadeOut().removeClass('selected');
		$(current_banner).fadeIn().addClass('selected');
		x++;
		$timer = setTimeout( function() { homepage_banners(x);}, 5000);
	} else {
		homepage_banners(1);
	}
}




/*	if ($('body').hasClass('home'))
	{
		homepage_banners(1);

		$('#boxes div.box').each(function(){
			$(this).addClass('pos_'+$('div.box').index(this));
		});

		$('div.navi').hover(
			function(){
				$(this).addClass('navi_hover');
			},
			function(){
				$(this).removeClass('navi_hover');
			});

		$('div.navi_right').click(function(){
			clearTimeout($timer);
			$('#promos div.promo').each(function(){
				if ($(this).hasClass('selected'))
				{
					$curent_item = $('#promos div.promo').index(this);

				}
			});
			$curent_item++
			homepage_banners($curent_item+1);
			return false;
		});

		$('div.navi_left').click(function(){
			clearTimeout($timer);
			$('#promos div.promo').each(function(){
				if ($(this).hasClass('selected'))
				{
					$curent_item = $('#promos div.promo').index(this);
				}
			});
			$curent_item++
			if ($curent_item != 1)
			{
				homepage_banners($curent_item-1);
			}
			if ($curent_item == 1)
			{
				homepage_banners($('#promos div.promo').length);
			}
			return false;
		});
	}
*/



/*
	$pag_sape = 0;
	$('div.navi_left').click(function(){
		if ($(this).parent().hasClass('disabled'))
		{
			return false;
		} else {
			if ($pag_sape > 0)
			{
				$('div.navi').removeClass('disabled')
				$pag_sape--;
				$('#promos_cnt').animate({
					left: '+=300'
				}, 1000, function() {
					// Animation complete.
				});
			}
		}
		return false;
	});

	$('div.navi_right').click(function(){
		if ($(this).parent().hasClass('disabled'))
		{
			return false;
		} else {
			if ($pag_sape < 4)
			{
				$('div.navi').removeClass('disabled')
				$pag_sape++;
				$('#promos_cnt').animate({
					left: '-=300'
				}, 1000, function() {
					// Animation complete.
				});
			}
		}
		return false;
	});


*/


/*
		$('div.navi_right').click(function(){
			clearTimeout($timer);
			$('#promos div.promo').each(function(){
				if ($(this).hasClass('selected'))
				{
					$curent_item = $('#promos div.promo').index(this);

				}
			});
			$curent_item++
			homepage_banners($curent_item+1);
			return false;
		});

		$('div.navi_left').click(function(){
			clearTimeout($timer);
			$('#promos div.promo').each(function(){
				if ($(this).hasClass('selected'))
				{
					$curent_item = $('#promos div.promo').index(this);
				}
			});
			$curent_item++
			if ($curent_item != 1)
			{
				homepage_banners($curent_item-1);
			}
			if ($curent_item == 1)
			{
				homepage_banners($('#promos div.promo').length);
			}
			return false;
		});
*/
