﻿var bXMLSet = false;
var oXML;
var sXML;
var oFlash;
var currWin = null;
var prvOpenedMenu = null;
var prvOpenedMenuArrow = null;
var isMenuEnable = false;
var _currentGallery = "";
var _folderCollection = [];
var _freeFootageCollection = [];
var console = {};
console.log = function(){};
//***************************************************************
//*                  Mixer functions                            *
//***************************************************************

function onFlashInit()
{   
    FlashProxy.init();
    oFlash = getFlashObject("mixer");
    setXML();
    
    //oFlash.setAuthorMode(null,0);
   // var activateMode = getActivateModeObject().value;
   
    //if (activateMode == "Activate")
    //{
	//    oFlash.activateMode(); 
	//}
	
	FlashProxy.onOpenGallery = function(gallery, args)
    {
        if (gallery == "Footage")
        {
            gallery = "Video";
        }
	    _currentGallery = gallery;
	    switch(gallery)
	    {
		    case "Soundtrack":
			    OpenResourceWin("SoundtrackGallery.aspx", 880, 550);
		        break;
		    case "Narration":
			    OpenResourceWin("Narration/Narration.aspx?g=" + getMediaItem().value, 800, 550);
		        break;
		    case "Soundeffects":
			    OpenResourceWin("SoundeffectGallery.aspx", 880, 550);
		        break;
		    case "Image":
			    OpenResourceWin("ImageGallery.aspx?g=" + getMediaItem().value, 800, 500);
		        break;
		    case "Video":
			    //window.open('select_video.html', gallery, 'width=400,height=200');
			    OpenResourceWin("FootageGallery.aspx?g=" + getMediaItem().value, 800, 550, null);
			    break;
		    case "Footage":
		        _folderCollection = args;
			    OpenResourceWin("FootageGallery.aspx?g=" + getMediaItem().value, 800, 550, null);
		        break;
	    }
    }
    
    FlashProxy.onFootageRemoved = function(o)
    {
        PageMethods.RemoveFromFolder(getMediaItem().value, o.ID.replace(";",""), RemoveFromFolder_Callback_Func); 
        RemoveFootageFromCollection(o.ID.replace(";",""));
    }
    
    function RemoveFromFolder_Callback_Func(results)
    {
    }
}

//---------------------------------------------------------------

function menuUpdate(l_name, s_number)
{
    //ChangeMenuBehavior();
    ShowMainMenu(l_name);
}

//---------------------------------------------------------------

function onLoadXML(s)
{
	//alert(s);
}

//---------------------------------------------------------------

function onAfterLoad()
{
    //ChangeMenuBehavior();
	ShowMainMenu('Video');
	var videoLayers = GetLayerObjects('Video');
    if (videoLayers > 0)
    {
        oFlash.Edit('Video', 0);
    }
}

//---------------------------------------------------------------

function showHowtoVideoPopup(referrer)
{
    //if (referrer == "menu")
    //{
    //    if (isMenuEnable)
   //     {
            OpenResourceWin('HowtoVideo.htm', 620, 540, null);
   //     }
   // }
  //  else
  //  {
  //      OpenResourceWin('HowtoVideo.htm', 620, 540, null);
  //  }
}
/*function browseFromFlash(sType)
{
	switch(sType)
	{
		case "audio":
            OpenResourceWin("AudioGallery.aspx", 800, 550);
		    break;
		case "narrations" : //"narration":
		    var arrgs = new Array();
            arrgs["WinName"] = "narration";
            arrgs["MediaGuid"] = getMediaItem().value;
		    OpenResourceWin("Narration/Narration.aspx?g=" + getMediaItem().value, 800, 550, arrgs);
		    break;
		case "slides" ://"SlideImage":
		    OpenResourceWin("ImageGallery.aspx?g=" + getMediaItem().value, 800, 500);
		    break;
		case "soundtracks" :
		    OpenResourceWin("SoundtrackGallery.aspx", 880, 550);
		    break;
		case "sfx" :
		    OpenResourceWin("SoundeffectGallery.aspx", 880, 550);
		    break;
		case "video" :
		    OpenResourceWin("FootageGallery.aspx?g=" + getMediaItem().value, 800, 550);
		    break;
		        
	}
}*/

//---------------------------------------------------------------

function onUpdate(str)
{
    //ChangeMenuBehavior();
	getXMLConfigObject().value = str; //oFlash.getXML();
}

//---------------------------------------------------------------

function getCurrentGallery()
{
    return _currentGallery;
}

function updateAfterBrowse(res)
{
	var s = FlashProxy.JSONParser.serialize(res);
	oFlash.updateAfterBrowse(s);
}
		
//function updateAfterBrowse()
//{
//	oFlash.updateAfterBrowse.apply(null, arguments);
//}

//---------------------------------------------------------------

function setXML(s)
{
    if(!bXMLSet && (s == null || s == "" || s == "undefined"))
    {
        bXMLSet = true;
	    s = getXMLConfigObject().value;
	    oFlash.setLocalPath('');
	    oFlash.setPlayerXML(s, false);
	    oFlash.setAuthorMode(0, 0);
	}
}

