$(document).ready(function(){

    // When mouseover media thumbnail, display title over image
    $('.videoThumb').mouseenter(function(){

        var MediaId = $(this).attr('media_id');
        $("#"+MediaId+"_div").fadeIn('fast');

        // When mouse moves out, then close the display
        $(this).mouseleave(function(){
            $("#"+MediaId+"_div").fadeOut('fast');
        });

    });


    // Place logo on center of screen
    var HeightMT = ($(window).height()/2)-97;
    $('#homeLink').css({marginTop: HeightMT});

    // On Logo mouse over, display menu
    $('#homeLink').mouseenter(function(){

        $('#ContentDiv').animate({opacity:0.25});
        var DocumentHeight = $(document).height()-$('#homeLink').height();

        $('#MainNavigation').css({height: DocumentHeight});
        $('#MainNavigation').slideDown(1000);
        $('#homeLink').animate({marginTop: "0"},1000);

        //$('#MainNavigation').animate({height: DocumentHeight});

    });

    /// After leaving WHOLE left container, then close the left menu
    $('#LeftCont').mouseleave(function(){

        $('#MainNavigation').slideUp(1000);

        var HeightMT = ($(window).height()/2)-$('#homeLink').height();
        $('#homeLink').animate({marginTop: HeightMT},1000,function(){
            $('#ContentDiv').animate({opacity:1});
        });

    });

    // Toggle directors menu
    $("#directorsUL").toggle(function(event){

       $("#DirectorList").show('slow');
        event.preventDefault();

    },function(event){

       $("#DirectorList").hide('slow');
        event.preventDefault();

    });

	  //Get our elements for faster access and set overlay width
  var div = $('div.sc_menu'),
       ul = $('ul.sc_menu'),
       // unordered list's left margin
       ulPadding = 0;

  //Get menu width
  var divWidth = div.width();

  //Remove scrollbars
  div.css({overflow: 'hidden'});

  //Find last image container
  var lastLi = ul.find('li:last-child');

  //When user move mouse over menu
  div.mousemove(function(e){

    //As images are loaded ul width increases,
    //so we recalculate it each time
    var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

    var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
    div.scrollLeft(left);
  });

});

function playMediaFile(MediaTarget,MediaWidth,MediaHeight,URL,MEDIAID)
{

	var FULLMediaURL = "http://c0894682.cdn.cloudfiles.rackspacecloud.com/"+MediaTarget;

    $('.VideoPlayer').animate({width:MediaWidth, height:MediaHeight, opacity: 1.0},"slow");
    $('.VideoPlayer').html(function(){

        var EmbedVidStr = QT_GenerateOBJECTText(FULLMediaURL ,  MediaWidth, MediaHeight, '', 'Scale', '1', 'EnableJavaScript', '1', 'postdomevents', 'True', 'id', 'qtPlayer', 'emb#name' , 'qtPlayer' , 'obj#id' , 'qtPlayer', 'emb#id', 'qtPlayer', 'emb#controller', 'true', 'emb#bgcolor', '#000000', 'emb#showlogo', 'false', 'emb#kioskmode', 'true')
        if(URL != 'short_films') var VidButtons = "<div align='left'><a href='"+FULLMediaURL+"' target='_blank'><img src='/media/images/podcast_button.jpg' border='0' /></a><a href='/directors/"+URL+"/forward/"+MEDIAID+"'><img src='/media/images/forward_button.jpg' border='0' /></a></div>";
        else var VidButtons = "<div align='left'><a href='"+FULLMediaURL+"' target='_blank'><img src='/media/images/podcast_button.jpg' border='0' /></a><a href='/short-films/forward/"+MEDIAID+"'><img src='/media/images/forward_button.jpg' border='0' /></a></div>";

        return EmbedVidStr + VidButtons;

    });

    return false;

}
