customerItems = new Array();
customerItemsPosition = new Array();
customerItemsTotal = 0;
customerItemsPerLine = 6;
customerOffset = 0;
customerOffsetN = 0;

$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};

function animateSlider( event ){
	
	var itemsIn = new Array();
	var itemsOut = new Array();
	var customerOffsetNN = 0;
	var topIn = 0;
	var topOut = 0;
	var topIni = 0;
	
	if( ( customerOffset + 1) == customerItemsTotal ){
		customerOffset = -1;
	}
	customerOffsetN = customerOffset;
	customerOffsetNN = customerOffset;

	for(i=0; i<customerItemsPerLine; i++){
		customerOffset += 1;
		itemsIn[i] = customerOffset;
	}

	if( customerOffsetN <= 0 ){
		customerOffsetN = customerItemsTotal-1;
	}
	if( customerOffsetNN <= 0 ){
		customerOffsetNN = customerItemsTotal-1;
	}

	for(i=0; i<customerItemsPerLine; i++){
		customerOffsetN = (customerOffsetNN-customerItemsPerLine)+(i+1);
		itemsOut[i] = customerOffsetN;		
	}
	
	
	if(event == "next"){
		topIn = 0;
		topIni = -20;
		topOut = 30;
	}
	
	if(event == "back"){
		topIn = 0;
		topIni = 30;
		topOut = -20;
	}
	
	for(i=0; i<customerItemsPerLine; i++){
		customerItems[itemsOut[i]].css({ top: customerItemsPosition[i]['top'], left: customerItemsPosition[i]['left'], position: "absolute" });
		customerItems[itemsOut[i]].pause((50*(i+1))).animate({ opacity: 0, "top": topOut }, { duration:200, complete: function(){ $(this).css("display","none"); }} );
	}
	
	for(i=0; i<customerItemsPerLine; i++){
		customerItems[itemsIn[i]].css({ top: topIni, left: customerItemsPosition[i]['left'], position: "absolute", display: "block" });
		customerItems[itemsIn[i]].pause(50+(50*(i+1))).animate({ opacity: 1, "top": topIn }, 200 );
	}
	
}

// after all documents elements are loaded
$(window).load(function(){
    
	for(i=0; i<customerItemsPerLine; i++){
		customerItems[i].css({ opacity: 1, display: "block" });
		customerItemsPosition[i] = new Array();
		customerItemsPosition[i]['top'] = customerItems[i].position().top;
		customerItemsPosition[i]['left'] = customerItems[i].position().left; 
	}
	customerOffset = customerItemsPerLine-1;
});


// after document is loaded
$(document).ready(function(){
	
	$(".slide-img").css("display","none");
	$(".slide").css("display","none");
	
	var slides = $("#slider .slide-container .slide");
	var images = $("#slider .slide-container .slide-img");

	$("#slider .tabs ul li").each(function(i){
		var element = $(this);
		element.click(function(){
			$("#slider .tabs ul li a").removeClass("selected");
			element.find("a").addClass("selected");
			$(slides).css("display","none");
			$(slides[i]).css("display","block");
			$(".slide-img").css("display","none");
			$(images[i]).css("display","block");
		});
	});
	
	$("#slider .tabs ul li .selected").click();
	
	$("#clients-slide .item").each(function(i){
		
		var element = $(this);
		
		element.css({ opacity: 0, display: "none" });
		
		customerItems.push(element);
		customerItemsTotal += 1;
		
		element.click(function(){
			window.location = element.find('.display').attr("href");
			return false;
		});
		if(!$.browser.msie){
			element.hover(
				function(){
					element.find('.content').stop();
					element.find('.content').animate({
										opacity: 1,
										'margin-top': '-35',
										height: '155'
									}, 
									200 );
					element.find('.display').stop();				
					element.find('.display').css('background-position','50% 100%').animate({
										'margin-top': '-35'
									}, 
									200);
				
				}, 
				function(){
					
					element.find('.content').stop();	
					element.find('.content').animate({
										opacity: 0,
										'margin-top': '0',
										height: '90'
									},
									200 );
									
					element.find('.display').stop();			
					element.find('.display').css('background-position','50% 0').animate({
										'margin-top': '0'
									}, 
									200);
				
				});
		}
	});
	
	
	
	$("#clients-slide .btn-slideback").click(function(){
		
		animateSlider( "back" );
		return false;
		
	});
	
	
	$("#clients-slide .btn-slidenext").click(function(){
		
		animateSlider( "next" );
		return false;
		
	});

});
