adiuventia = {
	maps: "" // Path to map images.
}

$(document).ready(function() {

	$("a.trailer").fancybox({
		'overlayShow'        : true,
		'overlayOpacity'     : 0.8,
		'overlayColor'       : '#ffffff',
		'padding'            : 0,
		'centerOnScroll'     : false,
		'showCloseButton'    : true,
		'enableEscapeButton' : true,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false
	});

	$('#head_image').cycle({
		fx:	   'fade',
		speed:	2500,
		speedIn:  2000,
		timeout:  500,
		next:	 '#head_image',
		slideExpr: 'img',
		nowrap: true
	});

	$('#head_image').css({position: 'relative'}).each(function() { 

		var $head_container = $(this);

		// Create a div container for the maps
		var div = document.createElement('div');
		var $div = $(div);
		$div.css({
			position: 'absolute',
			top: 0,
			left: 0,
			width: $head_container.width() + 'px',
			height: $head_container.height() + 'px',
			zIndex: 99,
			backgroundImage: 'url('+adiuventia.maps + 'world.jpg)',
			opacity: 0
		});

		$head_container.append($div);

		// World map.
		$('#language').hover(
			function() { // over
				$div.stop().fadeTo(500,1);
			},
			function() { // out
				$div.stop().fadeTo(500,0);
			}
		);

		// Country maps.
		$('#language .maps span').css({cursor: 'default'}).each(function() {
			var $this = $(this);
			var src = adiuventia.maps + $this.attr('class') + '.jpg';
			var img = new Image();
			var $img = $(img);
			$(img).load(function() {
				// Just append the img to the map div and make sure its positioned right.
				$div.append($img.css({position: 'absolute', opacity: 0, top: 0, left: 0}));
				// Once the image is loaded we can define the mouseover/out actions.
				$this.hover(
					function() {
						$img.stop().css({zIndex: 1}).fadeTo(500,1);
					},
					function() {
						$img.stop().css({zIndex: 0}).fadeTo(500,0);
					}		
				);
			});
			img.src = src;

		});

	}); // end each head_image

	$('#services .row').each(function() {
		var $row = $(this);
		var color	= '#000000';//$row.css('color');
		var bgcolor	= '#e7e8e9';//$row.css('background-color');
		
		// Disable the :hover CSS by using inline styles.
		$row.css({
			color: color,
			backgroundColor: bgcolor
		});
		
		$row.hover(
			function() {
				$row.stop().animate({color: '#fff', backgroundColor: '#6a6f75'},{duration:1000,easing:'easeOutExpo'});
			},
			function() {
				$row.stop().animate({color: color, backgroundColor: bgcolor},{duration:1000, easing: 'easeOutExpo'});
			}
		);		
	
	});

});