//---------------------------------------------------------------

function getXML() 
{
   return oFlash.getXML();
}	

//---------------------------------------------------------------

function flashTrace(s)
{
	
}

//---------------------------------------------------------------

function getFlashObject(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        return window[movieName];
    }
    else
    {
        return document[movieName];
    }
}

//---------------------------------------------------------------

function CreateMixerObject()
{
    // <![CDATA[
    var so = new SWFObject("mixer.swf", "mixer", "750", "570", "8", "#FFFFFF");
    so.addParam("allowScriptAccess","always");
    so.addParam("loop","false");
    so.addParam("menu","false");
    so.addParam("quality","best");
    so.addParam("scale","default");
    so.addParam("wmode","opaque");
    so.addParam("align","middle");
	so.write("flashcontent");
	SWFFormFix("mixer");
	document.getElementById("flashcontent").style.display = "block";
	//ShowMainMenu();
    // ]]>
}

//---------------------------------------------------------------

function OpenResourceWin(url, width ,height, arrgs)
{
    OpenWin("MixerResources", url, width, height, arrgs);
}

//---------------------------------------------------------------

//***************************************************************
//*                  Menu functions                             *
//***************************************************************

var layers = new Array ("Video", "Images", "Text", "Soundtrack", "Narration", "Soundeffects");
var videoSections = new Array("General", "Effects");
var slideSections = new Array("Background", "Image", "Text", "General");
var textSections = new Array("General", "Filters");
var soundtrackSections = new Array("General");
var narrationSections = new Array("General");
var soundeffectsSections = new Array("General");

function ShowMainMenu(layerName)
{
    ChangeMenuBehavior();
    
    var oTopTitle = document.getElementById("topTitle");
    oTopTitle.innerHTML = "Tasks Menu";
    
    if (isMenuEnable)
    {
        for (var i = 0; i < layers.length; i++)
        {   
              var optionsLayerTitle = document.getElementById(layers[i] + "Options");   
              var optionsLayerHolder = document.getElementById(layers[i] + "OptionsHolder"); 
              var itemsCountHolder = document.getElementById(layers[i] + "ItemsCountHolder"); 
              var itemsLayerHolder = document.getElementById(layers[i] + "Items"); 
              ShowLayerObjectsMenu(optionsLayerTitle, optionsLayerHolder, itemsCountHolder, itemsLayerHolder, layers[i]) 
        }
        OpenRelevantSectionMenu(layerName); 
    }
}

//---------------------------------------------------------------

function ShowLayerObjectsMenu(optionsLayerTitle, optionsLayerHolder, itemsCountHolder, itemsLayerHolder, layerName)
{
    var layerObjects = GetLayerObjects(layerName)
    itemsCountHolder.innerHTML = '(' + layerObjects + ' Items)';
    
    if (layerObjects == 0)
    {
        optionsLayerHolder.innerHTML = '';
        itemsLayerHolder.style.display = 'none';
        optionsLayerTitle.style.display = 'block';
        return false;
    }
    else
    {
        itemsLayerHolder.style.display = 'block';
        optionsLayerTitle.style.display = 'none';
    }
    //var oLayersMenu = document.getElementById("LayerObjectsMenu");
    var menuContent = '';
    
    menuContent += '<table class="menuElement" cellpadding="0" cellspacing="0" width="100%" border="0">'
    for (var i = 1; i <= layerObjects; i++)
    {
        menuContent += '<tr  class="menuElementLink" onmouseover="SwitchStyle(this, \'on\');" onmouseout="SwitchStyle(this, \'off\');">'
        menuContent += '    <td style="padding-left:10px;"><img src="images/arrow_link.gif" /></td>'
        menuContent += '    <td  style="padding-left:5px;width:100px">' + GetLayerNameForDisplay(layerName) + ' ' + i + '</td>'
        menuContent += '    <td style="padding-left:10px;width:100px"><span class="actionLink" onclick="oFlash.Edit(\'' + layerName + '\',\'' + (i - 1) + '\', \'General\');">Edit</span>&nbsp;|&nbsp;'
//        if (layerName == "Video" && layerObjects == 1)
//        {
//            menuContent += '    <span style="color:#aaa8a8;">Delete</span>'
//        }
//        else
//        {
            menuContent += '    <span class="actionLink" onclick="DeleteSlide(\'' + layerName + '\', \'' + (i - 1) + '\');">Delete</span>'
//        }
        menuContent += '    </td>'
        menuContent += '</tr>'
    }
    menuContent += '</table>'
    optionsLayerHolder.innerHTML = menuContent;
   
}

//---------------------------------------------------------------

