/*
window.onscroll = function() {
  document.getElementById('BG').style.top =
     (window.pageYOffset + window.innerHeight - 25) + 'px';
};
*/

$(document).ready(function() {

/*
	$("#shows li").bind('mouseenter',function(){
		var $this = $(this);
		var audio = $this.find("audio")[0];
		audio.play();
	});
*/	
/*
	$("#shows .more").bind('click',function(){
		var $this = $(this);
		$this.hide();
		$("#shows").css('position','absolute');
		$(".archived").fadeIn('fast');
		return false;
	});
*/
	$("a.expander").bind('click',function(){
		var $this = $(this);
		if($this.hasClass('expanded')) {
			$this.removeClass('expanded');
			$this.next("div.expanding").slideUp('fast');
		} else {
			$this.addClass('expanded');
			$this.next("div.expanding").slideDown('fast');
		}
		return false;
	});
	
	$("#view a.more").bind('click',function(){
		var $this = $(this);
		$this.hide();
		$this.siblings("div.more").fadeIn('fast');
		return false;
	});
	
	var videoCount = 0;
	var $videos = $(".video");
	var $boxes = $(".box");
	$.idleTimer(600);
	
//	$(".control:first").addClass('playing');
	
/*
	$(".control a").bind('click',function(){
		$(document).unbind('idle.idleTimer').bind('idle.idleTimer',function(){
			$boxes.dim();
		}).unbind('active.idleTimer').bind('active.idleTimer',function(){
			$boxes.undim();
		});
	});
*/
	
/*
	$(".control a").bind('click',function(){
		$this = $(this);
		$control = $this.closest('.control');
		if($control.hasClass('active')) {
			switch($this.attr('class')) {
				case 'prev':
					videoCount--;
					if(videoCount == 0) {
						$control.removeClass('active');
					}
					$(".control a.next").closest(".control").addClass('active');
					break;
				case 'next':
					videoCount++;
					if(videoCount == $videos.length-1) {
						$control.removeClass('active');
					}
					$(".control a.prev").closest(".control").addClass('active');
					break;
			}
			$videos.hide();
			$($videos[videoCount]).show();
		}
		return false;
	});
*/
	
	$(".videos a").bind('click',function(e){
		e.preventDefault();
		$this = $(this);
		$control = $this.closest('.control');
		$boxes.fadeTo('slow',0);
		$(document).unbind('idle.idleTimer').bind('idle.idleTimer',function(){
			$boxes.dim();
		});
		if($control.hasClass('active')) {
			videoID = $this.data('video');
			$video = $("."+videoID);
			$(".control").removeClass('playing');
			$control.addClass('playing');
			$videos.each(function(){
				var $this = $(this);
				var $cont = $("<div></div>");
				$cont.html($this.html());
				$this.hide();
				$this.html($cont.html());
			});
			$video.show();
			$(document).unbind('active.idleTimer').bind('active.idleTimer',function(){
				$boxes.undim();
			});
		}
		return false;
	});

	$(".image").bind('mouseenter',function(){
		$this = $(this);
		$(".description",$this).fadeIn('fast');
	}).bind('mouseleave',function(){
		$this = $(this);
		$(".description",$this).fadeOut('fast');
	});
	
});

$.fn.dim = function() {
	$this = $(this);
	$this.fadeTo('slow',0);
}

$.fn.undim = function() {
	$this = $(this);
	$this.fadeTo('slow',1);
}
