﻿function PreLoad()
{
    LoadImages();
    SetHeight();
}

function LoadImages()
{
    MenuHoverImage = new Image(); 
    MenuHoverImage.src = 'WebResource.axd?d=ZCU45PjaccUOnNiVE4RT3BIWbNfVCimpREGxZbt3qY49NVBahkeBNEh96H9W8T1n0&t=634024203286314763';
}
function SetHeight() {

    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight + document.body.offsetTop;
        xWithScroll = document.body.offsetWidth;
    }

    var MainDiv = document.getElementById("MainDiv");

    if (yWithScroll > MainDiv.offsetHeight)
        MainDiv.style.height = yWithScroll + 'px';


}

function Collection(url) {
//    __doPostBack("TreeNav1", "UpdateReq");
}

function RightClick(event) {
    var obj = event.srcElement || event.target;
    var seltreeNode = obj;
    alert(seltreeNode.innerHTML); //This will prompt selected Node Text
    seltreeNode.innerHTML = "Rajesh Babu"; //This will change the selected node text as “Rajesh Babu”
}



//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;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor() {
    //Check if it has changes
    if (currentAnchor != document.location.hash) {
        currentAnchor = document.location.hash;
        //if there is not anchor, the loads the default section
        if (!currentAnchor) {
            if (document.location.toString().indexOf("/Collection") != -1) {
                LoadCollection("section=M");
            }
            query = "section=Default";
        }
        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 + params;

            if (document.location.toString().indexOf("/Collection") != -1) {
                LoadCollection(query);
            }
        }
    }
}

function LoadCollection(query) {
    //Send the petition
    $("#Loading").show();

   var myRegExp = new RegExp("/", "g");
   query = query.replace(myRegExp, '?');
    
    $.get("/GetContent/TreeMenu/" + query, "", function(data) {
        $("#TreeMenu").html(data);
        //      $("#loading").hide();
    });

    $.get("/GetContent/Content/" + query, "", function(data) {
        $("#InnerContent").html(data);
             $("#Loading").hide();
    });
    
}