var opensub = "";
var opensubsub = "";
var subHolder = new Array();
var subSubHolder = new Array();
var createHtml = true;
$('#topMenu').hide();
$('#topMenu_bg').hide();
$('#mainContent').hide();
$('#mainContent_bg').hide();
$('#subContent').hide();
$('#subContent_bg').hide();
$('#subSubContent').hide();
$('#subSubContent_bg').hide();
$('#background').hide();
$('#popData').hide();
$('#coverup').show();
history.navigationMode = 'compatible';
$(document).ready(domReady)

var didDom = false;
function domReady() {
	didDom = true;
	if(createHtml) {
		$('#flashContent').hide();
		$('#flashContent').remove();
		var topmenu = $("#topMenu");		
		//$('#subContent div').remove();
		$('#topMenu').before('<div id="background" style="background:url(\'images/bgs/'+pageVar+'.jpg\');background-position: center center; background-repeat: no-repeat; z-index:-1">&nbsp;</div>');
	
		$('#topMenu').remove();
		
		$("#mainContent").transBGdraw();
		$("#subContent").transBGdraw();
		$("#subSubContent").transBGdraw();
		
		
		$("#mainContent").before(topmenu);
		
		$('#topMenu').transBGdraw();
		$("a").not($("a[target*='blank']")).each( function(int) {
			$(this).click(function(event){
			 exit($(this).attr("href"));
			 event.preventDefault();
		 });
		});
		$(".links span").each( function(int) {
			$(this).css("cursor","pointer");
			$(this).click(function(event){
			 sTarget = $(this).attr("id");
			 openSub();
		 });
		});
		
		$(".vidLink").each( function(int) {
			$(this).css("cursor","pointer");
			$(this).click(function(event){
				$('#coverup').fadeTo('slow', 0.5, function() { attachVideo(); });
				$('#coverup').after('<div id="videoHolder">VIDEO</div>');
				$('#videoHolder').hide();
		 });
		});
		
		$(".pagelink").wrapAll("<div id=\"topMenuMid\"></div>");
		
		$('.title').each( function(int) {
			$(this).html($(this).html().toUpperCase());
		});
		//$(".title").spanize()
		//$(".title").textgrad({maxGroup:1,type:'/',colgrad:[{pc:20,col:'D60'},{pc:40,col:'A98'},{pc:70,col:'C40'},{pc:90,col:'000'}],spanize:-1});
		
		$('#topMenu').hide();
		$('#topMenu_bg').hide();
		$('#mainContent').hide();
		$('#mainContent_bg').hide();
		$('#subContent').hide();
		$('#subContent_bg').hide();
		$('#subSubContent').hide();
		$('#subSubContent_bg').hide();
		$('#background').hide();
		$('#coverup').hide();
		$('#popData').hide();
		
		if(subHolder.length == 0) {
			$('#subContent div').each( function(int) {
				var tempContent = Array($(this).attr("id"), $(this).html());
				subHolder.push(tempContent);
				$(this).remove();
			});
		}
		
		if(subSubHolder.length == 0) {
			$('#subSubContent div').each( function(int) {
				var tempContent = Array($(this).attr("id"), $(this).html());
				subSubHolder.push(tempContent);
				$(this).remove();
			});
		}
		
		$('#background').onImagesLoaded(function(_this){
			enter();
		});
		
		$('#topMenu').html($('#topMenu').html().split("(i)").join("<img src=\"images/flm.gif\" border=\"0\" style=\"margin-bottom:-2px;\" />"));
		
		if(pageVar == "jobs") {
			$('#mainContent').css({"width":"280px","margin-left":"-445px"});
			$('#mainContent_bg').css({"width":"280px","margin-left":"-455px"});
			
			$('#subContent').css({"width":"280px","margin-left":"-140px"});
			$('#subContent_bg').css({"width":"280px","margin-left":"-150px"});
		}
		
		$(window).resize(function() {
			resizeHandler();
		});
		resizeHandler();
	}
}

function resizeHandler() {
	var targetX = Math.floor(($(window).width()/2)-800);
	var targetY = Math.floor(($(window).height()/2)-600);
	var targetWidth = 1600;
	var targetHeight = 1200;
	var targetXMargin = 0;
	var targetYMargin = 0;
	if(targetX < 0) {
		targetWidth = $(window).width();
		targetXMargin = targetX;
		targetX = 0;
	}
	if(targetY < 0) {
		targetHeight = $(window).height();
		targetYMargin = targetY;
		targetY = 0;
	}
	//$('#background').css({"left":targetX,"top":targetY,"width":targetWidth,"height":targetHeight,"backgroundPosition":targetXMargin+'px '+targetYMargin+'px'});
} 