function ShowSectionMenu(layerName, layerObject)
{
    var sectionsArray;
    var menuContent = "";
    var oSectionMenu = document.getElementById("SectionMenu");
    var oTopTitle = document.getElementById("topTitle");
    
    switch (layerName)
    {
        case "Video" :
            sectionsArray = videoSections;
            break;
        case "Slides" :
            sectionsArray = slideSections;
            break;
        case "Text" :
            sectionsArray = textSections;
            break;
        case "Soundtrack" :
            sectionsArray = soundtrackSections;
            break;
        case "Narration" : 
            sectionsArray = narrationSections;
            break; 
        case "Soundeffects" : 
            sectionsArray = soundeffectsSections;
            break;                         
    }
    
    menuContent += '<table class="menuElement" cellpadding="0" cellspacing="0" width="100%" border="0">'
    for (var i = 0; i < sectionsArray.length; i++)
    {
            menuContent += '<tr class="menuElementLink" style="cursor:pointer" onmouseover="SwitchStyle(this, \'on\');" onmouseout="SwitchStyle(this, \'off\');">'
            menuContent += '    <td style="padding-left:10px;"><img src="images/arrow_link.gif" /></td>'
            menuContent += '    <td width="150" style="padding-left:5px;" onclick="oFlash.Edit(\'' + layerName + '\',\'' + layerObject + '\', \'' + sectionsArray[i] + '\');return false;">' + sectionsArray[i] + '</td>'
            menuContent += '</tr>'
    }
    menuContent += '</table>'
    menuContent += '<table class="backElement" cellpadding="0" cellspacing="0" width="100%" border="0">'
    menuContent += '    <tr>'
    menuContent += '        <td><img src="images/arrow_back.gif" /></td>'
    menuContent += '        <td width="150" class="subTitleText" onclick="ShowMainMenu(\'' + layerName + '\');">Back</td>'
    menuContent += '    </tr>'
    menuContent += '</table>'
    oSectionMenu.innerHTML = menuContent;
    oTopTitle.innerHTML = "Edit " + GetLayerNameForDisplay(layerName);
    switchMenu("SectionMenu");
   
}

//---------------------------------------------------------------

function CreateSlide(layerName)
{
    if (isMenuEnable)
    {
        oFlash.Create(layerName);
    }
}

//---------------------------------------------------------------

function DeleteSlide(layerName, slideNumber)
{
    var response = window.confirm("Are you sure you want to delete this " + GetLayerNameForDisplay(layerName) + "?");
    if (response)
    {
        oFlash.Delete(layerName, slideNumber);
        ShowMainMenu(layerName)
    }
}

//---------------------------------------------------------------

function GetLayerObjects(layerName)
{
      return oFlash.getLayerObjectList(layerName);  
//    var layerObjectsXML = oFlash.getLayerObjectList(layerName);
//    
//    //code for IE
//    if (window.ActiveXObject)
//    {
//        var doc=new ActiveXObject("Microsoft.XMLDOM");
//        doc.async="false";
//        doc.loadXML(layerObjectsXML);
//    }
//    // code for Mozilla, Firefox, Opera, etc.
//    else
//    {
//      var parser=new DOMParser();
//      var doc=parser.parseFromString(layerObjectsXML,"text/xml");
//    }
//    return doc.documentElement.childNodes.length;
}

//---------------------------------------------------------------

function switchMenu(menuToShow)
{
    if (document.getElementById(menuToShow).style.display != "block")
    {
        document.getElementById("MainMenu").style.display = "none";
        //document.getElementById("LayerObjectsMenu").style.display = "none";
        document.getElementById("SectionMenu").style.display = "none";
        document.getElementById(menuToShow).style.display = "block";
    }
}

//---------------------------------------------------------------

function SwitchStyle (obj, switchCommand)
{
    if (switchCommand == "on")
    {
        if (obj.className == "menuElementDisable")
        {
            obj.className = "menuElementDisableOn";
        }
        else
        {
            obj.className = "menuElementLinkOn";
        }
    }
    else
    {
        if (obj.className == "menuElementDisableOn")
        {
            obj.className = "menuElementDisable";
        }
        else
        {
            obj.className = "menuElementLink";
        }
    }
}

//---------------------------------------------------------------

function Toggle(objId, imgId)
{
    if (isMenuEnable || objId == "Help")
    {
        var obj = document.getElementById(objId);
        var oimg = document.getElementById(imgId);
        
        if ((prvOpenedMenu != null) && (prvOpenedMenu.id != objId))
        {
            prvOpenedMenu.style.display = "none";
            prvOpenedMenuArrow.src = "images/arrow_open.gif";
        }
        
        obj.style.display = "block";
        oimg.src = "images/arrow_close.gif";
    
        prvOpenedMenu = obj
        prvOpenedMenuArrow = oimg;
        
    }
}

//---------------------------------------------------------------

