var slide_item = '#slides img';
var animate_time = 4000;

$( document ).ready( function(){
	
	$('.blink')
		.focus( function(){
			if ( $(this).attr('value') == $(this).attr('title') )
				$(this).attr({ 'value' : '' });
		})
		.blur( function(){
			if ( $(this).attr('value') == '' )
				$(this).attr({ 'value' : $(this).attr('title') });
		});
		
	
	var all_images = $( slide_item ).length;
	
	if ( all_images < 1 ) return;
	
	var zindex = all_images;
	$( slide_item ).each( function(){
		$( this ).css( { 'z-index': zindex } );
		zindex--;
	});
	
	start_images_slides( all_images );
	
	if( $( '.our-clients h3' ).length > 0 ) {
		
		$( '.our-clients h3' ).hover(
			function(){ $(this).parent().find('.list').show(); },
			function(){  }
		);
		
		$( '.our-clients' ).hover(
			function(){  },
			function(){ $(this).find('.list').hide(); }
		)
	}
	
	
})

function start_images_slides( num ) {
	var index = 0;
	var next;
	var interval = window.setInterval( function(){
		
		if ( index == num ) index = 0;
		
		next = index + 1;
		
		if ( next == num ) next = 0;
		
		$( slide_item + ":eq(" + index + ")" ).fadeOut(1200);
		$( slide_item + ":eq(" + next + ")" ).fadeIn(1200);
		
		$( '#top-served span:eq('+ index +')' ).fadeOut( 1200, function(){
			$( '#top-served span:eq('+ next +')' ).fadeIn( 1200 );
		})
		
		index++;
		
	}, animate_time);
}