/*******************************************************************************
 * Class for embedding flash into the Lightbox
 * *****************************************************************************
 *
 * @author Stanislav Zorjan - Stasha - [zstasa][@][yahoo].[com]
 * 
 *
 * Licensed under the Creative Commons Attribution 3.0 License
 * http://creativecommons.org/licenses/by/3.0/
 *
 * - Free for use in both personal and commercial projects
 * - Attribution requires leaving author name, author link, and the license info intact.
 *



/*                            !!!!  ATTENTION !!!                             */
/* The FlashInLightBox class uses "swfobject" for embedding flash into the Lightbox
 * swfobject can be downloaded from: http://code.google.com/p/swfobject/
 * ****************************************************************************/

/* THE INFO ON HOW TO USE THIS CLASS IS ON THE BOTTOM OF THE CLASS */

/* Class was build and tested on
 * Lightbox v2.04       http://www.lokeshdhakar.com/projects/lightbox2/
 * swfobject v2.1       http://code.google.com/p/swfobject/
 *
 * Tested on Browsers
 * IE 6, 7
 * FF 3.0.5
 * Opera 9.63
 * Safari 3.1.2
 * Chrome 1.0.154.43

/*******************************************************************************
 * Constructor
 */
function FlashInLightBox(){
    var _this = this;
    /*link to video*/
    this.url = "";
    
    /**************************************************************************/
    /* PARAMETERS */
    
    /*interval after which video is embedded to stage.
     *This is needed because of Lightbox animation.
     *If the value of timeout is smaller than animation time
     *video may be embedded on wrong position, or it won't be 
     *visible. If You experience such a problems than try to 
     *increase this value.
     */
    this.timeout = 2000 // milliseconds;

    /* END OF PARAMETERS */
    /**************************************************************************/
    
     this.interval = 0;

    /***************************************************************************
     * Method for embeding video
     */
    this.embed = function(url){
        if(url != ''){

            this.url = url;

            var imageContainer = document.getElementById("imageContainer");

            try{
                imageContainer.removeChild(document.getElementById("flash"));
            }catch(e){};

            var flash = document.createElement("div");
            var flash_holder = document.createElement("div");

            flash.setAttribute("id", "flash");
            flash_holder.setAttribute("id", "flash_holder");
            flash_holder.setAttribute("style", "position:absolute");
            flash.appendChild(flash_holder);

            imageContainer.appendChild(flash);
 
            this.a = setInterval(function(){
                _this.embed2()
            }, this.timeout);
            
        }
    }

    /***************************************************************************
     * Method invoked by timer event for embedding
     */
    this.embed2 = function(){
       
        clearInterval(this.a);
        var image = document.getElementById('imageContainer');
        var flash = document.getElementById('flash');
        flash.style.position = "absolute";
        flash.style.clear = "both";

        flash.style.top = image.offsetTop + image.offsetTop + image.firstChild.offsetTop +"px";
        flash.style.left = image.offsetLeft  + image.firstChild.offsetLeft+"px";
        swfobject.embedSWF(this.url, "flash_holder", parseInt(image.firstChild.offsetWidth), parseInt(image.firstChild.offsetHeight), "9.0.0");
    }


}

/* Creating new object of FlashInLightBox */
var flash_in_lightbox = new FlashInLightBox();


/* EXAMPLE OF SIMPLE Lightbox LING WITHOUT FLASH */
/* <a href="images/image-1.jpg" rel="lightbox" title="my caption">image #1</a> */

/* EXAMPLE OF LINK WITH EMBEDDING FLASH TO Lightbox */
/* <a onclick="flash_in_lightbox.embed('http://www.youtube.com/v/wUNOacSRNyM&hl=cs&fs=1')" href="images/EMPTY_IMAGE.jpg" rel="lightbox" title="my caption">image #2</a> */

/* The flash will be resized to size of image you pass to Lightbox, in this case it is "EMPTY_IMAGE.jpg" */
/* First is displayed image You pass to Lightbox and then flash is embedded */


/* Order in which javascripts should be included in the html page */

/*
   <script type="text/javascript" src="js/prototype.js"></script>
   <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
   <script type="text/javascript" src="js/lightbox.js"></script>
   <script type="text/javascript" src="js/swfobject.js"></script>
   <script type="text/javascript" src="js/FlashInLightBox.js"></script>
*/
