﻿var videoSrc = "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/_-IbPlneY60&hl=en&fs=1&autoplay=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/_-IbPlneY60&hl=en&fs=1&autoplay=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>";

var reklamVideoSrc = '<object style="margin-left:22px" width="720" height="430"><param name="movie" value="http://www.youtube.com/v/ctZ7dWo3ye8?fs=1&amp;hl=hu_HU&amp;color1=0x2b405b&amp;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ctZ7dWo3ye8?fs=1&amp;hl=hu_HU&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="720" height="430"></embed></object>';

var termekVideoSrc = '<object style="margin-left:22px" width="720" height="495"><param name="movie" value="http://www.youtube.com/v/CGNljMZkVdo?fs=1&amp;hl=hu_HU&amp;color1=0x2b405b&amp;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CGNljMZkVdo?fs=1&amp;hl=hu_HU&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="720" height="495"></embed></object>';

var fullSceenSrc = "<div class=\"fullscreen\" style=\"background: #000; opacity: 0.75; filter: alpha(opacity=75); -moz-opacity: 0.75;\">&nbsp;</div><div class=\"fullscreen\"><div class=\"side-box\" id=\"{0}\" style=\"margin: 0 auto; text-align: center;\"><h1>{1}</h1><a class=\"popup-close\" href=\"{4}\">&nbsp;</a><div class=\"nettype_popup_content\" style=\"padding: 15px 0; text-align: center; overflow: auto;\">{2}</div><br /><a href=\"{4}\">{3}</a></div></div>";

var popupBaseId = "nettype_popup";

var loadedImages = {};

function NavigateToDetailPage(contentId)
{
    document.location = document.location += "/Detail?Content=" + contentId;
}

function ShowPopupMessage(message, title, closetext)
{
    return ShowPopupMessageEx(message, title, closetext, 590, "javascript:RemovePopup();")
}

function ShowFixedPopupMessage(message, title, closetext, intendedHeight)
{
    var popupId = ShowPopupMessage(message, title, closetext);
    var innerHeight = window.innerHeight ? window.innerHeight : document.body.clientHeight;
    var scrollTop = parseInt(window.pageYOffset || document.body.scrollTop);
    $("#" + popupId + " .nettype_popup_content").css("height", intendedHeight + "px");
    var actualHeight = $("#" + popupId).get(0).scrollHeight;
    var top = scrollTop + (innerHeight / 2) - (actualHeight / 2);
    $("#" + popupId).css({ "top": top + "px" });
    $("#" + popupId + " .nettype_popup_content").css("width", "100%");
    return popupId;
}

function ShowReklamVideo()
{
    return ShowPopupMessageEx(reklamVideoSrc, "Tíz ujjal hibátlanul!", "Bezárás", 770, "javascript:RemovePopup();");
}

function ShowTermekVideo()
{
    return ShowPopupMessageEx(termekVideoSrc , "Hogyan működik a program?", "Bezárás", 770, "javascript:RemovePopup();");
}


function ShowPresentationVideo()
{
    return ShowPopupMessageEx(videoSrc, "Demó videó", "Bezárás", 590, "javascript:RemovePopup();");
}

function ShowPopupMessageEx(message, title, closetext, width, closeScript) 
{
    var popupId = popupBaseId; //if more than one popup is needed at a time, separate ids must be set
    
    // fullscreen background
    var fullHeight = $(document).height();
    $("body").append(String.format(fullSceenSrc, popupId, title, message, closetext, closeScript));
    $("div.fullscreen").css({ "height": fullHeight + "px" });

    // popup top
    var actualHeight = $("#" + popupId).height();
    var innerHeight = $(window).height();
    var top = parseInt($(document).scrollTop() + (innerHeight - actualHeight) / 2);

    // popup left
    var innerWidth = $(window).width();
    var left = parseInt($(document).scrollLeft() + (innerWidth - width) / 2);

    $("#" + popupId).css({ margin: "0", position: "absolute", top: top + "px", left: left + "px", width: width + "px"});
    return popupId;
}

function RemovePopup()
{
    //if more than one popup is there at a time, this removes all of them
    $("div.fullscreen").remove();
}

function GetBigImageSrc(thumbnail)
{
    return thumbnail.replace(/_thumbnail/, "").replace(/_thumb/, "");
}

function ShowBigImage(aTag)
{
    var imgsrc = GetBigImageSrc($("img", aTag).attr("src"));
    var alt = $("img", aTag).attr("alt") ? $("img", aTag).attr("alt") : "Kép";

    if (loadedImages[imgsrc])
    {
        var theImage = loadedImages[imgsrc];
        var src = theImage.src;
        ShowImage(theImage.src, alt);
    }
    else
    {
        var theImage = new Image();
        theImage.onload = function()
        {
            ShowImage(this.src, alt);
            loadedImages[imgsrc] = theImage;
        };
        theImage.src = imgsrc;
    }
}

function ShowImage(src, alt)
{
    var img = "<img src=\"" + src + "\" alt=\"" + alt + "\" style=\"display: block; margin: 0 auto;\" />";
    var popupId = ShowPopupMessage(img, alt, "Bezárás");

    setTimeout(function() {
        // top
        var actualHeight = $("#" + popupId + " img").height();
        var innerHeight = $(window).height();
        var top = parseInt($(document).scrollTop() + (innerHeight - actualHeight) / 2);

        // left
        var currentWidth = $("#" + popupId + " img").width() + 40;
        var innerWidth = $(window).width();
        var left = (innerWidth / 2) - (currentWidth / 2);

        $("#" + popupId).css({ width: currentWidth + "px", left: left + "px", top: top + "px"});
    }, 100);
}

String.format = function(text)
{
    //check if there are two arguments in the arguments list
    if (arguments.length <= 1)
    {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for (var token = 0; token <= tokenCount; token++)
    {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace(new RegExp("\\{" + token + "\\}", "gi"), arguments[token + 1]);
    }
    return text;
};

function getSilverlightVersion() {
    for (i = 4; i > 0; i--) {
        if (Silverlight.isInstalled(i.toString() + '.0')) {
            return 'Silverlight/' + i.toString() + '.0';
        }
    }
    return 'NoSilverlight';
}

