/**
* @author Norollahi
*/
//append click event to the UL list anchor tag
$(document).ready(function () {

    //Begin   - Geting name of page
    var url = document.location.href;
    url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));
    url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
    url = url.substring(url.lastIndexOf("/") + 1, url.length);
    //End   - Geting name of page

    var banner_filename = url.replace(".aspx", "");
    $('#SubPageBanner').attr('src', "Images/Pages/" + banner_filename + ".jpg");
    $('#SubPageBanner').show();

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", "xmls/mylink.xml", false);
    xmlhttp.send();
    xmlDoc = xmlhttp.responseXML;
    var x = xmlDoc.getElementsByTagName("Node");
    txt = "<ul>"
    for (i = 0; i < x.length; i++) {
        linkparentnode = (x[i].getElementsByTagName("parentNode")[0].childNodes[0].nodeValue) + ".aspx";
        if (linkparentnode == url) {
            linkhref = (x[i].getElementsByTagName("href")[0].childNodes[0].nodeValue);
            linkrel = (x[i].getElementsByTagName("rel")[0].childNodes[0].nodeValue);
            linkclass = (x[i].getElementsByTagName("classname")[0].childNodes[0].nodeValue);
            linktext = (x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue);
            if (linkclass == "active") {
                $(".ContentCenterBlock " + linkrel).slideDown(500);
            }
            $(".ContentCenterBlock " + linkrel + " .TopTitleRight").text(linktext);
            txt += "<li><a href=" + '"' + linkhref + '"' + " class=" + '"' + linkclass + '"' + " rel=" + '"' + linkrel + '"' + ">" + linktext + "</a></li>";
        }
    }
    txt += "</ul>";
    document.getElementById("linklist").innerHTML = txt;


    //Begin of Nemoodar panel moving
    $("#accordion").msAccordion({ defaultid: 0, vertical: true });
    //End of Nemoodar panel moving

    //Begin of AJAX simulation
    $('.PagesRightMenu ul a').click(function () {
        var link_href = $(this).attr('href');
        link_href = link_href.replace("#", "");
        file_name = "SubPages/" + link_href + ".txt";
        var activecheck = $(this).attr('class');
        var idcheck = $(this).attr('id');
        if (idcheck != 'panel1') {
            // jelogiri az baz shodane mojadade panel faal
            if (activecheck != 'active') {

                //reset all the items
                $('.PagesRightMenu ul a').removeClass('active');

                //set current item as active
                $(this).addClass('active');


                //scroll it to the right position
                var Selecteditem = $(this).attr('rel');

                $(".ContentCenterBlock .panel").hide();

                $(".ContentCenterBlock " + Selecteditem + " .entry").load(file_name);

                $("#loading").bind("ajaxSend", function () {
                    $(this).slideDown();
                }).bind("ajaxComplete", function () {
                    $(this).slideUp();
                });

                $(".ContentCenterBlock " + Selecteditem).slideDown(500);

                return false;
            };
        };
    });
    //End of AJAX simulation
});