function inc(filename)
{	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	$('script').after(script);
}

function enter() 
{
	$('#background').fadeIn(500, enterNext);
	
}
function enterNext() 
{
	$('#topMenu').fadeIn(500);
	$('#topMenu_bg').fadeIn(500);
	
	$('#mainContent').fadeIn(500);
	$('#mainContent_bg').fadeIn(500);
	
}

sTarget = "";
function openSub()
{
	if(opensub == "") {
		sTarget = sTarget;
		opensub = sTarget.split("_btn").join("");
		for(i=0;i<subHolder.length; i++) {
			if(subHolder[i][0] == opensub) {
				$('#subContent').html("");
				$('#subContent').wrapInner(subHolder[i][1]);
			}
		}
		$(".subLinks span").each( function(int) {
			$(this).css("cursor","pointer");
			$(this).click(function(event){
			 sTarget = $(this).attr("id");
			 openSub();
		 });
		});
		$(".brandLink").css({"cursor":"default"});
		$(".brandLink").click(function(event){
		  logoTarget = $(this).attr("id");
			if($("#logoTrgt").attr("src") != "cms/upload/"+logoTarget.split("logo_").join("logo/")) {
				$("#logoTrgt").hide();
				$("#logoTrgt").attr("src","cms/upload/"+logoTarget.split("logo_").join("logo/"));
				$("#logoTrgt").fadeIn('slow');
			}
		});
		$(".brandLink").mouseover(function(event){
		  logoTarget = $(this).attr("id");
			if($("#logoTrgt").attr("src") != "cms/upload/"+logoTarget.split("logo_").join("logo/")) {
				$("#logoTrgt").hide();
				$("#logoTrgt").attr("src","cms/upload/"+logoTarget.split("logo_").join("logo/"));
				$("#logoTrgt").fadeIn('slow');
			}
		});
		$("#bbtn").click(function(event){
			sTarget = "sub_NL_btn";
			openSub();
		})
		$(".storeLink").each( function(int) {
			$(this).click(function(event){
				$('#coverup').fadeTo('slow', 0.8);
				$('#coverup').after('<div id="pop_bg">&nbsp;</div>\n<div id="pop">&nbsp;</div>');
				$('#pop_bg').css({"z-index":"98"});
				
				$('#pop').css({"z-index":"99"});
			//	alert($('#pop').html())
				$('#pop_bg').hide();
				$('#pop').hide();
				storeTrgt = $(this).attr("id");
				setTimeout(setStore, 500)
			//	alert($(this).attr("id"))
				
				//alert("open store: "+$(this).attr("id"));
			});
			$(this).css("cursor","pointer");
		});
		$(".jobLink").each( function(int) {
			$(this).css("cursor","pointer");
			$(this).click(function(event){
			 ssTarget = $(this).attr("id");
			 openSubSub();
		 });
		});
		
		$(".jobLink_open").each( function(int) {
			$(this).click(function(event){
			 ssTarget = $(this).attr("id");
			 openSubSub();
		 });
		});
		
		$('#subContent').fadeIn(500);
		$('#subContent_bg').fadeIn(500);
	}else{
		opensub = "";
		$('#subContent').fadeOut(500);
		$('#subContent_bg').fadeOut(500, openSub);
		
		$('#subSubContent').fadeOut(500);
		$('#subSubContent_bg').fadeOut(500);
	}
}

storeTrgt = "";
function setStore() {
	$('#pop').html($('#store_'+storeTrgt).html());
	//alert($('#pop').html())
	$("#closeStore").each( function(int) {
		$(this).css("cursor","pointer");
		$(this).click(function(event){
			$('#coverup').fadeTo('slow', 0, function() { $('#coverup').hide(); });
			$('#pop').remove();
			$('#pop_bg').remove();
		});
	});
	$('#pop_bg').fadeIn('slow');
	$('#pop').fadeIn('slow');
}

