
Cufon.replace('.menu li a, #content h2, .right-col h3');

$(document).ready(function() {

	// This is more like it!
	$('#footer img, #current-clients .group').css('opacity', '.5').mouseover(function(){
		$(this).animate({'opacity':1}, 500);
	}).mouseout(function(){
		$(this).animate({'opacity':.5}, 500);
	});
	// var height=[];	
	// var borders = ['red','green','blue'];
	$('.group').each(function(i){
		if(i==1){
			$(this).css('margin-top','130px');
		}else if(i==2){
			$(this).css('margin-top','130px');
		}
		// height[i] = $(this).height();
		// $(this).css({'height':height[i]+200+'px', 'border':'1px solid '+borders[i]});
		// alert(height[i]+'px');
	});
	// alert(height);
	$('ul li:first-child').addClass('first-child');
	$('ul li:last-child').addClass('last-child');
	
	$('table tr:even').addClass('even');
	
	setTimeout(function(){
		
	},2000);
	
	$('#quotes').cycle({
		timeout: 8000,
		cleartype:       !$.support.opacity,
		cleartypeNoBg: true,
		height: '100px',
		random: true
	});
	
	// var groupCount = 4;
	// var totalGroups = Math.floor($('#current-clients img').length/groupCount);
	// 
	// var group1 = {};
	// var group2 = {};
	// var group3 = {};
	// var group4 = {};
	// var group5 = {};
	// var group6 = {};
	// var group7 = {};
	// 
	// var previousIndex = 0;
	// 
	// $('#current-clients img').each(function(key,value){
	// 	if(key<4){
	// 		group1[key] = $(this);
	// 	}
	// 	if(key>=4&&key<8){
	// 		group2[key] = $(this);
	// 	}
	// 	if(key>=8&&key<12){
	// 		group3[key] = $(this);
	// 	}
	// 	if(key>=12&&key<16){
	// 		group4[key] = $(this);
	// 	}
	// 	if(key>=16&&key<20){
	// 		group5[key] = $(this);
	// 	}
	// 	if(key>=20&&key<24){
	// 		group6[key] = $(this);
	// 	}
	// 	if(key>=24&&key<28){
	// 		group7[key] = $(this);
	// 	}
	// });
	// var allGroups = [group1,group2,group3,group4,group5];
	// allGroups = allGroups.sort(function() {return 0.5 - Math.random()});
	// $('#current-clients').hide();
	// 
	// var randKey = Math.floor(Math.random()*3);
	// if(previousIndex == randKey){
	// 	randKey = previousIndex+1;
	// }else if(randKey == previousIndex){
	// 	randKey = previousIndex+1;
	// }
	// previousIndex = randKey;
	// $('#current-clients').html('<h3>Current Clients</h3>');
	// $('#current-clients').hide();
	// $.each(allGroups[randKey], function(key, value){
	// 	$('#current-clients').append(value);
	// });
	// $('#current-clients').show();
	// $('#current-clients img').hide();
	// $('#current-clients img').fadeIn('slow');
	// setInterval(function(){
	// 	var randKey = Math.floor(Math.random()*3);
	// 	if(previousIndex == randKey){
	// 		randKey = previousIndex+1;
	// 	}else if(randKey == previousIndex){
	// 		randKey = previousIndex+1;
	// 	}
	// 	previousIndex = randKey;
	// 	$('#current-clients').html('<h3>Current Clients</h3>');
	// 	$('#current-clients').hide();
	// 	$.each(allGroups[randKey], function(key, value){
	// 		$('#current-clients').append(value);
	// 	});
	// 	$('#current-clients').show();
	// 	$('#current-clients img').hide();
	// 	$('#current-clients img').fadeIn('slow');
	// }, 5000);
	
	// $('#current-clients').prepend(group1[0]);
	
			// $('#wrap').html(group1[0]);
	// $('#left-col').html(group1);
	
	// $('#current-clients img:nth-child(5n)').after('</div>');
	
	// $('#current-clients img').wrap(function(){
	// 	return '<div class="test">' +  '</div>';
	// });
	
	// $('#current-clients img').each(function(index, el){
	// 			if(index==0){
	// 				$(this).insertBefore('<div>');
	// 			}
	// 			console.log(index);
	// 		});
	
	$('.menu li').mouseover(function(){
		$(this).find('ul').addClass('hover');
	}).mouseout(function(){
		$(this).find('ul').removeClass('hover');
	});
	
});



$(window).load(function() { 
    arrangeBoxes();
	shiftLeft();
    setInterval('shiftLeft()',1200);
});

// arrange the boxes to be aligned in a row
function arrangeBoxes() {
    $('#active-clients img').each( function(i, item) {
        var position = $('#active-clients').position().top + 3 + i * ( $(item).height() + 50 );
        $(item).css('top', position+'px')
		
        $(this).remove().appendTo('#active-clients');
    });
}

// shifts all the boxes to the left, then checks if any left the window
function shiftLeft() {
    $('#active-clients img').stop().animate({'top' : "-=100px"}, 1200, 'linear', checkEdge());
}

// returns the new location for the box that exited the window
function getNewPosition() {
    return $('#active-clients img:last').position().top + $('#active-clients img:last').outerHeight() + 20;
}

// if the box is outside the window, move it to the end
function checkEdge() {
    var windowsLeftEdge = $('#active-clients').position().top;

    $('#active-clients img').each( function(i, box) {
        // right edge of the sliding box
        var boxRightEdge = $(box).position().top + $(box).height();

        // position of last box + width + 10px
        var newPosition = getNewPosition();

        if ( parseFloat(boxRightEdge) < parseFloat(windowsLeftEdge-280) ) { 
            $(box).css('top', newPosition);
            $(box).remove().appendTo('#active-clients');
            first = $('#active-clients img:first').attr('class');
        }
    });
}
