﻿var bXMLSet = false;
var oXML;
var sXML;
var oFlash;
var isBounding = false;
var currentLayer = "Video";
var currentSlide = 0;
var propertyPrefix = "Image.";
var currStep = 0;

function onFlashInit()
{   
    FlashProxy.init();
    oFlash = getFlashObject("mixerLight");
    setXML();
}

function onLoadXML(s)
{
    
}

function onAfterLoad()
{
}

function onUpdate(str)
{
	getXMLConfigObject().value = str;
}

function updateAfterBrowse(res)
{
	var s = FlashProxy.JSONParser.serialize(res);
	oFlash.updateAfterBrowse(s);
}

function setXML(s)
{
    if(!bXMLSet && (s == null || s == "" || s == "undefined"))
    {
        bXMLSet = true;
	    s = getXMLConfigObject().value;
	    //oFlash.setLocalPath('resources/');
	    oFlash.setPlayerXML(s);
	    oFlash.setAuthorMode(0, 0);
	}
}

function getXML() 
{
   return oFlash.getXML();
}

function getFlashObject(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        return window[movieName];
    }
    else
    {
        return document[movieName];
    }
}

function CreateMixerObject()
{
    // <![CDATA[
    var so = new SWFObject("MixerLight.swf", "mixerLight", "320", "270", "8", "#FFFFFF");
    so.addParam("allowScriptAccess","always");
    so.addParam("quality","best");
    so.addParam("wmode","opaque");
	so.write("flashcontent");
	SWFFormFix("mixerLight");
	document.getElementById("flashcontent").style.display = "block";
    // ]]>
}

//------------------------------------------------------------------------------------------

function selectFootage(senderObj, isFree, isUserSubscribe, guid, sFile, sDescription, sImage)
{
    try
    {
        //var footageGalleryWin = GetRadWindow();
        //var oDictionaryEntry = footageGalleryWin.Argument;
        //var mixerPage = footageGalleryWin.BrowserWindow;
//        var xml = getXML();
//        
//        try //Internet Explorer
//        {
//          var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//          xmlDoc.async = "false";
//          xmlDoc.loadXML(xml);
//        }
//        catch(e)
//        {
//            try //Firefox, Mozilla, Opera, etc.
//            {
//                var parser = new DOMParser();
//                xmlDoc = parser.parseFromString(xml,"text/xml");
//            }
//            catch(e)
//            {
//                alert(e.message);
//                return;
//             }
//        }
//        var oldGuid = xmlDoc.firstChild.firstChild.firstChild.attributes(0).nodeValue;
//        var newGuid = guid;
//        
//        xml = xml.replace(oldGuid, newGuid);
//        bXMLSet = false;
//        oFlash.setPlayerXML(xml);
//        var xml1 = getXML();
        //xml.replace(
        oFlash.Delete("Video", 0);
        var res = new Object();
        res.ID = guid;
        res.description = sDescription.replace("~","'");
        res.thumbnail = sImage;
        res.resourceURL = sFile;
        res.updateType = "Video";
        oFlash.Edit("Video", 0);
        updateAfterBrowse(res);
        
        //if (oDictionaryEntry == null)
        //{
        //    oDictionaryEntry = new DictionaryEntry();
        //}
        
        //oDictionaryEntry.Add("IsSelected", true);
        //footageGalleryWin.Argument = oDictionaryEntry;
       // footageGalleryWin.Close();
    }
    catch(err)
    {
    
    }
}

//------------------------------------------------------------------------------------------

function selectAudio(guid, sFile, sDescription, sImage)
{
    try
    {
        oFlash.Delete("Soundtrack", 0);
        var res = new Object();
        res.ID = guid;
        res.description = sDescription.replace("~","'");
        res.thumbnail = sImage;
        res.resourceURL = sFile;
        res.updateType = "Soundtrack";
        oFlash.Edit("Soundtrack", 0);
        updateAfterBrowse(res);
    }
    catch(err)
    {
    
    }
}

//------------------------------------------------------------------------------------------

function selectImage(sFile, sFileName)
{
    try
    {
        var imageWin = GetRadWindow();
        var oDictionaryEntry = imageWin.Argument;
        var mixerPage = imageWin.BrowserWindow;
        var res = new Object();
        
        res.ID = "";
        res.description = sFileName;
        res.thumbnail = "";
        res.resourceURL = sFile;
        res.updateType = "Image";
        mixerPage.updateAfterBrowse(res);
        imageWin.Close();
    }
    catch(err)
    {
    
    }
} 

//------------------------------------------------------------------------------------------

function ToggleBounding(obj)
{
    if (isBounding)
    {
        oFlash.hideBoundingBox(obj);
        isBounding = false;
    }
    else
    {
        oFlash.showBoundingBox(obj);
        isBounding = true;
    }
}

//------------------------------------------------------------------------------------------

function selectLayer(layerName, slideNumber)
{
    oFlash.Edit(layerName, slideNumber);
    currentLayer = layerName;
    currentSlide = slideNumber;
}

//------------------------------------------------------------------------------------------

function SetSlideProperties(propertyName, propertyValue)
{
    if (currentLayer == "Images")
    {
        propertyName = propertyPrefix + propertyName;
    }
    oFlash.setSlideProperties(currentLayer ,currentSlide ,propertyName ,propertyValue);
}

//------------------------------------------------------------------------------------------

function OpenResourceWin(url, width ,height, arrgs)
{
    OpenWin("MixerResources", url, width, height, arrgs);
}

//------------------------------------------------------------------------------------------



