$(document).ready(function() {
	
	if (sel_menu.length > 1) {
		
		//alert (sel_amount);
		
		var element = document.getElementById(sel_menu);
		var newh = 23 + sel_amount + (20 * sel_amount);
		
		//alert (newh);
		
		$(element).animate({ 
		 	height: newh + "px"
		}, "slow" );
	}
	
	$('.fade_pics').cycle('fade');
	
	
	/**
	 * Home header
	 */

	var items = $('#header-con ul#header-images li');

	// Custom animation
	$("ul#blocks li").mouseenter(function(){

		if (!$(this).hasClass("active")) {
		
			var title = $(this).attr('id').replace('block_', '');
	
			active_img = $('#header-con ul#header-images li.active');
			active_block = $('#header-con ul#blocks li.active');
	
			slide_img = $('#header-con ul#header-images li#' + title);
	
			// Remove active
			active_img.removeClass('active');
			active_block.removeClass('active');
	
			slide_img.addClass('active');
			$(this).addClass('active');
	
			var next_item = title.replace ('nr', '');
	
			//$(active_img).fadeOut(1000);
			//$(slide_img).fadeIn (1000);
	
			$(active_img).css ("display", "none");
			$(slide_img).css ("display", "block");
			
			clearInterval(loader);
	
			loader = setInterval (function () {
	
				// Remove active
				active_img = $('#header-con ul#header-images li.active');
				active_block = $('#header-con ul#blocks li#block_' + $(active_img).attr('id') + '.active');
	
				// Calculate next
				next = items.index(active_img) + 1;
	
				// Check for offset
				if (next == items.length) {
					next = 0;
				}
	
				// Fetch next
				slide_img = items.get(next);
				slide_block = $('#header-con ul#blocks li#block_' + $(slide_img).attr('id'));
	
				// Remove active
				$(active_img).removeClass('active');
				$(active_block).removeClass('active');
	
				$(slide_img).addClass('active');
				$(slide_block).addClass('active');
	
				//$(active_img).fadeOut(1000);
				//$(slide_img).fadeIn (1000);
				
				$(active_img).css ("display", "none");
				$(slide_img).css ("display", "block");
	
			}, 7000);
		}

	});

	if (items.length > 1) {

		$('#header-con ul#header-images li').css ("display", "none");
		$('#header-con ul#header-images li.active').css ("display", "block");

		loader = setInterval (function () {

			// Remove active
			active_img = $('#header-con ul#header-images li.active');
			active_block = $('#header-con ul#blocks li#block_' + $(active_img).attr('id') + '.active');

			// Calculate next
			next = items.index(active_img) + 1;

			// Check for offset
			if (next == items.length) {
				next = 0;
			}

			// Fetch next
			slide_img = items.get(next);
			slide_block = $('#header-con ul#blocks li#block_' + $(slide_img).attr('id'));

			// Remove active
			$(active_img).removeClass('active');
			$(active_block).removeClass('active');

			$(slide_img).addClass('active');
			$(slide_block).addClass('active');

			//$(active_img).fadeOut(1000);
			//$(slide_img).fadeIn (1000);
			
			$(active_img).css ("display", "none");
			$(slide_img).css ("display", "block");

		}, 7000);

	}
	
});