function GetLayerNameForDisplay(layerName)
{
    var layerNameForDisplay = "";
    switch (layerName)
    {
        case "Video" :
            layerNameForDisplay = "Video";
            break;
        case "Images" :
            layerNameForDisplay = "Image";//layerName.substring(0, layerName.length - 1);
            break;
        case "Text" :
            layerNameForDisplay = "Text";
            break;
        case "Soundtrack" :
            layerNameForDisplay = "Soundtrack";
            break;
        case "Narration" : 
            layerNameForDisplay = "Narration";
            break; 
        case "Soundeffects" : 
            layerNameForDisplay = "soundEffect";
            break;                         
    }
    
    return layerNameForDisplay;
}

//---------------------------------------------------------------

function OpenRelevantSectionMenu(layerName)
{
    switch (layerName)
    {
        case "Video" :
            Toggle("VideoOptions", "video_arrow");
            break;
        case "Images" :
            Toggle("ImagesOptions", "slides_arrow");
            break;
        case "Text" :
            Toggle("TextOptions", "texts_arrow");
            break;
        case "Soundtrack" :
            Toggle("SoundtrackOptions", "Soundtrack_arrow");
            break;
        case "Narration" : 
            Toggle("NarrationOptions", "narrations_arrow");
            break; 
        case "Soundeffects" : 
            Toggle("SoundeffectsOptions", "sfx_arrow");
            break;                         
    }
}


//***************************************************************
//*                  Mixer resources  functions                 *
//***************************************************************

var _mediaItemGuid;

function selectFootage(senderObj, isFree, isUserSubscribe, guid, sFile, sDescription, sImage)
{
    try
    {
        //if (isFree || isUserSubscribe)
        //{
            var footageGalleryWin = GetRadWindow();
            var oDictionaryEntry = footageGalleryWin.Argument;
            var mixerPage = footageGalleryWin.BrowserWindow;
            var res = new Object();
            var VideoObjects = mixerPage.GetLayerObjects("Video");
            
            if (VideoObjects == 3)
            {
                alert("You can add no more then 3 footage.");
                return
            }
            
            res.ID = guid;
            res.description = sDescription.replace("~","'");
            res.thumbnail = sImage;
            res.resourceURL = sFile;
            res.updateType = mixerPage.getCurrentGallery();
            mixerPage.updateAfterBrowse(res);
            
            if (oDictionaryEntry == null)
            {
                oDictionaryEntry = new DictionaryEntry();
            }
            
            oDictionaryEntry.Add("IsSelected", true);
            footageGalleryWin.Argument = oDictionaryEntry;
            footageGalleryWin.Close();
        //}
        //else
        //{
        //    ShowSubscriptionPopup(senderObj)
       // }
    }
    catch(err)
    {
    
    }
}

function selectAudio(guid, sFile, sDescription, sImage)
{
    try
    {
        var audioGalleryWin = GetRadWindow();
        var oDictionaryEntry = audioGalleryWin.Argument;
        var mixerPage = audioGalleryWin.BrowserWindow;
        var res = new Object();
        
        res.ID = guid;
        res.description = sDescription.replace("~","'");
        res.thumbnail = sImage;
        res.resourceURL = sFile;
        res.updateType = mixerPage.getCurrentGallery();
        mixerPage.updateAfterBrowse(res);
        
        if (oDictionaryEntry == null)
        {
            oDictionaryEntry = new DictionaryEntry();
        }
       
        oDictionaryEntry.Add("IsSelected", true);
        audioGalleryWin.Argument = oDictionaryEntry;
        audioGalleryWin.Close();
    }
    catch(err)
    {
    
    }
}

//---------------------------------------------------------------

function selectNarration(sFile)
{
    try
    {
        var narrationWin = GetRadWindow();
        var oDictionaryEntry = narrationWin.Argument;
        var mixerPage = narrationWin.BrowserWindow;
        var res = new Object();
        
        res.ID = "";
        res.description = "";
        res.thumbnail = "";
        res.resourceURL = sFile;
        res.updateType = mixerPage.getCurrentGallery();
        mixerPage.updateAfterBrowse(res);
        
        if (oDictionaryEntry == null)
        {
            oDictionaryEntry = new DictionaryEntry();
        }
        oDictionaryEntry.Add("IsSelected", true);
        narrationWin.Argument = oDictionaryEntry;
        narrationWin.Close();
    }
    catch(err)
    {
    
    }
}

//---------------------------------------------------------------

function DeleteNarration(narrationGuid, mediaItemGuid)
{
    var response = window.confirm("Are you sure you want to delete this narration file ?");
    if (response)   
    {
        _mediaItemGuid = mediaItemGuid
        PageMethods.DeleteNarration(narrationGuid, DeleteNarration_CallBackFunc);
    }
}

//---------------------------------------------------------------

function DeleteNarration_CallBackFunc(results)
{
    window.location.href ("Narration.aspx?g=" + _mediaItemGuid);  
}

//---------------------------------------------------------------
    
