$( document ).ready( function(){
	start_slides( '.dog-slides a', 4500 );
	
	$('#navigation .drop-down').each(function(){
		var w=0;
		$(this).find('li').each(function(){
			w+= $(this).outerWidth();
		});
		w+=20;
		$(this).css({ 'width': w+'px' });
	});
	
	$('#navigation li').each(function(){
		var a = $(this).find('a:eq(0)');
		var drop = $(this).find('.drop-down:eq(0)');
		if( !a.hasClass('active') ){
			drop.hide();
		}
	});
	
	$('#navigation li').hover(
		function(){
			var a = $(this).find('a:eq(0)');
			var drop = $(this).find('.drop-down:eq(0)');
			if( a.hasClass('active') ){
				return;
			}
			
			a.addClass('hover');
			drop.show();
		},
		function(){
			var a = $(this).find('a:eq(0)');
			var drop = $(this).find('.drop-down:eq(0)');
			if( a.hasClass('active') ){
				return;
			}
			a.removeClass('hover');
			drop.hide();
		}
	);
	
	$('.questions-link a').click(function(){
		var cnt = $(this).parent().parent().find('.question-content:eq(0)');
		
		if( cnt.css('display') == 'none' ) {
			cnt.show();
			$(this).addClass('active');
		}else {
			cnt.hide();
			$(this).removeClass('active');
		}
		return false;
	})
	
	
	
});

function start_slides( item, time, callback ) {
	var all_items = $( item ).length;
	if ( all_items < 1 ) return;
	var zindex = all_items;
	var i=0;
	$( item ).each( function(){
		$( this ).css( { 'z-index': zindex } );
		if ( i > 0 ) $( this ).hide();
		zindex--;
		i++;
		var img = new Image();
		img.src = $( this ).attr('src');
	});
	
	var index = 0;
	var next;
	var time = time || 5000;
	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);
}