﻿//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
var ClassLink = "";
function checkAnchor() {    
    if (currentAnchor != document.location.hash) {
        currentAnchor = document.location.hash;
        
        if (!currentAnchor) {                
            query = "CH";
        }
        else {
                     
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
            var splits = currentAnchor.substring(1).split('&');
            //Get the section
            var section = splits[0];
            delete splits[0];
            //Create the params string
            var params = splits.join('&');
            //to split the id and opwp from the section
            var sect = section.split('o');
            section = sect[0];
            var query = "section=" + section + params;

			document.getElementById("banner").src = "Banner/" + section + ".png";
			$("#Content").fadeOut(500);
			setTimeout("showPage('" + section + "','" + query + "')", 500);

			if (splits.length == 3) {
			    var spl = splits[1].split('=');
			    if (document.getElementById(spl[1]).style.display == "none") {
			        SlidIt_Sub(spl[1]);
			    }
			    var spl2 = splits[2].split('=');
			    var sp = spl[1].split('u'); //to split Menu and id
			    SetSubColor_Sub(section + "_Link", sp[1] + "_Link", spl2[1] + "_Link");
			}
			if (splits.length == 2) {			    
			    var spl = splits[1].split('=');
			    if (document.getElementById(spl[1]).style.display == "none") {
			        SlidIt(spl[1]);

			    }
			    var sp = spl[1].split('u'); //to split Menu and id
			    SetSubColor(section + "_Link", sp[1] + "_Link");
			}
			if (splits.length == 1) {
			    var id = section + "_Link";
			    if (document.getElementById(id) != null)			    
			        SetColor(section + "_Link");
			}
        }        
	}
}

function SetColor(id) {
    RestATag();
    document.getElementById(id).style.color = "#223467";    
}

function SetSubColor(id, Mid) {
    RestATag();
    document.getElementById(id).style.color = "#223467";
    document.getElementById(Mid).style.color = "#223467";
}
function SetSubColor_Sub(id, Mid, Sid) {
    RestATag();
    document.getElementById(id).style.color = "#223467";
    document.getElementById(Mid).style.color = "#223467";
    document.getElementById(Sid).style.color = "#223467";
}
function RestATag() {
    var a = document.getElementsByTagName("a");
    for (var i = 0; i < a.length; i++) {
        a[i].style.color = "";
    }
}

function showPage(section, query) {
	$.ajaxSetup({ cache: false });
	$("#Content").empty().html('<div style="text-align:center;"><br /><br /><br /><br />'
								+ '<br /><img src="../Images/ajax-loader.gif" algin="center" /></div>');
	if (section == "8") { // For Board of Directros Module
	    $.get("Board.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	else if (section == "9") { // For Executive Managers Module
	    $.get("Executive.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	else if (section == "39") { // For Working for OPWP Module
	    $.get("WorkingForOPWP.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);

	    });
	}
	else if (section == "40") { // For Current Vacancies Module
	    $.get("Vacancy.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	else if (section == "42") { // For Current News Module
	    $.get("CurrentNews.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	else if (section == "43") { // For Archived News Module
	    $.get("NewsArchive.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	else {
	    $.get("Pages.aspx", query, function(data) {
	        $("#Content").html(data);

	        $("#Content").fadeIn(500);
	    });
	}
	if (section == "44") {
	    document.getElementById("map").style.display = "block";
	}
	else if (section == "79") {
	    document.getElementById("map").style.display = "none";
	}
	if (section == "8" || section == "40" || section == "9" || section == "39" || section == "42" || section == "43")
	    SlidBoard('Board_1');
}



var PreMenu = "";    
var CurMenu = "";

function SlidIt(Mid) {
    if (PreMenu == "") {
        PreMenu = Mid;            
        CurMenu = Mid;            
    }
    else {
        PreMenu = CurMenu;            
        CurMenu = Mid;
    }

        if (document.getElementById(Mid).style.display == "none") {
            $("#" + PreMenu).slideUp(500);

            $("#" + Mid).slideDown(500);
        }
        else {
            $("#" + Mid).slideUp(500);
        }
}

function SlidIt_Sub(Mid) {
    if (document.getElementById(Mid).style.display == "none") {        
        $("#" + Mid).slideDown(500);
    }
    else {
        $("#" + Mid).slideUp(500);
    }
}
var First = "";
var Click = "";
var PreBoard = "";
var CurBoard = "";

function CheckPrevMenu() {
    PreBoard = "";
    if (CurMenu != "")
    {
        $("#" + CurMenu).slideUp(500);
    }
}



function ChangeImage(URL) {
    document.getElementById("InvestImg").src = "Headers/" + URL;
}


function SlidBoard(Bid) {
    var Bar = Bid;
    Bid = Bid + "_";
    if (PreBoard == "") {
        PreBoard = Bid;
        CurBoard = Bid;
        First = "";
    }
    else {
        PreBoard = CurBoard;
        CurBoard = Bid;
        First = "Next";
    }
    if (First != "") {
        if (document.getElementById(Bid).style.display == "none") {
            $("#" + PreBoard).slideUp(500);
            var PreL = PreBoard.length;
            var PreB = PreBoard.substr(0, PreL - 1);

            document.getElementById(PreB).style.backgroundPosition = "top";

            $("#" + Bid).slideDown(500);
            document.getElementById(Bar).style.backgroundPosition = "bottom";
        }
        else {
            $("#" + Bid).slideUp(500);
            document.getElementById(Bar).style.backgroundPosition = "top";
        }
    }
}