function selectImage(sFile, sFileName, isFromWizard)
{
    try
    {
        var imageWin = GetRadWindow();
        var oDictionaryEntry = imageWin.Argument;
        var mixerPage = imageWin.BrowserWindow;
        var res = new Object();
        
        if (isFromWizard)
        {
            res.ID = "";
            res.description = sFileName;
            res.thumbnail = "";
            res.resourceURL = sFile;
            res.updateType = "Image";
            mixerPage.updateAfterBrowse(res);
        }
        else
        {
            res.ID = "";
            res.description = sFileName;
            res.thumbnail = "";
            res.resourceURL = sFile;
            res.updateType = mixerPage.getCurrentGallery();
            mixerPage.updateAfterBrowse(res);
            
            if (oDictionaryEntry == null)
            {
                oDictionaryEntry = new DictionaryEntry();
            }
            oDictionaryEntry.Add("IsSelected", true);
            imageWin.Argument = oDictionaryEntry;
        }
        imageWin.Close();
    }
    catch(err)
    {
    
    }
} 

//---------------------------------------------------------------

function DeleteImage(imgaeGuid, mediaItemGuid)
{
    var response = window.confirm("Are you sure you want to delete this image file ?");
    if (response) 
    {
        _mediaItemGuid = mediaItemGuid
        PageMethods.DeleteImage(imgaeGuid, DeleteImage_CallBackFunc);
    }
}

//---------------------------------------------------------------

function DeleteImage_CallBackFunc(results)
{
    window.location.href ("ImageGallery.aspx?g=" + _mediaItemGuid);  
}

//---------------------------------------------------------------

function ShowMoreInfoPopup(senderObj, description, fullDescription, title, keywords, Id)
{
    var moreInfoContainer = $get("moreInfo");
    var descriptionObj = null;
    var fullDescriptionObj = null;
    var keywordsObj = null;
    var IdObj = null;
    var titleObj = null;
    var html = null;
    var elementBounds = Sys.UI.DomElement.getBounds(senderObj);
    var posX = elementBounds.x;
    var posY = elementBounds.y;
    var pixelLeft = 0;
    moreInfoContainer.style.display = "none";
    moreInfoContainer.style.position = "absolute";
    
    if (document.all) 
    {
        descriptionObj = document.all[description];
        fullDescriptionObj = document.all[fullDescription];
        keywordsObj = document.all[keywords];
        titleObj = document.all[title];
        IdObj = document.all[Id];
        moreInfoContainer.style.top = posY - 150 +  'px';
        pixelLeft = posX - 210;
    }
    else
    {
        descriptionObj = document.getElementById(description);
        fullDescriptionObj = document.getElementById(fullDescription);
        keywordsObj = document.getElementById(keywords);
        titleObj = document.getElementById(title);
        IdObj = document.getElementById(Id);
        moreInfoContainer.style.top = posY - 175 +  'px';
        pixelLeft = posX - 210;
    }
    
    if (pixelLeft <= 65)
    {
        moreInfoContainer.className = "moreInfoLeft";
        moreInfoContainer.style.left = posX - 10 + 'px';
    }
    else
    {
        moreInfoContainer.className = "moreInfoRight";
        moreInfoContainer.style.left = posX - 210 + 'px';
    }
    html = '<div style="width:290px;height:115px;margin-left:10px;margin-top:10px">';
    html +='    <div style="float:right;height:15px;cursor: pointer" onclick="HideMoreInfoPopup();"><img src="../images/close_tiptool.jpg"></div>'
    html +='    <div class="fieldContainer" style="padding-left:10px">';
    html +='         <div class="label" style="width:70px">Title:</div>';
    html +='         <div style="float:left;width:200px">' + titleObj.value + '</div>';
    html +='    </div>';
    html +='    <div class="fieldContainer" style="padding-left:10px;padding-top:2px">';
    html +='         <div class="label" style="width:70px">Description:</div>';
    html +='         <div title='+ fullDescriptionObj.value +' style="float:left;width:200px">' + descriptionObj.value + '</div>';
    html +='    </div>';
    html +='    <div class="fieldContainer" style="padding-left:10px;padding-top:2px">';
    html +='         <div class="label" style="width:70px">Keywords:</div>';
    html +='         <div style="float:left;width:200px">' + keywordsObj.value + '</div>';
    html +='     </div>';
    html +='    <div class="fieldContainer" style="padding-left:10px;padding-top:2px">';
    html +='         <div class="label" style="width:70px">ID:</div>';
    html +='         <div style="float:left;width:200px">' + IdObj.value + '</div>';
    html +='     </div>';
    html +='</div>';
    moreInfoContainer.innerHTML = html;
    moreInfoContainer.style.display = "block";
}

//---------------------------------------------------------------

function HideMoreInfoPopup()
{
    var moreInfoContainer = $get("moreInfo");
    moreInfoContainer.style.display = "none";
}


//---------------------------------------------------------------

