function channelChange(activeId) {
	$('.videolist').hide();
	$('.videolink').removeClass("active");
	$('#' + activeId).addClass("active");
	activeListId = "videolist" + activeId.substring(9);
	$('#' + activeListId).show();
	
	turnDial(activeId); // Set dial to active channel
}

function turnDial(activeId, fadeSpeed) {
	if(fadeSpeed) { $('#knob').hide(); }
    $('#knob').removeClass();
    $('#knob').addClass(activeId);
	if(fadeSpeed) { $('#knob').fadeIn(fadeSpeed); }
}


$(document).ready(function(){

	channelChange('videolink1');
	
	if($("body").hasClass("thecoop")) { channelChange('videolink4'); }

	$(".videolink").click(function(e){
			this.blur();
			channelChange(this.id);
			e.preventDefault();
	});

	
	
	$("#dial a").mouseover(function(e) {  // Move dial on mouseover
			turnDial(this.id);
	});

	$("#dial").bind("mouseleave",function(e) {  // Reset dial to active channel
			turnDial($("#dial .active").attr("id"),"slow");
	});
	
	
	
	/* Attached Documents */
	$("#attachments td a[@href$='docx']").addClass("word-document"); // note @ has deprechiated
	$("#attachments td a[@href$='doc']").addClass("word-document");
	$("#attachments td a[@href$='pdf']").addClass("pdf-document");
	$("#attachments td a[@href$='jpg']").addClass("image-document");
	$("#attachments td a[@href$='gif']").addClass("image-document");
	$("#attachments td a[@href$='png']").addClass("image-document");
	
	
	
	/* Swap Playing Video Tabs */
	$('#share-box, #link-box').hide();
	$('#information-tab').addClass('active');
	
	$('#videolinks a').click( function () {
		$('#information-box, #share-box, #link-box').hide();
		$('#videolinks a').removeClass('active');
		$(this).addClass('active');
 		activeTab = $(this).attr('id');
		activeBox = activeTab.substring(0, activeTab.length-3) + 'box';
		$('#'+activeBox).show();
    	$(this).blur();
    	return false;
    });

	
	/* Swap Link Options */
	$('#link-textarea2, #link-textarea3').hide();
	$("#link-radio1").attr("checked", "checked"); 
	
	$('#link-box label').click( function() {
		$('#link-box textarea').hide();
		activeRadio = $('#link-box input:checked').attr('id');
		activeTextarea = 'link-textarea' + activeRadio.charAt(activeRadio.length-1);
		$('#'+activeTextarea).show();
	});
	
	/* See example */
	$('#link-box #seeexample').click( function() {
		var examplePopup = '<div id="examplePopup">' + $('#link-textarea1').val() + '<a href="#" class="close">Close</a></div>';
		$('#link-box').prepend(examplePopup);	
		$('#examplePopup, #examplePopup a').click( function() {
			$('#examplePopup').remove();
			$(this).blur();
    		return false;
		});
		$(this).blur();
    	return false;
	});
	
	$('#link-box textarea').focus( function() {
		$(this).select();
	});
								


	/* Custom select all Content button */
	$('th.select-all').click( function() {
		$('input.form-checkbox').attr("checked", "checked");
									   });


});