jQuery.fn.center = function () {
        this.css("position","absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
        return this;
    }
    
    $(document).ready(function() {
        $('.clickableVideo').click(function(e){
			$('#background').css({"opacity" : "0.7"})
				.fadeIn("slow");
			var vid=$(this).attr("id");

								var videos = $.getElementsByClass('video');     // Get all the videos on the page.
								var isplaying=null;
								for(i=0; i<videos.length; i++) {              // Loop through all the videos
									if (videos[i].style.display=='block') {     // This video is playing 
										isplaying=videos[i].id;                   // remember its name
										var tmp=videos[i].innerHTML;              // Get the division contents
										videos[i].innerHTML='';                   // destroy the contents
										videos[i].style.display='none';           // Terminate the video.
										videos[i].innerHTML=tmp;                  // rebuild the contents.
									}
								}
			if (typeof(vid)=="string") { vid=document.getElementById("vid"+vid); }
			$('#large').html(vid.innerHTML).center().show("fast");
            return false;
        });

        $(document).keypress(function(e){
            if(e.keyCode==27){
                $("#large").hide('slow');
                $("#background").fadeOut("slow");
            }
        });
 
        $("#background").click(function(){
			
            $("#large").fadeOut('slow');
			
           $("#background").fadeOut("slow");
        });
	$.extend({
	
		getElementsByClass: function (searchClass) {
			// This function returns an array of all HTML objects with the
			// specified className.  Tag is optional
			var returnArray = [];
			var els = document.getElementsByTagName('*');
			var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
			for (var i = 0; i < els.length; i++) {
				if ( pattern.test(els[i].className) ) { returnArray.push(els[i]); }
			}
			return returnArray;
		}
	}); 		
});