function AddToFolder(senderObj, footageGuid, mediaItemGuid, isFree, isUserSubscribe, isExistInFolder, sFile, sDescription, sImage)
{
    
    if (isFree || isUserSubscribe)
    {
        if (!isExistInFolder)
        {
            senderObj.style.cursor = 'wait';
            var oXmlHttp;
            var sPostUrl = "AddToFolder.aspx?g="+ mediaItemGuid + "&fg=" + footageGuid 
            if (window.navigator.appName == "Microsoft Internet Explorer")
	        {
	            oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
	            oXmlHttp.open ("POST", sPostUrl , false);
	        }
	        else
	        {
	            oXmlHttp = new XMLHttpRequest();
	            oXmlHttp.open ("GET", sPostUrl , true);
	        }
    	    
	        if (oXmlHttp != null)
	        {
	            oXmlHttp.onreadystatechange = function ()
	            {
	                if (oXmlHttp.readyState == 4 )
	                {
		                if (oXmlHttp.status==200)
		                {
		                    if (oXmlHttp.responseText == "added")
                            {
                                var prm = Sys.WebForms.PageRequestManager.getInstance();
                                var currURL = window.location.href;
                                //prm._doPostBack('', '');
                                AddFootageToCollection(footageGuid, sFile, sDescription, sImage);
                                window.location.href = currURL.substring(currURL.lastIndexOf("/") + 1, currURL.length) + "&AddedFolder=true"
                            }
		                }
		            } 
		        }
		        oXmlHttp.send (null);
		        senderObj.style.cursor = 'default';
	        }  
	    }
	    else
	    {
	        alert("This footage is already exists in the footage folder.");
	    }
    }
    else
    {
        ShowSubscriptionPopup(senderObj)
    }
}

//---------------------------------------------------------------

function RemoveFromFolder(footageGuid, mediaItemGuid)
{
    var oXmlHttp;
    var sPostUrl = "RemoveFromFolder.aspx?g="+ mediaItemGuid + "&fg=" + footageGuid 
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
        oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
        oXmlHttp.open ("POST", sPostUrl , false);
    }
    else
    {
        oXmlHttp = new XMLHttpRequest();
        oXmlHttp.open ("GET", sPostUrl , true);
    }
    
    if (oXmlHttp != null)
    {
        oXmlHttp.onreadystatechange = function ()
        {
            if (oXmlHttp.readyState == 4 )
            {
	            if (oXmlHttp.status==200)
	            {
	                if (oXmlHttp.responseText == "removed")
                    {
                        var prm = Sys.WebForms.PageRequestManager.getInstance();
                        prm._doPostBack('UpdatePanel1', '');
                        RemoveFootageFromCollection(footageGuid);
                    }
	            }
	        } 
	    }
	    oXmlHttp.send (null);
    }  
}

//---------------------------------------------------------------

function ShowSubscriptionPopup(senderObj)
{
    var popupContainer = $get("subscriptionPopup");
    var html = null;
    var elementBounds = Sys.UI.DomElement.getBounds(senderObj);
    var posX = elementBounds.x;
    var posY = elementBounds.y;
    
    popupContainer.style.display = "none";
    popupContainer.style.position = "absolute";
    popupContainer.style.left = posX + 200 +  'px';
    popupContainer.style.top = posY - 100 +  'px';
         
    html = '<div style="width:280px;height:115px;margin-left:10px;margin-top:10px">';
    html +='    <div style="float:right;height:15px;cursor:pointer" onclick="HideSubscriptionPopup();"><img src="../images/close_tiptool.jpg"></div>'
    html +='    <div style="clear:right;margin-left:30px;margin-top:30px;width:220px">';
    html +='        <div class="fieldContainer">';
    html +='            <div class="grayLabel" style="text-align:center">This footage is for subscribers only.</div>';
    html +='        </div>';
    html +='        <div class="fieldContainer" style="margin-top:20px;padding-left:15px">';
    html +='            <div style="float:left;width:84px;cursor:pointer"><a href="../SubscriptionOptions.aspx" target="_blank" onclick="CloseWin(\'MixerResources\');"><img src="images/button-subscribe.jpg" border="0" ></a></div>';
    html +='            <div style="float:left;width:84px;padding-left:10px;cursor:pointer"><img onclick="HideSubscriptionPopup();" src="images/button-nothanks.jpg"></div>';
    html +='        </div>';
    html +='     </div>';
    html +='</div>';
    popupContainer.innerHTML = html;
    popupContainer.style.display = "block";
}

//---------------------------------------------------------------

