﻿//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('&');
            var query = "section=" + section + params;
                    
            //document.getElementById("banner").src = "banner/" + section + ".jpg";
            $("#Content").fadeOut(300);
            setTimeout("showPage('" + section + "','" + query + "')", 300);

            if (ClassLink != "") {
                
                $("#" + ClassLink + "_Link").removeClass("rightmenu_active");
                $("#" + section + "_Link").addClass("rightmenu_active");
                ClassLink = section;

                
                //For the Details Pages
                if (section == "WhatsNewDetails") {
                    $("#WhatsNew_Link").addClass("rightmenu_active");
                    ClassLink = "WhatsNew";
                }
                if (section == "StaffDetails") {
                    $("#Staff_Link").addClass("rightmenu_active");
                    ClassLink = "Staff";
                }
                if (section == "ReviewerDetails") {
                    $("#Reviewer_Link").addClass("rightmenu_active");
                    ClassLink = "Reviewer";
                }
                if (section == "InstMembers") {
                    $("#Inst_Review_Link").addClass("rightmenu_active");
                    ClassLink = "Inst_Review";
                }
                if (section == "PhotoGallery") {
                    $("#Train_Link").addClass("rightmenu_active");
                    ClassLink = "Train";
                }
                if (section == "Forum") {
                    $("#Train_Link").addClass("rightmenu_active");
                    ClassLink = "Train";
                }
                if (section == "Faqs") {
                    var ids = params.split('=');
                    $("#" + ids[1] + "_Link").addClass("rightmenu_active");
                    ClassLink = ids[1];
                }
                //end of details pages
            }
            else {
                if (section == "Faqs") {
                    var ids = params.split('=');
                    $("#" + ids[1] + "_Link").addClass("rightmenu_active");
                    ClassLink = ids[1];                    
                }
                else {
                    $("#" + section + "_Link").addClass("rightmenu_active");
                    ClassLink = section;
                }
            }

            //For Contact Us
            if (section == "Staff" || section == "StaffDetails") {
                $("#Contact").fadeOut(500);
                setTimeout("showPageContact('Contact')", 500);
            }
            else if (section == "Board" || section == "Reviewer" || section == "OACPolicy") {
                $("#Contact").fadeOut(500);
            }
            
            //For the Links SlideDown
            if(section=="KeyOrganisation")
                SlidIt('LinkMenu');
        }
    }
}

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>');
    $.get(section + ".aspx", query, function(data) {
        $("#Content").html(data);


        $("#Content").fadeIn(300);

    });
}

function showPageContact(section) {
    $.ajaxSetup({ cache: false });
    $("#Contact").empty().html('<div style="text-align:center;"><br /><br /><br /><br />'
										+ '<br /><img src="images/ajax-loader.gif" algin="center" /></div>');
    $.get("Contact.aspx",function(data) {
        $("#Contact").html(data);


        $("#Contact").fadeIn(500);

    });
}

$(function() {
    $('img.image1').data('ad-desc', 'Whoa! This description is set through elm.data("ad-desc") instead of using the longdesc attribute.<br>And it contains <strong>H</strong>ow <strong>T</strong>o <strong>M</strong>eet <strong>L</strong>adies... <em>What?</em> That aint what HTML stands for? Man...');
    $('img.image1').data('ad-title', 'Title through $.data');
    $('img.image4').data('ad-desc', 'This image is wider than the wrapper, so it has been scaled down');
    $('img.image5').data('ad-desc', 'This image is higher than the wrapper, so it has been scaled down');
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
          galleries[0].settings.effect = $(this).val();
          return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
          galleries[0].slideshow.toggle();
          return false;
      }
    );
    $('#toggle-description').click(
      function() {
          if (!galleries[0].settings.description_wrapper) {
              galleries[0].settings.description_wrapper = $('#descriptions');
          } else {
              galleries[0].settings.description_wrapper = false;
          }
          return false;
      }
    );
});
