function SWFDelegate(url,width,height,caption) {
	var objLink = document.createElement('a');
	
	objLink.setAttribute('href',url);
	objLink.setAttribute('rel','lightbox');
	objLink.setAttribute('title',caption);
	
	if(typeof width != 'undefined') {
		objLink.setAttribute('width',width);
	}
	
	if(typeof height != 'undefined') {
		objLink.setAttribute('height',height);
	}
	
	lightBox.prototype.start(objLink);
}


function str_replace(search, replace, subject) {
    var _is_array = function(mixed_var) {
        return (mixed_var instanceof Array);
    };
    
    var f = search, r = replace, s = subject;
    var ra = _is_array(r), sa = _is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
     
    return sa ? s : s[0];
}


var lm_parsing = true;
function initMenu()
{
	pos = $('#swf').position();
	$('#left_menu').css('left', pos.left+'px');
	$('#left_menu').css('top', pos.top+30+100+'px');
	$('#left_menu').show();
	
	
	// rewrite uri
	if(lm_parsing)
	{
		$('#left_menu a').each(function (){
		
			ID = $(this).attr('id');
			
			//  lm replace by null
			ID = str_replace('lm', '', ID);
			
			bkg = $(this).attr('SWFBackground');
			
			$(this).attr('href', 'javascript:setMenuSelected('+ID+'); loadAnimation(\''+bkg+'\','+ID+'); ');
			// $(this).attr('onclick', 'loadAnimation(\''+bkg+'\','+ID+'); return false;');
			
		});
	}
	
}


function initContent()
{
	pos = $('#swf').position();
	if($.browser.msie)
		$('#content').css('top', pos.top+20+'px');
	else
		$('#content').css('top', pos.top+'px');
		
	$('#content').css('left', pos.left+'px');
	$('#content').show();
}


var bmenus = new Array('comlux_fleet', 'bm_comlux_news', 'comlux_gallery', 'quick_access');
var bmenu_open = false;
var bmenu_last_open = ''; // indice de 1 � 4

function bottomMenuHideAll()
{
	hideBottomMenu('');
		
	ni = $('#BImage'+bmenu_last_open).attr('src');
	ni = str_replace('-over', '', ni);
	$('#BImage'+bmenu_last_open).attr('src', ni);
	
	bmenu_open = false;
	$('#protectorT').hide();
	$('#protectorL').hide();
	$('#protectorR').hide();
}

function initProtector(target, t, l)
{		
	if($.browser.msie)
	{
		pos = $('div#'+target).position();
		t = pos.top*-1;	
		l = pos.left*-1;
		t -= $('div#'+target).height();
		
		if($.browser.msie)
		{
			if(target == 'bm_comlux_news')l += 150;
			else if(target == 'comlux_gallery')l += 305;
			else if(target == 'quick_access')l += 457;
		}		
	}

	// protector Top
	$('#protectorT').width($('div#'+target).width()+25);
	$('#protectorT').height(100);
	$('#protectorT').css('top', t - 100 +'px');
	$('#protectorT').css('left',  l +'px');
	$('#protectorT').show();
	
	// protector Left
	$('#protectorL').width(50);
	$('#protectorL').height($('div#'+target).height() + 150);
	$('#protectorL').css('top', t - 100 +'px');
	$('#protectorL').css('left',  l - 50 +'px');
	$('#protectorL').show();
	
	// protector Right
	$('#protectorR').width(50);
	$('#protectorR').height($('div#'+target).height() + 150);
	$('#protectorR').css('top', t - 100 +'px');
	$('#protectorR').css('left',  l + $('div#'+target).width() + 25 +'px');
	$('#protectorR').show();	
}

function getElementPosition(objID)
{
	return $(objID).position();
}

