
var FlashGallery = Gallery.extend({

    swf: null,
    swfObj: null, 
    
    constructor: function( swf, swfObj ) {
        // console.log("FlashGallery constructed!!" + swf );
        this.swf = swf;
        this.swfObject = swfObj;
        this.setIframe();
	},
	
	loadImage: function( e ){
	    var tar = e.target || e.srcElement;
        if(tar.nodeName.toLowerCase() == "img")
           tar = tar.parentNode;  
	    var txt = tar.href.toString();
	    var playlistId = "";
	    txt = txt.split("?")[1];
	    var displayType = txt.split("=")[0];
	    playlistId = txt.split("=")[1];
	    //txt = document.createTextNode( txt );
	    // console.log("FlashGallery::loadImage();" + tar );
	    
	    var so = new SWFObject(this.swf + "&" + displayType + "=" + playlistId, 
	                            "HRPMediaPlayer", 
	                            "932", 
	                            "612", 
	                            "8", 
	                            "transparent");
	                         
		so.addParam("wmode", "transparent");
		so.addParam("quality", "high");
        so.addParam("allowScriptAccess", "sameDomain");
        so.addParam("allowFullScreen", "false");
        so.addParam("align", "middle");
        so.addParam("name", "HRPMediaPlayer");
        so.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");
		so.write( this.wrapper );
		// console.log(this.title);
		
		//this.title.appendChild( txt );
	    this.title.style.visibility = "visible";
	    this.adjust();
	    this.showGallery();
	    
	},
	
	showGallery: function(){
		this.preloader.show();
		this.setOpacity( this.overlay, 75 );
		this.showIframe();
		this.show( this.overlay );
		this.show( this.gallery );
	},
	
	iShim: null,
	
	setIframe: function(){
	    if (document.all) 
        { 
            var body = document.getElementsByTagName("body")[0];
            body.insertAdjacentHTML("beforeEnd", '<IFRAME style="display: none; width: 0; height: 0;" src="" frameBorder="0" scrolling="no" id="iShim" />'); 
            this.iShim = document.getElementById("iShim"); 
        }
	},
	
    hideIframe: function(){
        if (document.all) 
        { 
            this.iShim.style.display = 'none';
            // alert("hideIframe()" + this.iShim.style.display);
        }
    },
    
    showIframe: function(){
        // alert("showIframe()");
        if (document.all) 
        { 
            this.iShim.style.display = "block";
        }
    },
    
    setIframePos: function(w, h, l, t){
        if (document.all) 
        { 
            //alert(l + ", "+ t);
            this.iShim.style.marginTop = t+"px"; 
            this.iShim.style.marginLeft = l+"px"; 
            this.iShim.style.width = w+"px"; 
            this.iShim.style.height = h+"px"; 
            // this.iShim.style.border = "solid 1px #c00";
        }
    },
	
	remove: function(){
	    this.hideIframe();
	    this.hideGallery();
	    this.wrapper.removeChild(this.wrapper.firstChild);
	},
	
	adjust: function(){
	    //alert("adjust()");
	    var w = 932;
        var h = 612;
        /*var l = this.scrollX() + 
                ( this.windowWidth() / 2 ) - ( w / 2 );
        var t = this.scrollY() + 
                ( this.windowHeight() / 2 ) - ( h / 2); */
              
        var l = "-" + (w/2);
        var t = "-" + (h/2);
        this.setIframePos(w, h, l, t);
        /*if( l < 0 ){
            l = 0;
        };
        if( t < 0 ){
            t = 0;
        }*/
        this.setOverlay();
        this.setX( this.gallery, l );
        this.setY( this.gallery, t );

        window.onresize = window.onscroll = this.reset( this, this.adjust );
	}
});
