// global site url var
var site_base_url = $('base').attr('href');

var maxPheight;
var maxHheight;

var fancySettings = {
	'hideOnContentClick':	false,
	'cyclic'			:	true,
	'margin'			:	60,
	'centerOnScroll'	:	true,
	'overlayOpacity'	:	0.8,
	'overlayColor'		:	'#b4b0af',
	'speedIn'			:	600, 
	'speedOut'			:	200, 
	'overlayShow'		:	true,
	'showCloseButton'	:	true,
	'titlePosition' 	:	'inside',
	'titleFormat'		:	formatTitle
}

// DOM load
$(function() {
	
	/* 
		$('a.media').mediabox({autoplay:1, caption:0, loadingImage: 'loader.gif'}); 
	*/
	
	/*
	// image europe imagemap mouseover
	if($('.prodsite').length >= 1)
	{
		
		$('.prodsite').hide();
		$('.prodsite:first').show();
		
		$("area").hover(function()
		{
			
			var href = $(this).attr('href');
			var div = $(href);
			wc(href);
			
			if(div.length > 0)
			{
				$('.prodsite').hide();
				div.show();
			}
		}, function()
		{
		
		});
	}
	*/
	
	/* Fancybox Using custom settings */
	$('a:has(img)',$('div.thumbnail')).fancybox(fancySettings);
	
	/* 
		milestones 
	*/
	$("li a",
		$('#milestones .timeline ul')
		.mouseleave(function(){
			$("#milestones div.overview div")
			.stop(false,true)
			.slideUp();
		})
	)
	.mouseenter(function(){
		
		var position = $(this).position();
		var count = 0;
		
		$("#milestones div.overview div:not(." + $(this).attr('class') + ")")
		.stop(false,true)
		.hide();
		
		$("#milestones div.overview div." + $(this).attr('class'))
		.each(function(){
			
			var left = count * 128;
			var xpos = (position.left - left);
			
			$('h4',
				$(this)
				.css({
					"left": xpos + "px",
					"bottom" : "0px",
					"opacity": 0.90,
					'z-index': '-'+count
				})
				.addClass('visible')
				.slideDown()
			).css({
				'opacity':function(){
					return count > 0 ? 0 : 0.90;
				}
			});
			
			count++;
		});
		
	})
	.mouseleave(function(){
		$("#milestones div.overview div:not(." + $(this).attr('class') + ")")
		.stop(false,true)
		.slideUp();
	});
	

});


/* window load (NOT DOM) */
$(window).load(function(){
   
	// style height van logo's in country brands
	if( $('div.panel.brand',$('#pagecontent')).length > 1){
	
		maxPheight = 0;
		maxHheight = 0;
		
		var count = 1;
		
		$('div.panel.brand',$('#pagecontent'))
		.each(function(){
		
			var theP = $('div.image:first',$(this)).height();
			var theH = $('h3:first',$(this)).height();
			
			if(theP > maxPheight){
				maxPheight = theP;
			}
			
			if(theH > maxHheight){
				maxHheight = theH;
			}
			
			count++;
		});
		
		if(maxPheight <= 16	){
			maxPheight = 80;
		}
		
		//$('img',
			$('div.panel.brand div.image',$('#pagecontent'))
			.css({
				
				'height':maxPheight +'px',
				'margin-bottom':'0px',
				'vertical-align':'middle',
				'position':'relative',
				'top':function(i,e){
				
					//var thisH = $(this).height();
					//var lH = (maxPheight - thisH);
					//var pad = Math.floor(lH / 2);
					
					//return pad + 'px';
					
					return ($(this).height()/2) - ($('img:first',$(this)).height()/2) + "px";
				}
			})
		/*).css({
			'padding-top':function(i,e){
			
				//var thisH = $(this).height();
				//var lH = (maxPheight - thisH);
				//var pad = Math.floor(lH / 2);
				
				//return pad + 'px';
				
				return $(this).parent().height()/2 - $(this).height()/2 + "px";
				
			}
		});*/
		
		$('div.panel.brand h3',$('#pagecontent'))
		.css({
			'height':maxHheight +'px'
		});
		
	}
	
});


function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="fancydescription">' + (title && title.length ? '<b>' + title + '</b><br/>' : '' ) + (currentArray.length > 1 ? '<span id="fancypagecount"><a href="javascript:;" onclick="$.fancybox.prev();">&#8249;&#8249; prev </a> &#160; Image ' + (currentIndex + 1) + ' of ' + currentArray.length + ' &#160; <a href="javascript:;" onclick="$.fancybox.next();"> next &#8250;&#8250;</a></span>' : '') +'</div>';
}

function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}
