﻿var BrettBox = {

    _caption: undefined,
    _src: undefined,
    _windowHeight: undefined,
    _windowWidth: undefined,
    _flashPath: undefined,
    
    getType: function(){        
        switch(BrettBox._src.substring(BrettBox._src.lastIndexOf('.')))
        {
            case ".jpg":
                return "image";
                break;
            case ".bmp":
                return "image";
                break;
            case ".gif":
                return "image";
                break;   
            case ".png":
                return "image";
                break;  
            case ".swf":
                return "flash";
                break;                                           
        }
    },

    remove: function(){
        $('img', '#brettWindow .header').fadeOut(500);
        $('.caption', '#brettWindow').css('visibility', 'hidden');
        $('.content', '#brettWindow').empty();
        $('#brettWindow').slideUp(500, function(){
            $(this).remove();
            $('#overlay').fadeOut(500, function(){
                $(this).remove();
            });
        });
    },

    render: function(src, windowWidth, windowHeight, caption, flashPath){
        var ratio = windowWidth / windowHeight;
        var wH = $(window).height() - 120;
        
        if (windowHeight > wH)
        {
            windowHeight = wH;
            windowWidth = parseInt(wH * ratio);
        }      
        
        this._src = src;
        this._caption = (caption != undefined) ? caption : undefined;
        this._windowHeight = isNaN(parseInt(windowHeight)) ? 0 : parseInt(windowHeight);
        this._windowWidth = isNaN(parseInt(windowWidth)) ? 0 : parseInt(windowWidth);   
        this._flashPath = (flashPath != undefined) ? flashPath : undefined;
        
        $('body').append('<div id="overlay" style="filter:alpha(opacity=50);">&#160;</div>');                           
    
        $('#overlay').fadeIn(500, function(){            
            $(this).click(function(){
                BrettBox.remove();                
            });
            
            var bw = '<div id="brettWindow"><div class="header"><img src="images/closelabel.gif" /></div><div class="content"></div><div class="caption"></div></div>';
            $('body').append(bw);
           
            $('#brettWindow').show();
            $('#brettWindow').animate({
                height: (BrettBox._windowHeight + 22) + "px",
                marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
            }, 600, function(){
                $('#brettWindow').animate({
                    marginLeft: "-" + (parseInt(BrettBox._windowWidth/2) + 10) + "px",
                    width: BrettBox._windowWidth + "px"
                }, 600, function(){     
                
                    $('.content', '#brettWindow').css({
                        height: BrettBox._windowHeight+"px",
                        width: BrettBox._windowWidth+"px"
                    });          
                    
                    if (!(!BrettBox._caption))
                    {
                        $('.caption', '#brettWindow').text(BrettBox._caption).show();
                        BrettBox._windowHeight += $('.caption', '#brettWindow').height() + 10;
                        $('#brettWindow').animate({
                            height: (BrettBox._windowHeight + 22) + "px",
                            marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
                        }, 600, function(){
                            $('.caption', '#brettWindow').css('visibility', 'visible'); 
                            BrettBox._windowHeight -= $('.caption', '#brettWindow').height() + 10;
                            BrettBox.replaceContent();
                        });
                    }
                    else
                        BrettBox.replaceContent();
                        
                }); 
            });
        });
    },
    renderImage: function(src, windowWidth, windowHeight, caption, flashPath){
        var ratio = windowWidth / windowHeight;
        var wH = $(window).height() - 120;
        
        if (windowHeight > wH)
        {
            windowHeight = wH;
            windowWidth = parseInt(wH * ratio);
        }      
        
        this._src = src;
        this._caption = (caption != undefined) ? caption : undefined;
        this._windowHeight = isNaN(parseInt(windowHeight)) ? 0 : parseInt(windowHeight);
        this._windowWidth = isNaN(parseInt(windowWidth)) ? 0 : parseInt(windowWidth);   
        this._flashPath = (flashPath != undefined) ? flashPath : undefined;
        
        $('body').append('<div id="overlay" style="filter:alpha(opacity=50);">&#160;</div>');                           
    
        $('#overlay').fadeIn(500, function(){            
            $(this).click(function(){
                BrettBox.remove();                
            });
            
            var bw = '<div id="brettWindow"><div class="header"><img src="images/closelabel.gif" /></div><div class="content"></div><div class="caption"></div></div>';
            $('body').append(bw);
           
            $('#brettWindow').show();
            $('#brettWindow').animate({
                height: (BrettBox._windowHeight + 22) + "px",
                marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
            }, 600, function(){
                $('#brettWindow').animate({
                    marginLeft: "-" + (parseInt(BrettBox._windowWidth/2) + 10) + "px",
                    width: BrettBox._windowWidth + "px"
                }, 600, function(){     
                
                    $('.content', '#brettWindow').css({
                        height: BrettBox._windowHeight+"px",
                        width: BrettBox._windowWidth+"px"
                    });          
                    
                    if (!(!BrettBox._caption))
                    {
                        $('.caption', '#brettWindow').html(BrettBox._caption).show();
                        BrettBox._windowHeight += $('.caption', '#brettWindow').height() + 10;
                        $('#brettWindow').animate({
                            height: (BrettBox._windowHeight + 22) + "px",
                            marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
                        }, 600, function(){
                            $('.caption', '#brettWindow').css('visibility', 'visible'); 
                            BrettBox._windowHeight -= $('.caption', '#brettWindow').height() + 10;
                            BrettBox.replaceContent();
                        });
                    }
                    else
                        BrettBox.replaceContent();
                        
                }); 
            });
        });
    },
    
    replaceContent: function(){
        switch (BrettBox.getType())
        {
            case "flash":
                $('.content', '#brettWindow').html('<object type="application/x-shockwave-flash" ' + (BrettBox._flashPath != undefined ? 'flashvars="importedPath='+BrettBox._flashPath+'"' : '') + ' data="' + BrettBox._src +'" width="' + BrettBox._windowWidth +'" height="' + BrettBox._windowHeight + '"><param name="movie" value="' + BrettBox._src +'" /></object>');
                break;
            case "image":                     
                $('.content', '#brettWindow').html('<img src="' + BrettBox._src + '" height="' + BrettBox._windowHeight + 'px" width="' + BrettBox._windowWidth + 'px" />');
                break;
        }   
        
        $('img', '#brettWindow .header').click(function(){
            BrettBox.remove();
        }).fadeIn(500);     
    },
    renderPlayer: function(src, windowWidth, windowHeight, caption, flashPath){
    	var caption = '<div id="videoPlayer"><script type="text/javascript" src="http://www.smithoptics.com/flash/swfobject.js"></script><script type="text/javascript">var flashvars = {htmlPage: "http://www.smithoptics.com/lounge.html/#/",settingsFile: "http://www.smithoptics.com/flash/xml/settings.xml",img: "http://www.smithoptics.com/uploads/videos/endFrameImage.jpg",currVideo: "0",vp: "http://www.smithoptics.com/uploads/videos/'+ src +'"};var params = {allowFullScreen: "true"};swfobject.embedSWF("http://www.smithoptics.com/flash/videoPlayer.swf", "videoPlayer", "640", "380", "9.0.115", "", flashvars, params);</script><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>'; 
    	var windowWidth = 640;
    	var windowHeight = 380;
        var ratio = windowWidth / windowHeight;
        var wH = $(window).height() - 120;
        
        if (windowHeight > wH)
        {
            windowHeight = wH;
            windowWidth = parseInt(wH * ratio);
        }      
        
        this._src = src;
        this._caption = (caption != undefined) ? caption : undefined;
        this._windowHeight = isNaN(parseInt(windowHeight)) ? 0 : parseInt(windowHeight);
        this._windowWidth = isNaN(parseInt(windowWidth)) ? 0 : parseInt(windowWidth);   
        this._flashPath = (flashPath != undefined) ? flashPath : undefined;
        
        $('body').append('<div id="overlay" style="filter:alpha(opacity=50);">&#160;</div>');                           
    
        $('#overlay').fadeIn(500, function(){            
            $(this).click(function(){
                BrettBox.remove();                
            });
            
            var bw = '<div id="brettWindow"><div class="content"></div><div class="header"><img src="images/sourcecode.gif" /></div><div class="caption"></div></div>';
            $('body').append(bw);
           
            $('#brettWindow').show();
            $('#brettWindow').animate({
                height: (BrettBox._windowHeight + 22) + "px",
                marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
            }, 600, function(){
                $('#brettWindow').animate({
                    marginLeft: "-" + (parseInt(BrettBox._windowWidth/2) + 10) + "px",
                    width: BrettBox._windowWidth + "px"
                }, 600, function(){     
                
                    $('.content', '#brettWindow').css({
                        height: BrettBox._windowHeight+"px",
                        width: BrettBox._windowWidth+"px"
                    });          
                    
                    if (!(!BrettBox._caption))
                    {
                        $('.caption', '#brettWindow').text(BrettBox._caption).show();
                        BrettBox._windowHeight += $('.caption', '#brettWindow').height() + 10;
                        $('#brettWindow').animate({
                            height: (BrettBox._windowHeight + 22) + "px",
                            marginTop: "-" + (parseInt(BrettBox._windowHeight/2) + 21) + "px"
                        }, 600, function(){
                            $('.caption', '#brettWindow').css('visibility', 'visible'); 
                            BrettBox._windowHeight -= $('.caption', '#brettWindow').height() + 10;
                            BrettBox.replaceContentPlayer();
                        });
                    }
                    else
                        BrettBox.replaceContentPlayer();
                        
                }); 
            });
        });
    },
    //swfobject.embedSWF("http://www.smithoptics.com/flash/videoPlayer.swf", "c", "640", "380", "9.0.115", "", flashvars, params);
   
      
		  
    //<PARAM NAME=FlashVars VALUE="htmlPage=AmericanDream.mp3&mySong2=FewFarBetween.mp3&mySong3=Rain.mp3">
    replaceContentPlayer: function(){
    	var htmlPage = "http://www.smithoptics.com/lounge.html";
  	  var settingsFile = "http://www.smithoptics.com/flash/xml/settings.xml";
  	  var img = "http://www.smithoptics.com/uploads/videos/endFrameImage.jpg";
  	  var currVideo = "0";
  	  var vp = "http://www.smithoptics.com/uploads/videos/"+ this._src;
  	  var flashValues = "htmlPage="+ htmlPage +"&settingsFile="+ settingsFile +"&img="+ img +"&currVideo="+ currVideo+"&vp="+vp;
  	  
                $('.content', '#brettWindow').html('<object type="application/x-shockwave-flash" vp="+ vp +" data="http://www.smithoptics.com/flash/videoPlayer.swf" width="640" height="380"><param name="movie" value="http://www.smithoptics.com/flash/videoPlayer.swf" /><PARAM NAME=FlashVars VALUE="'+ flashValues +'"/></object>');
           
        
        $('img', '#brettWindow .header').click(function(){
            BrettBox.remove();
        }).fadeIn(500);     
    }

}