﻿/// <reference path="~/Resources/js/jquery-1.2.6-intellisense.js" />
/// <reference path="~/Resources/js/start.js" />

$(function() {
    $("#header .site-title").click(function() {
        window.location = $(this).children("a").attr("href");
    });
});

$(function($) {
    $.fn.spacer = function(input, minHeight, extra) {
        var height = $(input).height() + (extra == null ? 0 : extra);
        if (minHeight != null && height < minHeight)
            height = minHeight;
        $(this).height(height);
    }
});

$(function($) {
    $.fn.modalPopup = function() {
        if ($(this).parent().hasClass("popup"))
            return;

        var container = $(this).wrap("<div class=\"popup modal\"></div>")
                               .centerScreen()
                               .parent();
        $(this).hide();
        var background = $("<div class=\"background\"></div>").css({ opacity: 0.6 });
        container.prepend(background).click(function() {
            $(this).children("div").filter(":not(.background)").add(background).fadeOut(250, function() {
                container.remove();
            });
        });
        $(this).fadeIn(250);
        return container;
    }
});

$(function($) {
    $.fn.centerScreen = function(loaded) {
        var obj = this;
        if (!loaded) {
            obj.css('top', $(window).height() / 2 - this.height() / 2 + $(window).scrollTop());
            obj.css('left', $(window).width() / 2 - this.width() / 2);
            $(window).resize(function() { obj.centerScreen(!loaded); }).scroll(function() { obj.centerScreen(!loaded); });
        } else {
            obj.stop();
            obj.animate({ top: $(window).height() / 2 - this.height() / 2 + $(window).scrollTop(), left: $(window).width() / 2 - this.width() / 2 }, 200, 'linear');
        }

        return this;
    }
});


// Positioning
$(function($) {
    $.fn.padding = function() {
        var padding = {};
        var _padding = $(this).css("padding-left");
        padding.left = _padding.substring(0, _padding.length - 2) * 1;

        _padding = $(this).css("padding-right");
        padding.right = _padding.substring(0, _padding.length - 2) * 1;

        _padding = $(this).css("padding-top");
        padding.top = _padding.substring(0, _padding.length - 2) * 1;

        _padding = $(this).css("padding-bottom");
        padding.bottom = _padding.substring(0, _padding.length - 2) * 1;

        return padding;
    };

    $.fn.getHeight = function() {
        var padding = $(this).padding();
        return padding.top + $(this).height() + padding.bottom
    };

    $.fn.getWidth = function() {
        var padding = $(this).padding();
        return padding.left + $(this).width() + padding.right;
    };
});

function back() {
    history.go(-1);
}
