// JavaScript Document

/* Nieuwsbrief messages */

jQuery(document).ready(function(){
	if(jQuery("#top_message").length) {
		jQuery("#top_message").delay(200).animate({
			top: '0px'
		},500, function(){
			jQuery("#top_message").delay(5000).animate({
				top:'-70px'
			});	
		});
	}
	var easing = 'easeOutBack';
	var easing2 = 'linear';
	var isAnimating = false;
	$("<div class=\"sub-menu-info\"></div><img src=\"/wp-content/themes/autokoopadvies/images/menu.png\" class=\"sub-menu-image\" />").appendTo("#mainnav .menu-item-4394");
	$("<span class=\"menu_fall_back\"></span>").prependTo("#mainnav .menu-item-4394");
	
	$("#mainnav .menu-item-4394").mouseenter(function(){
		$(".menu_fall_back").css('height','180px');
		if($(this).find('div').height() < 100) {
			$(this).find('img').animate({
				width: '114px',
				height: '114px',
				left: '8px',
				top: '-82px'
			},300,easing,function(){
				$(".menu-item-4394").find('div').css('background-color','#a42816');
				$(".menu-item-4394").find('div').animate({
					height: '100px',
					top: '35px'
				},400, easing);
				
				$(".menu-item-4394").find('a').animate({
					top: '65px'	
				},400, easing);		
					
				$(".menu-item-4394").find('.sub-menu').css('display','block');
				
				$(".menu-item-4394").find('.sub-menu').css('opacity','1');
				$(".menu-item-4394").find('.sub-menu').delay(280).animate({
					width: '530px',
					height: '450px',
					padding: '5px'
				},600, easing, function(){
					var i = 0;
      				(function displayImages() {
         				$(".menu-item-4394").find('.sub-menu li').eq(i++).fadeIn(20);
						$(".menu-item-4394").find('.sub-menu li').eq(i++).fadeIn(20);
						$(".menu-item-4394").find('.sub-menu li').eq(i++).fadeIn(20,displayImages);
      				})();
				});			
			});				
		}
	});
	
	$(".menu-item-4394").find('a').mouseenter(function(){
		if($(this).css('top') == '65px') {
			$(this).css('background','none')	
		}
	});
	
	$(".menu-item-4394").mouseleave(function(){
		$(".menu_fall_back").css('height','1px');
		$(this).find('.sub-menu,div,a,img').stop();	
		
		$(this).find('.sub-menu').animate({
			width: '0',
			height: '0',
			padding: '0',
			opacity: '0'
		},600, easing,function(){
			$(this).css('display','none');	
			$(".menu-item-4394").find('.sub-menu li').css('display','none');
		});
		
		$("#glow").animate({
			opacity: 0	
		},400);
				
		$(this).find('div').delay(280).animate({
			height: '0px',
			top: '32px'
		},300,easing2);
		
		$(this).find('a').delay(280).animate({
			top: '0px'
		},200, easing2);
			
		$(this).find('img').delay(280).animate({
			width: '0px',
			height: '0px',
			left: '55px',
			top: '32px'	
		},200,easing2);
		
	});
	if(jQuery("#slideshow section img").length > 1) {
		interval = setInterval ( 'changeImage()', 5000 );
	}
});

function changeImage() {
	var index;
	jQuery("#slideshow section img").each(function(){
	
		if(jQuery(this).css('display') != 'none') {
			jQuery(this).fadeOut(1500);
			index = jQuery(this).index();
			if(jQuery(this).attr('class') && jQuery("h1."+jQuery(this).attr('class')).length) {
				jQuery("h1."+jQuery(this).attr('class')).animate({
					left: '-1000px'
				}, 500);
			}
			
		}
	
	});
	
	if(index+1 >= jQuery("#slideshow section img").length) {
		index = 0;
	} else {
		index++;
	}
	
	jQuery("#slideshow section img").eq(index).fadeIn(1500);
	if(jQuery("#slideshow section img").eq(index).attr('class') && jQuery("h1."+jQuery("#slideshow section img").eq(index).attr('class')).length) {
		jQuery("h1."+jQuery("#slideshow section img").eq(index).attr('class')).css('display','block');
		jQuery("h1."+jQuery("#slideshow section img").eq(index).attr('class')).animate({
			left: '0px'
		},500);
	}
	
}
