
var w = 0;
var h = 0;
var screenheight = 0;
var resizeCalled = false;
var ie = false;
var opened = false;

function PlacePopup() {
    if (!resizeCalled) {
        if (document.documentElement.clientHeight) {
            screenheight = document.documentElement.clientHeight;
        } else {
            screenheight = $(window).height();
        }
        w = ($(window).width());
        h = (screenheight); // <-- visible screen portion

        if ((screenheight + 100) <= $("html").height()) {
            h_full = ($("html").height()); // <-- full length of scrollable content        
        } else {
            h_full = ($("body").height()); // <-- full length of scrollable content        
        }
        var scrollTop = window.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop;


        $("#Popup_NetworkFlyer").width(w - 300);
        $("#Popup_NetworkFlyer").css("top", 70 + scrollTop);
        $("#Popup_NetworkFlyer").css("left", 150);

        $(".cover").width(w);
        $(".cover").height(h_full);

        $(".Popup").css("top", (((h / 2) - ($(".Popup").height() / 2))) - 50 + scrollTop); // <-- these place the popup in 
        $(".Popup").css("left", ((w / 2) - ($(".Popup").width() / 2))); //          the centre of the screen

        //ie6 fix:
        resizeCalled = true;
        setTimeout("resizeCalled = false", 10)
    }
}

function Popup(id, show) {
    PlacePopup();
    if (show) {
        $("#" + id).fadeIn(500);
        $(".cover").show();
    }
    else {
        $("#" + id).fadeOut(250);
        $(".cover").hide();
    }
}

$(document).ready(function() {
    $("#login_text").click(function() {
        SwitchLoginForm();
    });
    $("#login_arrow").click(function() {
        SwitchLoginForm();
    });
    $("#area_info_h2").click(function() {
        SwitchInfo();
    });

    $(".loginform_user").click(function() {
        if ($(this).val() == "Email address") $(this).val("");
    });
    $(".loginform_password").focus(function() {
        $("#loginform_passwordCover").hide();
    });
    $("#loginform_passwordCover").click(function() {
        $(this).hide();
        $(".loginform_password").focus();
    });

});
    // BANNER ROTATOR
    images = $('.site-banner').children('li');
    var imageIndex = images.length;
    var i = imageIndex;

    $(document).ready(function() {
        if (images.length > 0) {
            hideAll();
        }
    });
    
    function hideAll() {
        var zIndex = 9999;
        for (var j = 0; j < imageIndex - 1; j++) {
            zIndex--;
            $(images[j]).css('z-index', zIndex); //this ensures the images are in the correct order of zindex
            if (j == 0) {
                $(images[j]).fadeOut(1000); //fade the last image out a lil slower than the rest
            } else {
                $(images[j]).fadeOut('fast'); //fade all of the images out
            }
        }
        changeImage(); //start again!
    };
    function changeImage() {
        i--;
        if (i < 0) {
            i = imageIndex;
            hideAll();
        } else {
            $(images[i]).fadeIn(1000);
            setTimeout(function() { changeImage() }, 4000);
        }
    };



var loginFormOpen = false;
function SwitchLoginForm() {
    if (!loginFormOpen) {
        $(".loginform").slideDown();
        $("#login_arrow").removeClass("shut");
        loginFormOpen = true;
    } else {
        $(".loginform").slideUp();
        $("#login_arrow").addClass("shut");
        loginFormOpen = false;
    }
}

var infoOpen = false;
function SwitchInfo() {
    if (!infoOpen) {
        $("#sectionDescription").slideDown();
        $("#info_arrow").removeClass("shut");
        infoOpen = true;
    } else {
        $("#sectionDescription").slideUp();
        $("#info_arrow").addClass("shut");
        infoOpen = false;
    }
}


function OpenPlayer(id) {
    if (ie) {
        window.open("/Player.aspx?id=" + id, "MusicPlayer", "location=0,status=1,scrollbars=0,width=274,height=510");
    } else {
        var playerWindow = window.open("/Player.aspx?id=" + id, "MusicPlayer", "location=0,status=1,scrollbars=0,width=274,height=510");
        playerWindow.focus();
    }
}
function FocusPlayer() {
    if (ie) self.focus();
}

function validateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (!reg.test(email)) {
        return false;
    }
    else {
        return true;
    }
}


function textCounter(controlId,counterPanelId,maxLimit) {
    var text = $("#" + controlId).val();
    if (text.length > maxLimit)
    {
        text = text.substring(0, maxLimit);   
          $("#"+controlId).val(text)
          $("#" + counterPanelId).html("Maximum character limit (" + maxLimit + ") reached.");
     }
     else if (text.length < maxLimit)
     {
        var textLength = text.length;
        var charsLeft = maxLimit - textLength;
        $("#" + counterPanelId).html(charsLeft + " characters left.");
     }
 }
 /**********************JQuery Paging functions*****************************************/

 var Global_LoadingImage = "<img src='/images/pagedResultsLoader.gif' class='loader' alt='Loading please wait..'>"
 
 //<Param name="list_panel_id"> Id of panel which will contain the paged results</Param>
 //<param name="full_list_panel_id"> Id of panel which contains the full list to be pageged</param>
 //<param name="paging_css"> CSS for the panel which will contain the page numbers</param>
 //<param name="edgeEntries"> number of extra pages to show after reaching max pages</param>
 //<param name="maxPages"> Maximum number of pages to show out of total page count</param>
 //<param name="pageSize"> Number of rows per page</param>
 function initPagination(list_panel_id, full_list_panel_id, paging_css, paged_row_identifier, edgeEntries, maxPages, pageSize) {
     var list_Count = $("#" + full_list_panel_id + " div." + paged_row_identifier).length;
     $('#' + list_panel_id).show();
     if (list_Count == 0) {
         $("." + paging_css).hide();
     }
     $("." + paging_css).pagination(list_Count, {
         num_edge_entries: edgeEntries,
         num_display_entries: maxPages,
         callback: pageselectCallback,
         items_per_page: pageSize,
         list_panel_id: list_panel_id,
         full_list_panel_id: full_list_panel_id,
         paged_row_identifier: paged_row_identifier

     });
 }
// function pageselectCallback(page_index, jq, list_panel_id, full_list_panel_id, paged_row_identifier,pageSize) {
//     var new_content = "";
//     var list_Count = $("#" + full_list_panel_id + " div." + paged_row_identifier).length;
//     var max_elem = Math.min((page_index + 1) * pageSize, list_Count);
//     $("#" + list_panel_id).empty();
//     for (var i = page_index * pageSize; i < max_elem; i++) {
//         new_content = $("#" + full_list_panel_id + " div." + paged_row_identifier + ":eq(" + i + ")").clone();
//         $("#" + list_panel_id).append(new_content)
//     }
// }
/***************************************************************************************/