function initBottomMenu()
{

	// D�tection IE6
	var IE6 = false 

	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0); 
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);

	if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;
	//
	
	
	// com_fleet: BImage1
	// news: BImage2 
	// comlux_gallery: BImage3
	// quick_access : BImage4

	// fleet ****************************************************************************************
	$('#BImage1').parent().click(function (){		
		
		if(bmenu_open)
		{
			bottomMenuHideAll();
			if(bmenu_last_open == 1)
			{
				return;
			}
		}
		
		bmenu_last_open = 1;
		
		// hideBottomMenu('comlux_fleet');
		$('#BImage1').attr('src', str_replace('mb1.gif', 'mb1-over.gif', $('#BImage1').attr('src')));
		
		pos = $(this).position();
		if($.browser.msie && !IE6)
		{
			t = 0 - $('div#comlux_fleet').height();
			l = 0;
			//alert(navigator.userAgent);
		}
		else if(IE6){
			
			//alert("IE6");
			t = pos.top + 25;
			l = pos.left;
			
		}else{		
			
			t = pos.top - $('div#comlux_fleet').height() - 5;
			l = pos.left;
		}		
		
		$('div#comlux_fleet').css('top', t+'px');
		$('div#comlux_fleet').css('left', l+'px');
		
		initProtector('comlux_fleet', t, l);		
		
		$('div#comlux_fleet').show();
		bmenu_open = true;
	});	
	

	// news ****************************************************************************************
	$('#BImage2').parent().click(function (){
											   
		if(bmenu_open)
		{
			bottomMenuHideAll();
			if(bmenu_last_open == 2)
			{
				return;
			}
		}	
		bmenu_last_open = 2;
		
		//hideBottomMenu('bm_comlux_news');
		$('#BImage2').attr('src', str_replace('mb2.gif', 'mb2-over.gif', $('#BImage2').attr('src')));
		
		pos = $(this).position();
		if($.browser.msie && !IE6)
		{
			t = 0 - $('div#bm_comlux_news').height();
			l = 150;
			
		}else if(IE6){
			
			//alert("IE6");
			t = pos.top + 25;
			l = pos.left;
			
		}else{
			t = pos.top - $('div#bm_comlux_news').height() - 5;
			l = pos.left;
		}		
		
		$('div#bm_comlux_news').css('top', t+'px');
		$('div#bm_comlux_news').css('left', l+'px');
		
		initProtector('bm_comlux_news', t, l);		
		
		$('div#bm_comlux_news').show();
		bmenu_open = true;
	});
		
	// gallery ****************************************************************************************
	$('#BImage3').parent().click(function (){
											   
		if(bmenu_open)
		{
			bottomMenuHideAll();
			if(bmenu_last_open == 3)
			{
				return;
			}
			
		}	
		bmenu_last_open = 3;
		
		//hideBottomMenu('comlux_gallery');
		$('#BImage3').attr('src', str_replace('mb3.gif', 'mb3-over.gif', $('#BImage3').attr('src')));
		
		pos = $(this).position();
		if($.browser.msie && !IE6)
		{
			t = 0  -  $('div#comlux_gallery').height();
			l = 305;
		}else if(IE6){
			
			//alert("IE6");
			t = pos.top + 25;
			l = pos.left;
			
		}else{
			t = pos.top - $('div#comlux_gallery').height() - 5;
			l = pos.left;
		}		
		
		$('div#comlux_gallery').css('top', t+'px');
		$('div#comlux_gallery').css('left', l+'px');
		
		initProtector('comlux_gallery', t, l);		
		
		$('div#comlux_gallery').show();
		bmenu_open = true;	   
	});	
		
	
	// quick_access **********************************************************************************
	$('#BImage4').parent().click(function (){
											   
		if(bmenu_open)
		{
			bottomMenuHideAll();
			if(bmenu_last_open == 4)
			{
				return;
			}
			
		}	
		bmenu_last_open = 4;
		
		//hideBottomMenu('quick_access');
		$('#BImage4').attr('src', str_replace('mb4.gif', 'mb4-over.gif', $('#BImage4').attr('src')));
		
		pos = $('#BImage'+bmenu_last_open).position();	
		
		if($.browser.msie && !IE6)
		{
			t =  0  -  $('div#quick_access').height();
			l = 457;
		}
		else if(IE6){
			
			//alert("IE6");
			t = pos.top + 25;
			l = pos.left;
			
		}else{
			t = pos.top - $('div#quick_access').height() - 5;
			l = pos.left;
		}		
		
		$('div#quick_access').css('top', t+'px');
		$('div#quick_access').css('left', l+'px');
		
		initProtector('quick_access', t, l);		
		
		$('div#quick_access').show();
		bmenu_open = true;				   
	});		
	
	
}

