$(document).ready(function () {
	
	/*
	 * Animation for header
	 */
	
	$('#header_list').innerfade({ speed: 1500, timeout: 7000, type: 'sequence', containerheight: '292px' }); 
	
	/*
	 * Slider interval
	 */
	
	// Check if element exists
	if ($('#item1').length > 0 ) {
		
		animateAccordeon ();
		
		var interval = 7000;
		var slider = setInterval(animateAccordeon, interval);
		
		/*
		 * Slider mouseaction
		 */
		
		$('.item').each(function () {
			
			$(this).mouseover(function () {
				
				clearTimeout (slider);
				animateAccordeonHover($(this).attr('id'));
			});
		});
	}	
});

/*
 * Header accordeon
 */

function animateAccordeon() {

    // Get active item
	var activeID = $('#header_content_right ul .active').attr('id');
	activeID = activeID.substring(activeID.length - 1, activeID.length);

	switch (activeID) {
	
		case '1':
			
			// Animate
			$('#item2').stop().animate({width: '57px'}, {duration:1000 });
			$('#item3').stop().animate({width: '38px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '2':
			
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '38px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '3':
			
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '287px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '4':
		
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '287px'}, {duration:1000 });
			$('#item4').stop().animate({width: '268px'}, {duration:1000 });
			
			break;
	}
	
	if (activeID == 4) {
		nextID = 1;
	} else {
		nextID = parseInt(activeID) + 1;
	}	

	$('.item').removeClass('active');
	$('.item').addClass('inactive');
	$('#item' + nextID).removeClass('inactive');
	$('#item' + nextID).addClass('active');
}	

/*
 * Header accordeon mouseover
 */

function animateAccordeonHover(newID) {

	newID = newID.substring(newID.length - 1, newID.length);
	
	switch (newID) {
	
		case '1':
			
			// Animate
			$('#item2').stop().animate({width: '57px'}, {duration:1000 });
			$('#item3').stop().animate({width: '38px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '2':
			
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '38px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '3':
			
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '287px'}, {duration:1000 });
			$('#item4').stop().animate({width: '19px'}, {duration:1000 });
			
			break;
		
		case '4':
		
			// Animate
			$('#item2').stop().animate({width: '306px'}, {duration:1000 });
			$('#item3').stop().animate({width: '287px'}, {duration:1000 });
			$('#item4').stop().animate({width: '268px'}, {duration:1000 });
			
			break;
	}
	
	$('.item').removeClass('active');
	$('.item').addClass('inactive');
	$('#item' + newID).removeClass('inactive');
	$('#item' + newID).addClass('active');
}