function ShowHelpPopup(type)
{
    var popupContainer = $get("mixerHelpPopup");
    var html = null;
    var title = null;
    var helpContent = null;
    
    switch (type)
    {
        case "timeline" :
            title = "Timeline";
            helpContent = "The timeline contains all the layers. At the top of the time line there is a ruler. Each segment equals a frame. There are 25 frames per second.  Time in seconds are marked every 2 (ex. 2, 4, 6, 8)."
            break;
        case "videolayer" :
            title = "Video Layer";
            helpContent = "The video layer is the base of your ad and contains the footages you selected. You can add effects, change the length, and adjust the transparency.  You can add up to a maximum of 3 videos to your ad."
            break;
        case "textlayer" :
            title = "Text Layer";
            helpContent = "The text layer contains text that is visible while the video plays in the background. Use this layer to insert a company slogan, website address, or phone number to run over the video image."
            break;
        case "imagelayer" :
            title = "Image Layer";
            helpContent = "The image layer is where you can upload image files that block the video in the background. Use this layer as a title card or an end frame that contains a logo or picture, as well as promotional text to convey an advertising message."
            break;
        case "Soundtrack" :
            title = "Soundtrack Layer";
            helpContent = "The soundtrack layer allows you to access our music gallery for your ad.  You can add up to a maximum of 2 music tracks to your video ad."
            break;
        case "narration" :
            title = "Narration";
            helpContent = "The narration layer lets you record your own narration for your ad. All you need is a microphone.  You can also upload a narration you already have in MP3 format."
            break;
        case "soundeffects" :
            title = "Sound Effects";
            helpContent = "Choose sound effects from our audio effects library to make your video ad stand out."
            break;
        case "videocontrols" :
            title = "Video Controls";
            helpContent = "Press the Play button at anytime to watch your clip. Fast-Forward to get to the end of the clip and Rewind to get to the beginning. You may also drag the black triangle-shaped marker at the top of the timeline back and forth to view a particular frame."
            break;
        case "timelinezoom" :
            title = "Timeline Zoom";
            helpContent = "In order to zoom in or out of the timeline, shift the slider at the top left corner of the timeline."
            break;
    }
    popupContainer.style.display = "none";
    popupContainer.style.position = "absolute";
    popupContainer.style.left = 200 +  'px';
    popupContainer.style.top = 300 +  'px';
    
    html = '<div style="width:280px;height:115px;margin-left:5px;margin-top:10px">';
    html +='    <div style="float:right;height:15px;cursor:pointer" onclick="HideHelpPopup();"><img src="../images/close_tiptool.jpg"></div>'
    html +='    <div style="clear:right;width:270px" >';
    html +='        <div >';
    html +='            <div class="grayLabel" style="text-align:left;font-size:11px;padding-bottom:5px">' + title + '</div>';
    html +='        </div>';
    html +='        <div>';
    html +='            <div style="text-align:left;font-size:11px">' + helpContent + '</div>';
    html +='        </div>';
    html +='    </div>';
    html +='</div>';
    popupContainer.innerHTML = html;
    popupContainer.style.display = "block";
}

//---------------------------------------------------------------

function ShowSearchHelpPopup()
{
    var searchHelpContainer = $get("SearchHelp");
    searchHelpContainer.style.position = "absolute";
    searchHelpContainer.style.display = "block";
}

//---------------------------------------------------------------

function HideSubscriptionPopup()
{
    var popupContainer = $get("subscriptionPopup");
    popupContainer.style.display = "none";
}

//---------------------------------------------------------------

function HideHelpPopup()
{
    var popupContainer = $get("mixerHelpPopup");
    popupContainer.style.display = "none";
}

//---------------------------------------------------------------

function HideSearchHelpPopup()
{
    var searchHelpContainer = $get("SearchHelp");
    searchHelpContainer.style.display = "none";
}

//---------------------------------------------------------------

function MarkFootage(sender, imgId, footageGuid)
{
    var oXmlHttp;
    var sPostUrl = "MarkFootage.aspx?g="+ footageGuid + "&mark=" + sender.checked;
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
        oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
        oXmlHttp.open ("POST", sPostUrl , false);
    }
    else
    {
        oXmlHttp = new XMLHttpRequest();
        oXmlHttp.open ("GET", sPostUrl , true);
    }
    
    if (oXmlHttp != null)
    {
        oXmlHttp.onreadystatechange = function ()
        {
            if (oXmlHttp.readyState == 4 )
            {
	            if (oXmlHttp.status==200)
	            {
	                if (oXmlHttp.responseText == "marked")
                    {
                         if (sender.checked)
                         {
                            document.getElementById(imgId).src = document.getElementById(imgId).src.replace(footageGuid + ".png", footageGuid + "_free.png");
                         }
                         else
                         {
                            document.getElementById(imgId).src = document.getElementById(imgId).src.replace("_free", "");
                         }
                    }
	            }
	        } 
	    }
	    oXmlHttp.send (null);
    }  
}

//---------------------------------------------------------------

function SetFootageRating(sender, footageGuid)
{
    var oXmlHttp;
    var sPostUrl = "SetFootageRating.aspx?g="+ footageGuid + "&rating=" + sender.value;
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
        oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
        oXmlHttp.open ("POST", sPostUrl , false);
    }
    else
    {
        oXmlHttp = new XMLHttpRequest();
        oXmlHttp.open ("GET", sPostUrl , true);
    }
    
    if (oXmlHttp != null)
    {
        oXmlHttp.onreadystatechange = function ()
        {
            if (oXmlHttp.readyState == 4 )
            {
	            if (oXmlHttp.status==200)
	            {
	                if (oXmlHttp.responseText == "success")
                    {
                         
                    }
	            }
	        } 
	    }
	    oXmlHttp.send (null);
    }  
}