function hideBottomMenu(except)
{
	for(i=0; i <  bmenus.length; i++)
	{
		if(bmenus[i] != except)
			$('div#'+bmenus[i]).hide();
	}	
}



function loadAnimation(bkg, pageID)
{
	$('#content').hide();
	document.getElementById('myFlash').loadAnimation(bkg, pageID);
	//loadContent(pageID);
	
}

function loadContent(pageID)
{
	$.get('/en/'+pageID+'.html?ajax=1&target=content&t='+Math.random(), {}, function (data){
		$('#content').html(data);																						  
		$('#content').fadeIn('normal');
		
		loadSlogan(pageID);
		
	});
	
}

function loadSlogan(pageID)
{
	$.get('/en/'+pageID+'.html', {}, function (data){
		
		d = $.trim(data);
		pos1 = d.indexOf('<div id="slogan">');
		pos2 = d.indexOf('</div>', pos1);		
		
		if(pos1 == -1)
		{
			d = '';
		}
		else
		{			
			d = d.substring(pos1, pos2);
			d += '</div>';
			d = $.trim(d);
		}
		$('#top_slogan').html(d);		
		
	});
	
}



function initSitePlan()
{
	/*if($.browser.msie)
	{
		pos = $('#countain').position();
		$('#website_map_content').css('left', pos.left+'px');
		$('#website_map_content').css('top', pos.top+157+'px');
	}
	else
	{
		pos = $('#swf').position();
		$('#website_map_content').css('left', pos.left+'px');
		$('#website_map_content').css('top', pos.top+20+'px');			
	}*/
	// $('#website_map_content').show();
}

function websitePlan()
{		
	$('#website_map_content').toggle();
	
}

function setMenuVisible(bool)
{
	if(!bool)
		$('#left_menu').hide();
	else
		$('#left_menu').show();
}

function setContentVisible(bool)
{
	if(!bool)
		$('#content').hide();
	else
		$('#content').show();
}

function setMenuSelected(id)
{
	// not news page
	if(id != 124 && id != 125 && id != 204)
	{
		$('#left_menu ul a').removeClass();
		$('a#lm'+id).addClass('a_sel');
		
		$('#left_menu ul ul').attr('selected', 0);

		// children ul ?		
		if($.browser.msie && $.browser.version < 8)
		{			
			$('a#lm'+id).parent().children('ul').slideDown('normal');
			
			$('a#lm'+id).parents('ul').attr('selected', 1);	
			
			$('a#lm'+id).parent().parent().parent().children('a').addClass('a_sel')
			$('#left_menu ul ul[selected!=1]').hide();
					
			//$('a#lm'+id).parent().parent().parent().children('ul').hide();			
		}
		else
		{
			$('a#lm'+id).parent().next().slideDown('normal');
			
			$('a#lm'+id).parents('ul').attr('selected', 1);	
			
			
			$('a#lm'+id).parent().parent().prev().children('a').addClass('a_sel');
			
			$('#left_menu ul ul[selected!=1]').hide();
			
			// flag all parents
			//$('#left_menu ul ul').attr('selected', '0');
			//$('a#lm'+id).parents('ul').attr('selected', '1');
			//$('a#lm'+id).childrens('ul').attr('selected', '1');			
		}
		
		//$('#left_menu ul ul[selected!=1]').slideUp('normal').attr('selected', '0');
		
		
	}
	else
	{
		$('#lmcomlux_news a').removeClass();
		$('#comlux_news'+id+' a').addClass('a_sel');
	}	
}


function log(v)
{
	if(!window.console)return;
	window.console.log(v);
}


function flashSetHome(num)
{
	if(!home_detected)return;	
	document.getElementById('myFlash').flashSetHome(num);		
}

function flashCloseHome(num)
{
	if(!home_detected)return;
 	document.getElementById('myFlash').flashCloseHome(num);		
}
