﻿
$(function() {
    var url = location.href;
    
    var page = url.substring(url.lastIndexOf("/") + 1);
    
    if (page == "") { page = "default.aspx"; }
    page = page.toLowerCase();
    page = page.replace(".aspx", "");
    
    if (page.indexOf("_") != -1) { page = page.split("_")[0]; }
    
    page = page + ".aspx";
    
    $("#site_mainNav a[href=" + page + "]").parent().addClass("active_link");
    
    $(".content_tagCloud a").tagcloud({
        size: {
            start: 100, 
            end: 300, 
            unit: "%"
        }, 
        color: {
            end: "#13245e", 
            start: "#bc4c51"
        }
    });

    $(".content_metaList").each(function() {
        var children = $(this).children();
        
        if (children.length > 2) {
            for (var i = 1; i < children.length - 1; i++) {
                children.eq(i).html(children.eq(i).html() + ", ");
            }
        }
    });
    
    $(".content_galleryPagination").each(function() {
        var formEl = $(this).parents("form");
        var curPage = parseInt(formEl.find("[name=p]").val());
        var totPage = parseInt(formEl.find("[name=tp]").val());
        
        if (curPage == 1) {
            $(this).find("[title=first], [title=previous]").css("cursor", "normal").fadeTo(1, 0.5);
        }
        if (curPage == totPage) {
            $(this).find("[title=last], [title=next]").css("cursor", "normal").fadeTo(1, 0.5);
        }
    });
    
    $(".content_galleryPagination a").click(function() {
        var formEl = $(this).parents("form");
        var curPage = parseInt(formEl.find("[name=p]").val());
        var totPage = parseInt(formEl.find("[name=tp]").val());
        
        var title = $(this).attr("title");
        var newPage = 1;
        
        if (title == "previous") { newPage = curPage - 1; }
        if (title == "next") { newPage = curPage + 1; }
        if (title == "last") { newPage = totPage; }
        
        if (newPage < 1) { newPage = 1; }
        if (newPage > totPage) { newPage = totPage; }
        
        if (curPage != newPage) {
            formEl.find("[name=p]").val(newPage);
            formEl.submit();
        }
        
        return false;
    });
});

