/*------------------------------------------------
/ Design 2011
------------------------------------------------*/

$(function(){ /* On Load */
	
	/* sidebarR */
	$('.scrollable').scrollable({vertical: true, mousewheel: true}).navigator().autoscroll({
		interval: 5000		
	});	
	
	
	/* banner gallery in index */
	
	function buttonCountMargin ()
	{
		countMargin=($('.infoL').width() - $('.infoButton').width())/2;
		$('.infoButton').css('margin-left', countMargin + 'px');
	}
	buttonCountMargin();

	
	
	var bannerShowID;

	$('.infoButton a')
		.each(function(i){
			$(this).data('i',i);
		})
		.click(function(){return false;})
		.hover(
			function(){ stopBannerShow(); activateBanner($(this)); },
			startBannerShow
		);
		
	$('.infoText')
		.hover(
			function(){ stopBannerShow();},
			startBannerShow
		);

	/*$('.infoButton a, .infoText')
		.hover(
			stopBannerShow,
			startBannerShow
		);*/

	function activateBanner($a)
	{
		if ($a.hasClass('active')) return false;

		$a.siblings().removeClass('active');
		$a.addClass('active');

		var i=$a.data('i');

		$('.infoText').removeClass('showBlock');
		$('.infoText').eq(i).addClass('showBlock');

		return false;
	}

	function showPrevBanner()
	{
		var $prev_link=$('.infoButton .active').prev();

		var $a=$prev_link.length
				? $prev_link
				: $('.infoButton a:last');

		activateBanner($a);
	}

	function showNextBanner()
	{
		var $next_link=$('.infoButton .active').next();

		var $a=$next_link.length
				? $next_link
				: $('.infoButton a:first');

		activateBanner($a);
	}

	function startBannerShow()
	{
		bannerShowID=setInterval(showNextBanner, 3000);
	}

	function stopBannerShow()
	{
		clearInterval(bannerShowID);
	}

	startBannerShow();



}); //  onLoad
