var iTimerID;
var activeDIV;

currentDiv=0;

function vp() {
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}
 
function f_update_size() {
	var v = new vp;
	document.getElementById("_disable").style.width = v.windowX + "px";
	pageY = (document.body.scrollHeight > v.windowY)?document.body.scrollHeight:v.windowY;
	document.getElementById("_disable").style.height = pageY + "px";
	if(current_page=='/')
	{
		document.getElementById("_disable").style.height = "950px";
	}
}
 
function f_disable(on_off, id) {
	if(on_off == true) {
		activeDIV = id;
		iTimerID = window.setInterval("f_update_size()", 100);
		document.getElementById("_content").disabled = true;
		document.getElementById("_disable").style.display= "block";
	} else {
		activeDIV = null;
		clearInterval(iTimerID);
		document.getElementById("_content").disabled = false;
		document.getElementById("_disable").style.display="none";
	}
}

function f_centerDIV() {
	try {
		var v = new vp;
		var obj = document.getElementById(activeDIV);
		obj.style.display = "block";
		obj.style.left = (v.windowX - obj.clientWidth) / 2  + "px";
		if((window.innerHeight || document.body.offsetHeight) > obj.clientHeight + 100) {
			obj.style.top = 100;
		} else {
			obj.style.top = (((window.innerHeight || document.body.offsetHeight)- obj.clientHeight)  / 2) + v.scrollY + "px";
		}
		
		if((((window.innerHeight || document.body.offsetHeight)- obj.clientHeight)  / 2)<0)
		{
			obj.style.top="100px";
		}
		obj.style.display = "block";
	} catch(e) { }
}

function pe_slideshow1 ()
{
	var photo = $('#large_photo1>img');

	next_photo = (current_photo+1 < photo.length) ? current_photo+1 : 0;
	$(photo[current_photo]).animate({'opacity':0}, 2000);
	$(photo[next_photo]).animate({'opacity':1}, 2000);
	
	current_photo = next_photo;
	
	setTimeout(pe_slideshow1, 5000);
}

function pe_slideshow2 ()
{
	var photo = $('#large_photo2>img');

	next_photo = (current_photo+1 < photo.length) ? current_photo+1 : 0;
	$(photo[current_photo]).animate({'opacity':0}, 2000);
	$(photo[next_photo]).animate({'opacity':1}, 2000);
	
	current_photo = next_photo;
	
	setTimeout(pe_slideshow2, 5000);
}

function prompt_show() {
	f_disable(true, "div_login");
	f_centerDIV();
	document.frmLogin.username.focus();
}
 
function prompt_close() {
	f_disable(false);
	if(current_page=='/crew-management')
	{
		current_page='/working-at-ara';
	}
	if (current_page.indexOf("/fleet-management") !=-1) 
	{
		current_page='/fleet';
	} 
	document.location.replace(""+current_page);
	document.getElementById("framePrompt").src = "about:blank";
	document.getElementById("div_login").style.display= "none";
}

function pr() {
	this.show = prompt_show;
	this.close = prompt_close;
}

function pe_lookup()
{
	
	var lookup = $('#to_lookup>div');
	$(lookup[currentDiv]).hide('slide',{ direction:"down" },1000,function(){
		currentDiv=currentDiv+1;
		if($('#to_lookup>div').length==(currentDiv))
		{
			currentDiv=0;
		}
		$(lookup[currentDiv]).show('slide',{ direction:"down" },1000);
	});
	
	setTimeout(pe_lookup, 4000);
}

$(document).ready(function() {
if( $('#to_lookup>div').length > 1 ) 
{
	var lookup = $('#to_lookup>div').hide();
	//alert(lookup.length);
	
	rand_no = Math.random();
	//currentDiv  = Math.ceil(lookup.length * rand_no);
	currentDiv=0;
	
	$(lookup[currentDiv]).show('slide',{ direction:"down" },1000);
	setTimeout(pe_lookup, 4000);
	
	if( $('#large_photo1>img').length > 1 ) 
	{
		var photo = $('#large_photo1>img').css({'opacity':0});
		$(photo[0]).css({'opacity':1});
		current_photo=0;
		
		
		setTimeout(pe_slideshow1, 5000);
	}
	if( $('#large_photo2>img').length > 1 ) 
	{
		var photo = $('#large_photo2>img').css({'opacity':0});
		$(photo[0]).css({'opacity':1});
		current_photo=0;
		
		
		setTimeout(pe_slideshow2, 5000);
	}
	
	Shadowbox.init();
}

$("#wrapper").mousemove(function(e){
      var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
      var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
      
      if(oldslide!='subMenu34'&&oldslide!='')
      {
	      if(e.pageY>($('#'+oldslide).outerHeight()+183))
	      {
	      	slideMenu('subMenu34');
	      }
	      var offset = $('#'+oldslide).offset();

	      if(e.pageX>($('#'+oldslide).outerWidth()+offset.left))
	      {
	      	slideMenu('subMenu34');
	      	//alert("Here!");
	      }
	      if(e.pageX<offset.left)
	      {
	      	slideMenu('subMenu34');
	      }
      }
      
      if(e.pageY>450)
      {
      	slideMenu('subMenu34');
      }
});


});

