function showNoPluginWarning(streamName) {
	$('#center').addClass('noplugin');
	$('#instructions').show();

	var isLinux = navigator.userAgent.match(/Linux/);

	if (typeof(streamName) != "undefined") {
		if (isLinux) {
			$('#instructions').append('<div class="linuxHelp">Plugin detection is not available on linux. If you do have the plugin, execute the following command at your command line: <pre>./OctoshapeClient -url:' + streamName + '</pre> from the directory where you installed the plugin.</div>');
		}
	} else {
		if (isLinux) $('#instructions').append('<div class="linuxHelp">Plugin detection is not available on linux. Once the broadcast is about to start, you will see the streamname here which you can add to the octoshape command</div>'); 
	}
}

jQuery(document).ready(function() {
	if (typeof(octoStream) != 'undefined' && octoStream.length > 2 && octoType == "wmv") {
		if (octoOK()) {
			octoSetOndemandBarPath("/js/octobar.swf");
			var octoBar = (new String(octoStream)).match(/ond/) ? 1 : 0;
			// it seems to work better with a little timeout
			setTimeout(function() {
				octoPlayEmbedded(octoStream, 'player', 512,307, octoBar);
			}, 500); 

		} else {
			showNoPluginWarning(octoStream);
		}
	}

	if (typeof(octoChangeChannel) != 'undefined') {

		$('a.switch-stream-on').click(function() {
			octoChangeChannel('JESC.main');
			return false;
		});
		$('a.switch-stream-back').click(function() {
			octoChangeChannel('JESC.backstage');
			return false;
		});
	};

	$('#tabs').each(function() {

		var getid = function(num, el) {
			var h = $(el).attr('href').split('#')[1];
			return '#' + h;
		}

		var getel = function(num, el) {
			return $(getid(num, el));
		}

		var links = $(this).find('a');

		var ids 	= links.map(getid).get().join(',');
		var content = $(ids);

		var selectEl = function(el) {
			links.removeClass('active');
			el.addClass('active');
			content.hide();
			getel(0, el).show();
		}

		links.click(function() {
			selectEl($(this));
			return false;
		});

		selectEl($(links.get(0)));
	});

	$('form.twitter').submit(function() {

		var $f = $(this);
		var $s = $f.find('.status');
		var $b = $f.find('.button');
		var hashTag = $f.attr('id');

		var status = $s.val();
		if (status.length < 5) {
			alert('Please enter a Twitter status message');
			return false;
		}

		status += ' #' + hashTag;

		$s.val(status);

		if (status.length > 140) {
			alert("Sorry, tweets are limited to 140 characters");
			return false;
		}

		$f.ajaxSubmit({
			success: function(data) {
				console.log(data);
			},
			iframe: true,
			dataType: 'xml'
		});

		$b.attr('disabled', 'disabled');

		setTimeout(function() {
			$s.attr('disabled', 'disabled');
		}, 500);

		setTimeout(function() {
			$b.attr('disabled', null);
			$s.attr('disabled', null);
			$s.val('#eurovision');
		}, 10000);

		return false;
	});

	// makes 
	$('#channels li').click(function(target) {
		var link = $(this).find('a').attr('href');
		document.location = link;
		return false;
	});


});
