﻿/// <reference path="~/scripts/jquery-vsdoc.js"/>
var popup =
{
    htmlID: '#SSX',

    left: 191 - 8, leftEnd: 191 + 816,
    height: 10, heightEnd: 610,
    top: 0, width: 10,

    calculateEndWidth: function() {
        return 816; //this.width + (this.leftEnd - this.left);
    },

    init: function() {
        $(this.htmlID).css('width', this.width).css('top', this.top).css('left', this.left).css('height', this.height);

        $("#SSX_open").click(function() {
            if ($(this).text() == '+') {
                $(popup.htmlID)
                    .css('width', popup.width)
                    .css('top', popup.top)
                    .css('left', popup.left)
                    .css('height', popup.height);
                popup.animate(false);
            } else {
                $(window.popup.htmlID).fadeOut('slow', function() { $('#SSX_open').text('+'); });
            }
        });
    },

    close: function() {
        $(window.popup.htmlID).fadeOut('slow', function() { $('#SSX_open').text('+'); });
    },

    animate: function(autoclose) {
        $("#SSX_open").text('x'); //css('display', 'none');
        $(this.htmlID).css('display', 'block').animate(
			{
			    left: this.left,
			    width: this.calculateEndWidth(),
			    height: this.heightEnd
			}, 500, 'linear', function() {
			    if (autoclose)
			        window.setTimeout('$(window.popup.htmlID).fadeOut("fast", function() { $("#SSX_open").text("+"); })', 15000);
			});
    }
}

// TODO: uncomment following lines

$(window).load(function() {
	$.post('/', { async: true, p: 1 }, function(responseText, textStatus) {
		if (textStatus == 'success') {
			$("#SSX_open").css('display', 'block');
			if (responseText == 'true') {
				if (p == 1) popup.animate(true);
			} else {
				//$('#SSX_open').text('x');
			}
		}
	}, 'text');
});

$(function() { popup.init(); });

