﻿function ChangeTipsPage(id)
{
    var currentPage = parseInt(id.substring(5));
    var lastPage = $("ul#paging > li:not(\".edge_button\")").length - 1;
    
    $("div#tips_container ul.tips").css("display", "none");
    
    var pageToShow = "div#tips_container ul#tips-" + id;
    $(pageToShow).css("display", "block");

    $("ul#paging > li#page-previous").unbind();
    $("ul#paging > li#page-previous").click(function() {
        ChangeTipsPage("page-" + (currentPage - 1));
    });

    $("ul#paging > li#page-next").unbind();
    $("ul#paging > li#page-next").click(function() {
        ChangeTipsPage("page-" + (currentPage + 1));
    });
    
    ChangePage(currentPage, lastPage);         
}

$(document).ready(function() {
    AddPagingHoverEffects();    
    
    $("ul#paging > li.edge_button").click(function() {
        if(this.id == "page-first")
        {
            ChangeTipsPage("page-0");
        }
        else if(this.id == "page-last")
        {   
            var last = $("ul#paging > li:not(\".edge_button\")").length - 1;
            ChangeTipsPage("page-" + last);
        }
    });

    $("ul#paging > li:not(\".edge_button\")").click(function() {
        ChangeTipsPage(this.id);
    });    
    
    var printable = window.location.toString().indexOf('print=true') >= 0;
    
    if(!printable)
    {
        if(ReadPagingUrl() > -1)
        {
            var pg = ReadPagingUrl();
            ChangeTipsPage("page-" + pg);
        }
        else 
        {
            ChangeTipsPage("page-0");
        }    
    }
    
});