﻿
//iterates all links in content to check for 'rel="FlowPlayer"'. If found, grabs the link ID and calls the js f() to embed FlowPlayer
function checkVideoEmbed(content_id) {
    
    //gets the elements
    var content = document.getElementById(content_id); //content div
    var arrObjects = content.getElementsByTagName("object"); //object in content div
    for (i = 0; i < arrObjects.length; i++) { //iterate <objects> in page
        if (arrObjects[i].attributes.getNamedItem("rel") != null) { //checks if rel attr.
            if (arrObjects[i].attributes.getNamedItem("rel").value == "FlowPlayer") { //check if rel attr = "FlowPlayer"
                var curr_obj = arrObjects[i]; //gets current <object ... rel="FlowPlayer" ...>
                var height = curr_obj.attributes.getNamedItem("height").value; //gets height / width
                var width = curr_obj.attributes.getNamedItem("width").value;
                var url; //url of the file (parsed out below
                var embed = true; //whether to embed FlowPlayer
                var arrChildObjects = curr_obj.getElementsByTagName("param"); //gets all <param ...> elements of current <object>
                for (j = 0; j < arrChildObjects.length; j++) { //iterate child param objects
                    if (arrChildObjects[j].attributes.getNamedItem("name") != null) { //checks if name attr
                        if (arrChildObjects[j].attributes.getNamedItem("name").value == "Movie") { //check if name attr = "Movie" (per CuteEditor)
                            url = arrChildObjects[j].attributes.getNamedItem("value").value; //gets the value attr, which is the flv url
                            url = url.substring(url.indexOf("videoUrl=") + 9, url.length - 1); //snips off CuteEditor stuff in url
                            url = url.substring(url.indexOf("files/")); //snips off http:// ... to files/...
                            url = "/" + url.substring(0, url.indexOf("&")); //snips off everything after ".flv" (CuteEditor adds stuff)
                            if (url.indexOf(".flv") < 0) { embed = false; } //only load FlowPlayer for FLV files (vs. swf)
                        }
                    }
                }
                //FlowPlayer embeds in an anchor, so create it
                var container = document.createElement('a')
                //generate random ID as CuteEditor does not add ids to <object>
                var container_id = "c_" + new Date().getTime(); //getTime is milliseconds since 1970, so will be unique
                container.id = container_id //set id
                container.setAttribute("style", "height:" + height + "px; width:" + width + "px; display:block;"); //add styles
                container.href = url; //add url to flv
                //replaces <object> with <a> (req'd for FlowPlayer); see: http://my.opera.com/Ti/blog/show.dml/423621
                curr_obj.parentNode.replaceChild(container, curr_obj);
                //embeds FlowPlayer if appr.
                if(embed) {
                    //loadFlowPlayer script on pg calling this file
                    loadFlowPlayer(container_id); //gets ID of new link and sends it to embed f()
                }
            }
        }
    }
}

/*
NOTES:
- rel="FlowPlayer" inserted into CuteEditor Flash embed code to act as hook for this script (so other <object>s in page are not also overwritten): \CuteSoft_Client\CuteEditor\Scripts\Dialogs\Dialog_InsertFlash.js  ln 1
- FlowPlayer js inserted into CuteEditor Flash Dialog page: \CuteSoft_Client\CuteEditor\Dialogs\InsertFlash.aspx  lns 37 - 61
- The HTML FlowPlayer is looking for to add video to page, is (update text in []): <p><a id="[unique id]" style="display: block; width: [width]px; height: [height + 23]px;" href="files/video/[video file].flv" rel="FlowPlayer"></a></p>
- The js in this page re-writes the CuteEditor Flash embed to the HTML for FlowPlayer
- The script below will embed FlowPlayer into any hard-coded FlowPlayer <a href...></a>
	        
//Hard-Code FlowPlayer Embed Script:
// usage: Add this HTML to the page (update text in []): <p><a id="[unique id]" style="display: block; width: [width]px; height: [height + 23]px;" href="files/video/[video file].flv" rel="FlowPlayer"></a></p> 
var content = document.getElementById("content"); //content div
var arrLinks = content.getElementsByTagName("a"); //link in content div
for (i = 0; i < arrLinks.length; i++) { //iterate links
    if (arrLinks[i].attributes.getNamedItem("rel") != null) { //checks if rel attr.
        if (arrLinks[i].attributes.getNamedItem("rel").value == "FlowPlayer") { //check if rel attr = "FlowPlayer
            loadFlowPlayer(arrLinks[i].id); //gets ID of link and sends it to embed f()
        }
    }
}
*/