function showmenu()
{
	
	repositionMenu();
	$('#MODMenu').fadeIn("slow");
	//$('#MODMenuFadeBg').attr('style', "background-color:#000000;width:100%;height:100%;position:fixed;top:0px;left:0px;z-index:3;")
	
	
	$('#MODMenuFadeBg').fadeTo("slow", 0.75);
	//alert("#MODMenuFadeBg = " + document.getElementById("MODMenuFadeBg").style.zIndex + ", MODMenu = " + document.getElementById("MODMenu").style.zIndex);
}

function repositionMenu(){
    // IE has a z-index issue (if you try and apply a z-index to something in another DIV)
    var MODContent = $("#MODContent");
	var offset = MODContent.offset();
	var offsetTop = offset.top + 100;
	$('#MODMenu').css("position","absolute"); // Move it to be absolutely positioned relative to the parent MODContent.
	$('#MODMenu').css("left",offset.left + "px"); // Move it to be 100px from the top.
	$('#MODMenu').css("top",offsetTop + "px"); // Move it to be 100px from the top.

	$('#MODMenu').css("z-index","8"); // Move it to be absolutely positioned relative to the parent MODContent.
	//ie_apply_zindex('#MODMenu', 8) // IE z-index fix.
	
	$('#MODMenuFadeBg').attr('style', "background-color:#000000;width:"+MODContent.innerWidth()+"px;height:"+MODContent.innerHeight()+"px;position:absolute;top:"+offset.top+"px;left:"+offset.left+"px;z-index:3;")
	$('#MODMenuFadeBg').fadeTo(0, 0);	
}

function onBrowserResize(){
    shownewhome();
    repositionMenu();
}

function shownewhome()
{
	// IE has a z-index issue (if you try and apply a z-index to something in another DIV)
	var MODContent = $("#MODContent");
	var offset = MODContent.offset();
	var offsetTop = offset.top + 130;
	$('#MODHomePage').css("position","absolute"); // Move it to be absolutely positioned relative to the parent MODContent.
	$('#MODHomePage').css("left", offset.left + "px"); // Move it to be 100px from the top.
	$('#MODHomePage').css("top",offsetTop + "px"); // Move it to be 100px from the top.

	$('#MODHomePage').css("z-index","2"); // Move it to be absolutely positioned relative to the parent MODContent.
	//ie_apply_zindex('#MODMenu', 8) // IE z-index fix.
	//$('#MODHomePage').fadeIn("slow");
}

function hidenewhome()
{
	$('#MODHomePage').fadeOut("slow");
}

function hidenewhomefast()
{
	$('#MODHomePage').hide();
}

function hidemenu()
{
	$('#MODMenu').fadeOut("slow");
}

function showtext1()
{
	$('#MODMissionText1').fadeIn("slow");
}

function showtext2()
{
	$('#MODMissionText2').fadeIn("slow");
}

function showtext3()
{
	$('#MODMissionText3').fadeIn("slow");
}

function showtext4()
{
	$('#MODMissionText4').fadeIn("slow");
}

function hidetext1()
{
	$('#MODMissionText1').fadeOut("slow");
}

function hidetext2()
{
	$('#MODMissionText2').fadeOut("slow");
}

function hidetext3()
{
	$('#MODMissionText3').fadeOut("slow");
}

function hidetext4()
{
	$('#MODMissionText4').fadeOut("slow");
}

function hideall()
{
	$('#MODMissionText1').hide();
	$('#MODMissionText2').hide();
	$('#MODMissionText3').hide();
	$('#MODMissionText4').hide();
	$('#MODMenu').hide();
	$('#MODMenuFadeBg').fadeTo("slow", 0);
	$('#MODMenuFadeBg').attr('style', "display:none");
	$('#MODRegisterContainer').hide();
	$('#MODLoginContainer').hide();
	$('#MODEditDetailsContainer').hide();
	$('#MODContactUsContainer').hide();
}

function hideit()
{
	$('#MODFader').fadeTo(0, 0);
	$('#MODFader').attr('style', "display:none");
}

