﻿/// <reference path="Libs/jquery-vsdoc.js" />

////////////////////////////////////////////////////////////////////////////////
//
//	YouDo.ru
//	Copyright 2008-2009 YouDo.ru
//	All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////

// Function to allow including of Javascript files
function IncludeJS(jsFile)
{
    document.write('<script type="text/javascript" src="' + jsFile + '"></scrip' + 't>');
}

function IncludeCSS(cssFile)
{
    document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '" media="screen"/>');
}

// Including dependencies
// FIXME: Неудачное решение - включать скрипты и стили внутри другого скрипта
// FIXED: первая попытка =)

var IsProductionHost = this.window.location.host.indexOf('.') > 0;
var ProductionHostUrl = 'http://youdo.ru';

IncludeJS((IsProductionHost ? ProductionHostUrl : '') + '/Scripts/swfobject.js');
if (typeof (jQuery) == 'undefined')
    IncludeJS((IsProductionHost ? ProductionHostUrl : '') + '/Scripts/Libs/jquery-min.js');
IncludeJS((IsProductionHost ? ProductionHostUrl : '') + '/Scripts/Libs/jquery.fancybox-1.3.0.js');
IncludeCSS((IsProductionHost ? ProductionHostUrl : '') + '/css/jquery/fancybox.css');

function ChangeFlashHeight(height)
{
    GetMovie().style.height = height + "px";
}

function ChangeFlashWidth(width)
{
    GetMovie().style.width = width + "px";
}

function ChangeFlashSize(width, height)
{
    ChangeFlashWidth(width);
    ChangeFlashHeight(height);
}

function OnFlashEvent(eventName, eventArgs)
{
    switch (eventName)
    {
        case "ChangeFlashHeight":
            ChangeFlashHeight(eventArgs);
            break;

        case "ChangeFlashSize":
            ChangeFlashSize(eventArgs);
            break;
        default:
        	Sys.Debug.trace("Flash event: " + eventName);
    }
}

function ChangeTask(locator)
{
    GetMovie().changeTask(locator);
}

function ChangeSolution(locator)
{
    GetMovie().changeSolution(locator);
}

function ChangeTour(locator)
{
    GetMovie().changeTour(locator);
}

function getGateway()
{
    return (IsProductionHost ? ProductionHostUrl : '') + '/service.media';
}

function EmbedPlayer(taskID, solutionID, mediaID, mode, urlPrefix, misc)
{
    var fullMode;

    switch (mode)
    {
        case "i": fullMode = "IndexMode"; break;
        case "s": fullMode = "SolutionMode"; break;
        case "t": fullMode = "TourMode"; break;
    }

    if (urlPrefix == undefined || urlPrefix == null)
    {
        urlPrefix = (IsProductionHost ? ProductionHostUrl : '') + '/';
    }

    document.write('<scrip' + 't type="text/javascript"' + '>');

    document.write('function getMode(){return "' + fullMode + '";}');
    document.write('function getLocator(){return CreateLocator(' + taskID + ',' + solutionID + ',' + (mediaID ? mediaID : 'null') + ');}');

    document.write('var flashvars =	{' + (misc ? misc : '') + '};');
    document.write('var params = {menu: "false", scale: "noScale", wmode: "transparent", allowScriptAccess: "always"};');
    document.write('swfobject.embedSWF("' + urlPrefix + 'ContentPlayer.swf", "altContent", "620", "408", "9.0.0", "' + urlPrefix + 'expressInstall.swf", flashvars, params);');
    document.write('</scrip' + 't>');

    document.write('<div id="altContent" style="width: 620px; height: 408px;"' + '><a href="http://www.adobe.com/go/getflashplayer"' + '>');
    document.write('<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"	width="112px" height="33px" alt="Get Adobe Flash player" /' + '></' + 'a></' + 'div>');
    document.write('<div id="fancyHelper" style="display:none;"></div>');
}

function ChangeWidth(width)
{
    ChangeFlashWidth(width);
    GetMovie().changeWidth(width);
}

function SetViewAreaSize(width, height)
{
    GetMovie().setViewAreaSize(width, height);
}

function GetMovie()
{
    return document["altContent"];
}

function CreateLocator(TaskID, SolutionID, MediaID)
{
    return { TaskID: TaskID, SolutionID: SolutionID, MediaID: MediaID };
}

function ShowPhotoFullScreen(url)
{
    var fancyHelper = document.getElementById("fancyHelper");
    fancyHelper.innerHTML = '<a class="fancyPic" href="' + url + '&ext=.jpg"></a>';

    $(".fancyPic").fancybox
	(
		{
		    "padding": 2,
		    "imageScale": true,
		    "overlayShow": true,
		    "overlayOpacity": 0.8,
		    "hideOnContentClick": true,
		    "centerOnScroll": true
		}
	);

    $($("#fancyHelper").children().get(0)).trigger("click");
    fancyHelper.innerHTML = '';
}
