﻿// sets size and position of the movie div
function fixWinSize(w,h)
{


    h = h -10;
    var top = $(document).scrollTop() +  document.documentElement.clientHeight/2-h/2;
    
    $('#smmoviecontainer').css({  
        "position": "absolute",  
        "top": top + "px",  
        "left":  document.documentElement.clientWidth/2-w/2 + "px",
        "display": "block",
        "width": "auto",
        "height": "auto"
    });
    
    $('#smmovieplayerwindow').css({  
        "width": w + "px",
        "height": h + "px",
        "display": "block"
    });
}

// called by movieplayer
function contentSize(winsize) {
    var w = winsize.split(":")[0];
    var h = winsize.split(":")[1];
    fixWinSize(w,h);
}

// opening movie window
function OpenWindow()
{
    $('#smmoviecontainer').fadeIn("fast");
    $('#smmovieplayerbackground').fadeIn("fast");
}

// closing movie
function CloseMovie()
{
    $('#smmoviecontainer').fadeOut("fast");
    $('#smmovieplayerwindow').text("");
    $('#smmovieplayerbackground').fadeOut("fast");
}
                    

// adding and handling click events to flv links
$(document).ready(function() {
     
    $('a[href*=.flv], a[href*=.f4v], a[href*=film.aspx]').each(function(){
            $(this).click(function(){
                
                var movie = $(this).attr('href');
                
                
                // add movie background div if it does not already exist
                if($('#smmovieplayerbackground').length == 0)
                {
                    $(document.body).append("<div id='smmovieplayerbackground'>background</div>");
                    $('#smmovieplayerbackground').css({  
                        "position": "absolute",  
                        "top": "0px",  
                        "left": "0px",
                        "width": "100%",
                        "height":  $(document).height(),
                        "background-color" : "#000000",
                        "opacity" : "0.4",
                        "display" : "none"
                    }); 
                    
                    $('#smmovieplayerbackground').click(function(){
                        CloseMovie();
                    });
                }
                
                // add movie div if it does not already exist
                if($('#smmoviecontainer').length == 0)
                {
                    var header = $(this).attr('title') != "" ? $(this).attr('title') : "Movie";
                    $(document.body).append("<div id='smmoviecontainer'><div id='smmovieplayerwindow'></div></div>");
                    
                    $('#smmovietoolbar').css({  
                        "background-color": "#000000",  
                        "color": "#eeeeee",
                        "display": "block",
                        "padding": "0 1em",
                        "text-align": "left"
                        });
                    
                    $('#smmovietoolbar a').css({  
                        "float": "right"
                        });

                    var wi = 550;
                    var hi = 800;
                    
                    $('#smmoviecontainer').css({  
                        "position": "absolute",
                        "background-color": "#ffffff",  
                        "top": document.documentElement.clientHeight/2-hi/2 + "px",  
                        "left":  document.documentElement.clientWidth/2-wi/2 + "px",
                        "width": wi + "px",
                        "height": hi + "px"
                        });

                }

                // embed flash
               /* if(flashembed.isSupported([9,115]))
                {
                    $('#smmovieplayerwindow').flashembed(
                            {src:'/SMControls/Resources/Flash/VideoPlayer.swf',bgcolor:'#ffffff',quality:'high'},
                            {flvFile: movie ,maxHeight:'700'}
                            )
                }
                else
                {
                    $('#smmovieplayerwindow').css({  
                        "padding": "2em"
                        });
                    $('#smmovieplayerwindow').html("Your browser does not support Flash 9. Please download from <a href='http://www.adobe.com/go/getflashplayer' target='_blank'>Adobe</a>");
                }*/
                
                $('#smmovieplayerwindow').html("<object width='800' height='550'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=11759613&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id=11759613&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='800' height='550'></embed></object>");
                // show windows
                
                OpenWindow();
                fixWinSize(800,550);
                return false;
            });
    });


});