$(function(){
    $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
        
    $( '#navigation li' ).mouseover( function() {
    	if ( $(this).parent().hasClass( 'submenu' ) ) return;
    	
		$('.submenu').hide();
		$( this ).find('.submenu').show();
		
	}).mouseout( function() {
		if ( $(this).parent().hasClass( 'submenu' ) ) return;
		
		$( this ).find('.submenu').hide();
	});
	
	
	start_slides( '#home-slider a', 7500, function( next ){
		$( '.featured-thumbs strong' ).removeClass( 'active' );
		$( '.featured-thumbs strong:eq(' + next + ')' ).addClass( 'active' );
	});
	
});




function start_slides( item, time, callback ) {
	
	
	var all_items = $( item ).length;
	
	
	if ( all_items < 1 ) return;
	
	var zindex = all_items;
	
	$( item ).each( function(){
		$( this ).css( { 'z-index': zindex } );
		zindex--;
	});
	
	var index = 0;
	var next;
	var time = time || 7500;
	var callback = callback || function(){};
	
	var interval = window.setInterval( function(){
		if ( index == all_items ) index = 0;
		next = index + 1;
		
		if ( next == all_items ) next = 0;
		
		$( item + ":eq(" + index + ")" ).fadeOut(1200);
		$( item + ":eq(" + next + ")" ).fadeIn(1200, function(){
			callback( next );
		});
		
		index++;
	}, time);
}
