﻿var background;
var popUp;
var screenHeight;
$(function(){
    background = $("#background");
    popUp = $("#pop-up");
    
    if (document.documentElement.clientHeight > document.body.clientHeight)
    {
        screenHeight = document.documentElement.clientHeight;
    }
    else
    {
        screenHeight = document.body.clientHeight + 20;
    }
    
    // Lighting the current link
    $("a").each(function()
    {
        if (document.URL.indexOf($(this).attr("href")) != -1)
        {
            $(this).addClass("red");
        }
    });
});

id = function(o)
{
	return document.getElementById(o);
}

px = function (x)
{
	return ''.concat(Math.round(x), 'px');
}

function Contains(Father, Child)
{
	// We climb through Child parents till we find Father
 	while(Child && (Father!=Child) && (Child!=null))
		Child = Child.parentNode;
	return Father == Child;
}

// JScript File
function DefaultButton(button)
{
    if(event.which || event.keyCode)
    {
        if ((event.which == 13) || (event.keyCode == 13)) 
        {
            id(button).click();
            return false;
        }
    }
    else 
    {
        return true;
    }
}

function ShowBackground()
{
    //background.css("height", $("html").height());
    background.css("height", screenHeight);
    background.show().css('opacity',0).fadeTo("slow", 0.60);
}

function HideBackground()
{
    background.fadeOut("slow");
}

function ShowPopUp(text)
{
    var width  = popUp.width();
    var height = popUp.height();
    //var left   = ($("html").width()  - width)/2;
    //var top    = ($("html").height() - height * 2)/2;
    var left   = (screen.width  - width)/2;
    var top    = (screenHeight - height)/2;
    
    popUp.find("div").html(text);
    popUp.fadeIn("slow");
    
    popUp.css("left", left);
    popUp.css("top", top);
}

function HidePopUp()
{
    if (popUp.css("display")=="block")
    {
        popUp.fadeOut("slow");
    }
}

$.fn.print = function() 
{
    top.printRef=window.open('','Print',
      'width=1,height=1'
       +',menubar=0'
       +',toolbar=0'
       +',status=0'
       +',scrollbars=0'
       +',resizable=0');
       
    top.printRef.document.writeln(
      '<html><head><title>Printing...</title></head>'
       +'<body bgcolor=white onLoad="window.print(); self.close();">'
       +this.html()
       +'</body></html>');
     top.printRef.document.close();
}

function ShowPopUpInfo(id)
{
    $(".PopUpInfo").hide();
    $("#"+id).show();
}

function HidePopUpInfo()
{
    $(".PopUpInfo").hide();
}

var player = null;

function ShowVideo(sender, handlerUrl) {
    ShowBackground();

    $.get(handlerUrl, function(data) {
        player = $(data);
        player.find(".close").click(function() {
            HideBackground();
        });

        player.prependTo(document.body);

        // Calculating the link distance from the window
        var o = sender;
        var left;
        var top;
        for (left = 0, top = 0; o != null; o = o.offsetParent) {
            left += o.offsetLeft;
            top += o.offsetTop;
        }

        player.css({ "opacity": 0, "width": sender.offsetWidth, "height": sender.offsetHeight, "left": left, "top": top });

        var targetLeft = (document.body.clientWidth - 540) / 2;
        var targetTop = (document.body.clientHeight - 299) / 2;

        player.animate({ "opacity": 1, "width": 540, "height": 299, "left": targetLeft, "top": targetTop }, 800, "easeInCubic", function() {
            player.css("filter", ""); // fix IE bug
            player.find("object").fadeIn();
            
            $(this).animate({ borderWidth: 10, left: "-=10px", top: "-=10px" }, function() {
                player.find(".close").animate({ height: 26, width: 26, right: -20, top: -20 }, 800, "easeOutElastic");
            });
        });

    });

    return false;
}

function HideVideo() {
    player.remove();
    HideBackground();
}