// ***************************************************************
// ***************************************************************
// ***************************************************************
// Banner JS

var total = null;
var int = 0;
var width = 0;
var $slide = null;
var ani = false;
$(document).ready(function(){
	//get the banner count
	total = $('#banner-main-view .banner-image').length;
	width = $('#banner-main-view .banner-image:first-child').width();
	$slide = $('#banner-main-view .banner-container');
	
	//add next/previous
	$('a#banner-next, a#banner-prev').click(function(){
		id = $(this).attr('id');													 
		
		if( id=='banner-prev' )
			banner_prev();
		else if( id=='banner-next' )
			banner_next();
	});
	
});


function banner_next()
{
	//get current x
	var x=$slide.css('left');
    
	if( (int+1)  < (total) && ani==false )
	{
		int++;
		nx = parseInt(x) - parseInt(width);
			
		banner_slide(nx);
	}
	else if( (int+1) >= (total) && ani==false )
	{
		int=0;
		banner_slide(0);
	}
}

function banner_prev()
{
	//get current x
	var x=$slide.css('left');
	if( (int) > 0 && ani==false )
	{
		int--;
		nx = parseInt(x) + parseInt(width);
			
		banner_slide(nx);
	}
}

function banner_slide(x)
{
	ani=true;
	$slide.animate({left: x}, 1000, function(){ani=false});
}