//---------------------------------------------------------------

function AddFootageToCollection(footageGuid, sFile, sDescription, sImage)
{
    var footageGalleryWin = GetRadWindow();
    var mixerPage = footageGalleryWin.BrowserWindow;
    var res = new Object();
    res.ID = footageGuid;
    res.description = sDescription;
    res.thumbnail = sImage;
    res.resourceURL = sFile;
    res.updateType = mixerPage.getCurrentGallery();
    mixerPage._folderCollection.push(res)
}

//---------------------------------------------------------------

function RemoveFootageFromCollection(id)
{
    var footageGalleryWin = GetRadWindow();
    var mixerPage = null;
    var folderCollection = null;
    var tmpFolderCollection = [];
    var removeFromMixer;
    
    if (footageGalleryWin == null)
    {
        folderCollection = _folderCollection;
        removeFromMixer = true;
    }
    else
    {
        mixerPage = footageGalleryWin.BrowserWindow;
        folderCollection = mixerPage._folderCollection
        removeFromMixer = false;
    }
    
    for (var i = 0; i < folderCollection.length; i++)
    {
        if (folderCollection[i].ID != id)
        {
            tmpFolderCollection.push(folderCollection[i])
        }
    }
    
    if (removeFromMixer)
    {
        _folderCollection = tmpFolderCollection;
    }
    else
    {
        mixerPage._folderCollection = tmpFolderCollection;
    }
}

//---------------------------------------------------------------

function OpenFootageFolder()
{
    if (isMenuEnable)
    {
        oFlash.Create('Video');
        //FlashProxy.openFootageFolder();
    }
}

//---------------------------------------------------------------

function ChangeMenuBehavior()
{
    var videoLayers = GetLayerObjects('Video');
    if (videoLayers > 0)
    {
        if (!isMenuEnable)
        {
            for (var i = 0; i < layers.length; i++)
            {   
                  var oSection = document.getElementById(layers[i] + "Section");   
                  oSection.className = "subTitle";
            }
    
            //document.getElementById("mixerMenu").className = 'menu';
            isMenuEnable = true;
            //document.getElementById("wizardOptionNotice").style.display = 'none'; 
        }
    }
    else
    {
        if (isMenuEnable)
        {
            for (var i = 0; i < layers.length; i++)
            {   
                  var oSection = document.getElementById(layers[i] + "Section");   
                  oSection.className = "subTitleDisable";
            }
            //document.getElementById("mixerMenu").className = 'menuDisable';
            isMenuEnable = false;
            ResetMenu();
        }
        //document.getElementById("wizardOptionNotice").style.display = 'block'; 
    }
}

//---------------------------------------------------------------

function ResetMenu()
{
    for (var i = 0; i < layers.length; i++)
    {   
          var optionsLayerTitle = document.getElementById(layers[i] + "Options");   
          var optionsLayerHolder = document.getElementById(layers[i] + "OptionsHolder");
          optionsLayerTitle.style.display = 'none';
          optionsLayerHolder.innerHTML = '';
    }
    var itemsCountHolder = document.getElementById("VideoItemsCountHolder"); 
    itemsCountHolder.innerHTML = '(0 Items)';
}

//---------------------------------------------------------------

function AddToFreeFootageCollection(obj, freeSignId)
{
    var res = new Object();
    var isElelemtExist = false;
    res.obj = obj;
    res.freeSignId = freeSignId;
  
    for (var i = 0; i < _freeFootageCollection.length; i++)
    {
        if (_freeFootageCollection[i].freeSignId == freeSignId)
        {
            isElelemtExist = true;
            break;
            
        }
    }
    
    if (!isElelemtExist)
    {
        _freeFootageCollection.push(res)
    }
}

//---------------------------------------------------------------

function SignFreeFootage()
{   
    var freeSignId;
    var obj;
    var freeSignObj;
    var coors;
    var xLeft = 10;
    var yTop = document.all ? 173 : 340;
    var addToTop = document.all ? 142 : 136;
    var addToTopWithAdminZone = document.all ? 25 : 47;
    var adminZone = document.getElementById("pnlAdminZone");
    
    for (var i = 0; i < _freeFootageCollection.length; i++)
    {
        freeSignId = _freeFootageCollection[i].freeSignId;
        //obj = _freeFootageCollection[i].obj;
        var freeSignObj = $get(freeSignId);
        //var coors = FindPos(obj);
        //var xLeft = coors[0];
        //var yTop = coors[1];
        
        
        if (i > 0)
        {
            if (adminZone != null)
            {
                yTop += (addToTop + addToTopWithAdminZone);
            }
            else
            {
                yTop += addToTop;
            }
        }
        
        if (freeSignObj != null)
        {
            freeSignObj.style.position = 'absolute';
            freeSignObj.style.top = yTop + 'px';
            freeSignObj.style.left = xLeft + 'px';
            freeSignObj.style.zIndex = 500;
            freeSignObj.style.display = 'block';
        }
    }
}