function hideitslow()
{
	$('#MODFader').fadeOut("slow"); // note: the line below seems to negate this line. Not sure whether to remove it.
	$('#MODFader').attr('style', "display:none") ;
}

function showme()
{
		showme_refactored('MODRegisterContainer');
}

function showedit()
{
		showme_refactored('MODEditDetailsContainer');
}

function hideme()
{
	$('#MODRegisterContainer').fadeOut("slow");
}

function trans()
{
	//$('#MODRegisterBG').fadeTo(0, 0.7);
}

function showmelogin()
{
		showme_refactored('MODLoginContainer');
}

function hidemelogin()
{
	$('#MODLoginContainer').fadeOut("slow");
	$('#MODFader').fadeOut("slow");
}

function hideedit()
{
	$('#MODEditDetailsContainer').fadeOut("slow");
	//$('#MODFader').fadeOut("slow");
}

function showme_refactored(id, offsetX, offsetY,faderAlpha)
{
    var MODContent;
	try
	{
		// Position the login box correctly (i.e. override the accessible positioning if JS disabled)
		MODContent = $("#MODContent");
		var offset = MODContent.offset();
		var offsetLeft = offset.left + ((offsetX)?offsetX:50);
		var offsetTop = offset.top + ((offsetY)?offsetY:50);
		$('#'+id).css("position","absolute"); // Move it to be absolutely positioned relative to the parent MODContent.
		$('#'+id).css("left",offsetLeft + "px"); // Move it to be 100px from the top.
		$('#'+id).css("top",offsetTop + "px"); // Move it to be 100px from the top.
	}
	catch(er)
	{
		$('#'+id).css("position","absolute"); // Move it to be absolutely positioned relative to the parent MODContent.
		$('#'+id).css("left","100px"); // Fall-back positioning.
		$('#'+id).css("top","100px"); // Fall-back positioning.
	}

    // BC
    if((faderAlpha==undefined || faderAlpha!=-1) && MODContent){
	    //$('#MODFader').attr('style', "background-color:#000000;width:100%;height:1500px;position:absolute;top:0px;left:0px;z-index:3;")
	    $('#MODFader').attr('style', "height:"+(MODContent.innerHeight()+600)+"px;position:absolute;top:"+MODContent.offset().top+"px;left:"+MODContent.offset().left+"px;z-index:3;")
	    $('#MODFaderMask').attr('style', "background-color:#000000;width:"+MODContent.innerWidth()+"px;height:"+MODContent.innerHeight()+"px;")
	    $('#MODFader').fadeTo(0, 0);
	}

    // Show the login box.
    $('#'+id).fadeIn("slow");

    if(faderAlpha==undefined || faderAlpha!=-1){
        $('#MODFader').fadeTo("slow", ((faderAlpha)?faderAlpha:0.75));
    }
}

function hideme_refactored(id)
{
	$('#'+id).fadeOut("slow");
	$('#MODFader').fadeOut("slow");
}

function toggleShow(id, doHide)
{
		var elem = document.getElementById(id);
		if(elem){
				if(doHide)
				{
						$('#'+id).hide();
						$('#'+id).addClass('hide');	
				}
				else{
						$('#'+id).fadeIn("slow");		
						$('#'+id).removeClass('hide');	
				}
		}
		
}

function registerForEvent(loggedIn){
    
    if(loggedIn){
        $('#MODEventRegistration').css("display","block");
        showme_refactored('MODEventRegistrationContainer',570,230,-1);
        
    }
    else
    {
        showme_refactored('MODLoginContainer',546,200);
    }
    
    return false;

}

var alreadySubmitted = new Array();
function submitOnce(elem){
    if(elem){
        if(elem.id){
            if(alreadySubmitted[elem.id]){
                return false;
            }else{
                alreadySubmitted[elem.id] = true;
                return true;
            }
        }
    }
}


function pageLoaded(sender, args)
{
    // clear array
    if(alreadySubmitted){
        alreadySubmitted = new Array();
    }
}