ssTarget = "";
function openSubSub()
{
	if(ssTarget == "none_nl") {
		var trgt = "job/?lang=NL&c=NL";
		if(sTarget == "sub_BE_nl_btn") trgt = "job/?lang=NL&c=BE";
		exit(trgt);
	} else if(ssTarget == "none_fr") {
		var trgt = "job/?lang=FR&c=BE";
		exit(trgt);
	} else if(ssTarget == "none_de") {
		var trgt = "job/?lang=DE&c=DE";
		exit(trgt);
	} else if(ssTarget == "none_en") {	
		var trgt = "job/?lang=EN&c=EN";
		exit(trgt);
	}else{
		if(opensubsub == "") {
			tarr = ssTarget.split("_");
			ssTarget = tarr[0];
			opensubsub = "sub_sub_"+ssTarget;
			//alert(ssTarget);

			if(sTarget == "sub_NL_btn") $('#g2job').html($('#g2job').text().split("- &gt;").join(jlinks[1]+" &gt;"));
			if(sTarget == "sub_BE_nl_btn") $('#g2job').html($('#g2job').html().split("- &gt;").join(jlinks[1]+" &gt;"));
			if(sTarget == "sub_BE_fr_btn") $('#g2job').html($('#g2job').html().split("- &gt;").join(jlinks[2]+" &gt;"));
			if(sTarget == "sub_DE_btn") $('#g2job').html($('#g2job').html().split("- &gt;").join(jlinks[3]+" &gt;"));
			if(sTarget == "sub_UK_btn") $('#g2job').html($('#g2job').html().split("- &gt;").join(jlinks[4]+" &gt;"));
			
			for(i=0;i<subSubHolder.length; i++) {
				if(subSubHolder[i][0] == opensubsub) {
					$('#subSubContent').html("");
					$('#subSubContent').wrapInner(subSubHolder[i][1]);
					$('.openJobLink A').click(function(event) {
						var trgt = String($(this).attr("href"));
						if(sTarget == "sub_NL_btn") trgt = trgt.split("lang=-").join("lang=NL");
						
						if(sTarget == "sub_BE_nl_btn") trgt = trgt.split("lang=-").join("lang=NL");
						
						
						if(sTarget == "sub_BE_fr_btn") trgt = trgt.split("lang=-").join("lang=FR");
						
						
						if(sTarget == "sub_DE_btn") trgt = trgt.split("lang=-").join("lang=DE");
						
						
						if(sTarget == "sub_UK_btn") trgt = trgt.split("lang=-").join("lang=EN");
						
						
						exit(trgt);
						event.preventDefault();
					});
				}
			}		
			if(sTarget == "sub_NL_btn" && $('#g2job')) $('#g2job').html(jlinks[1].toUpperCase()+" &gt;");
			if(sTarget == "sub_BE_nl_btn" && $('#g2job')) $('#g2job').html(jlinks[1].toUpperCase()+" &gt;");
			if(sTarget == "sub_BE_fr_btn" && $('#g2job')) $('#g2job').html(jlinks[2].toUpperCase()+" &gt;");
			if(sTarget == "sub_DE_btn" && $('#g2job')) $('#g2job').html(jlinks[3].toUpperCase()+" &gt;");
			if(sTarget == "sub_UK_btn" && $('#g2job')) $('#g2job').html(jlinks[4].toUpperCase()+" &gt;");
			
			$('#subSubContent').fadeIn(500);
			$('#subSubContent_bg').fadeIn(500);
		}else{
			opensubsub = "";		
			$('#subSubContent').fadeOut(500);
			$('#subSubContent_bg').fadeOut(500, openSubSub);
		}
	}
}


var exitTarget = "";
function exit(target) 
{
	exitTarget = target;/*
	$('#topMenu').fadeOut(500);
	$('#topMenu_bg').fadeOut(500);
	
	$('#subContent').fadeOut(500);
	$('#subContent_bg').fadeOut(500);
	
	$('#subSubContent').fadeOut(500);
	$('#subSubContent_bg').fadeOut(500);
	
	$('#mainContent').fadeOut(500);
	$('#mainContent_bg').fadeOut(500, exitNext1);
*/
	window.location = exitTarget;
}
function exitNext1() 
{
	$('#background').fadeOut(500, exitNext2);
}
function exitNext2() 
{
	window.location = exitTarget;
}

