// JavaScript Document

var movingInsideImageContainerId = 'bannerImagesCropped';
var imageClass = 'image_link_component';
var imageCount;
var boxWidth = 520;
var speed = 1000;
var numb;

j(document).ready(function() {

	imageCount = j('#'+movingInsideImageContainerId+' .'+imageClass).length;
	
	for(var i=0; i<imageCount; i++){
		currentImageDisplay = i+1;
		if(i==0){
			var classToAdd = ' class="first active"';
		}else if(i==imageCount-1) {
			var classToAdd = ' class="last"';
		}else {
			var classToAdd = ' class=""';
		}
		j('#bannerNav li:last').before('<li><a href=# id="bannerNumber'+i+'"'+classToAdd+'>'+currentImageDisplay+'</a></li>');
		j('#bannerNumber'+i).click(( function( i ) { return function() { numbLink(i) } } )(i));
		j('#bannerNumber'+i).click(function() { return false; });
		j(".image_link_component:eq("+i+") a").mouseover(showNav);
		j(".image_link_component:eq("+i+") a").mouseout(hideNav);
		j("#bannerNumber"+i).mouseover(showNav);
		j("#bannerNumber"+i).mouseout(hideNav);
	}
	//alert(document.getElementById('bannerNav').offsetWidth);
	hideNav();
	j("#bannerNavContainer").mouseover(showNav);
	j("#bannerNavContainer").mouseout(hideNav);
	j("#prev").mouseover(showNav);
	j("#prev").mouseout(hideNav);
	j("#next").mouseover(showNav);
	j("#next").mouseout(hideNav);
	j('#bannerNav').css('position','absolute');
	j('#bannerNav').css('left',(boxWidth / 2)-(document.getElementById('bannerNav').offsetWidth / 2));//document.getElementById('bannerNav').offsetWidth;
});

function randomize() {

	imageCount = j('#'+movingInsideImageContainerId+' .'+imageClass).length;

	for(var i=0; i<imageCount; i++){
		var move_index = Math.round( Math.random() * j('#not_moved .'+imageClass).length - 1 );
		j('#not_moved .'+imageClass+':eq('+move_index+')').appendTo('#bannerImagesCropped');
	}

}

function numbLink(numb){
	clearInterval(timer);
	j('#bannerNav a:eq('+(current+1)+')').removeClass('active');
	j('#'+movingInsideImageContainerId).animate({left:-(numb * boxWidth) +"px"}, speed, numbCallback);
	j('#bannerNav a:eq('+(numb+1)+')').addClass('active');
	current = numb;
	return false;
}

function numbCallback(){
}

function hideNav(){
	var animSpeed = (((210 - parseInt(j('#bannerNavContainer').css('top').split('px').join(''))) / 29) * 400);
	j('#bannerNavContainer').stop();
	j('#bannerNavContainer').animate({top:"210px"}, animSpeed, numbCallback);
}

function showNav(){
	var animSpeed = (((parseInt(j('#bannerNavContainer').css('top').split('px').join('')) - 181) / 29) * 400);
	j('#bannerNavContainer').stop();
	j('#bannerNavContainer').animate({top:"181px"}, animSpeed, numbCallback);
}