function attachVideo() {
	$('#videoHolder').css({"position":"absolute","width":"640px","height":"380px","top":"50%","left":"50%","margin-left":"-320px","margin-top":"-180px","background-color":"#000","z-index":"99"});
	$('#videoHolder').html('<p style=\"font-weight:bold;text-align: right;cursor: pointer;\" class=\"closeVid\">CLOSE&nbsp;&nbsp;</p>\n<video width="640" height="360" poster="videos/poster.jpg" preload="none" controls>\n<source src="videos/ts_'+pageVar+'.mp4" type="video/mp4"><!-- SAFARI --></source>\n<source src="videos/ts_'+pageVar+'.ogv" type="video/ogg"><!-- OGG --></source>\n<OBJECT id="VIDEO" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"	type="application/x-oleobject" width="640" height="360">\n<PARAM NAME="URL" VALUE="videos/ts_'+pageVar+'.wmv">\n<PARAM NAME="enabled" VALUE="True">\n<PARAM NAME="AutoStart" VALUE="False">\n<PARAM NAME="Mute" VALUE="False">\n<PARAM NAME="fullScreen" VALUE="False">\n<PARAM name="uiMode" value="full">\n</OBJECT>\n</video>');
	$('.closeVid').click(function(event){
		closeVid();
	});
	$('#videoHolder').fadeIn();
}
function attachStoreVideo(trgt) {
	$('#pop').fadeTo('slow', 0, function() { attachStoreVideo2(trgt); });
	$('#coverup').after('<div id="videoHolder">VIDEO</div>');
	$('#videoHolder').hide();
	$('#pop').hide();
	$('#pop_bg').hide();
}
function attachStoreVideo2(trgt) {
	$('#videoHolder').css({"position":"absolute","width":"640px","height":"380px","top":"50%","left":"50%","margin-left":"-320px","margin-top":"-180px","background-color":"#000","z-index":"99"});
	$('#videoHolder').html('<p style=\"font-weight:bold;text-align: right;cursor: pointer;\" class=\"closeVid\">CLOSE&nbsp;&nbsp;</p>\n<video width="640" height="360" poster="videos/poster.jpg" preload="none" controls>\n<source src="videos_stores/'+trgt+'.mp4" type="video/mp4"><!-- SAFARI --></source>\n<source src="videos_stores/'+trgt+'.ogv" type="video/ogg"><!-- OGG --></source>\n<OBJECT id="VIDEO" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"	type="application/x-oleobject" width="640" height="360">\n<PARAM NAME="URL" VALUE="videos_stores/'+trgt+'.wmv">\n<PARAM NAME="enabled" VALUE="True">\n<PARAM NAME="AutoStart" VALUE="False">\n<PARAM NAME="Mute" VALUE="False">\n<PARAM NAME="fullScreen" VALUE="False">\n<PARAM name="uiMode" value="full">\n</OBJECT>\n</video>');
	$('.closeVid').click(function(event){
		closeVid2();
	});
	$('#videoHolder').fadeIn();
}
function closeVid2() {
	$('#videoHolder').remove();
	$('#pop').show();
	$('#pop_bg').show();
	$('#pop').fadeTo('slow', 1);
}


function attachLatestVideo(trgt) {
	$('#coverup').fadeTo('slow', 0.8, function() { attachLatestVideo2(trgt); });
	$('#coverup').after('<div id="videoHolder">VIDEO</div>');
	$('#videoHolder').hide();
}
function attachLatestVideo2(trgt) {
	$('#videoHolder').css({"position":"absolute","width":"640px","height":"380px","top":"50%","left":"50%","margin-left":"-320px","margin-top":"-180px","background-color":"#000","z-index":"99"});
	$('#videoHolder').html('<p style=\"font-weight:bold;text-align: right;cursor: pointer;\" class=\"closeVid\">CLOSE&nbsp;&nbsp;</p>\n<video width="640" height="360" poster="videos/poster.jpg" preload="none" controls>\n<source src="videos_stores/'+trgt+'.mp4" type="video/mp4"><!-- SAFARI --></source>\n<source src="videos_stores/'+trgt+'.ogv" type="video/ogg"><!-- OGG --></source>\n<OBJECT id="VIDEO" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"	type="application/x-oleobject" width="640" height="360">\n<PARAM NAME="URL" VALUE="videos_stores/'+trgt+'.wmv">\n<PARAM NAME="enabled" VALUE="True">\n<PARAM NAME="AutoStart" VALUE="False">\n<PARAM NAME="Mute" VALUE="False">\n<PARAM NAME="fullScreen" VALUE="False">\n<PARAM name="uiMode" value="full">\n</OBJECT>\n</video>');
	$('.closeVid').click(function(event){
		closeVid();
	});
	$('#videoHolder').fadeIn();
}

function closeVid() {
	$('#videoHolder').remove();
	$('#coverup').fadeTo('slow', 0, function() { $('#coverup').hide() });
}

function removeVideo() {
}


function outputStatus(e) {
		//alert("e.success = " + e.success +"\ne.altId = "+ e.altId +"\ne.objId = "+e.objId +"\ne.objRef = "+ e.objRef);
		if(e.success) {
			createHtml = false;
			$('#topMenu').remove();
			$('#topMenu_bg').remove();
			$('#mainContent').remove();
			$('#mainContent_bg').remove();
			$('#subContent').remove();
			$('#subContent_bg').remove();
			$('#subSubContent').remove();
			$('#subSubContent_bg').remove();
			$('#background').remove();
			$('#coverup').remove();
		}
}
