/* slightly better JavaScript, now that most of the old code has been re-factored... */

var openWindow = function(params) {
	var defaults = {
			url: '#',
			title: 'New Window',
			options: 'height:600',
			focus: false
		},
		options = jQuery.extend({}, defaults, params),
		newWindow = window.open(options.url, options.title, options.options);		
		
	if (options.focus && window.focus) {
		newWindow.focus();
	}

	return newWindow;
}

var openListenLive = function() {
	var params = {
		url: '/listenlive/',
		title: 'WDET',
		options: 'height=225,width=475',
		focus: true
	};
	window.listenLiveWindow = window.openWindow(params);
}

/* stuff to do when DOM is ready */
jQuery(function() {
	var b = new WDET.Billboards(),
		n = new WDET.StickyNav();

	jQuery('ul.main-navigation ul.wide').columnize({
		columns: 3,
		balance: false
	});

	jQuery('ul.main-navigation ul').css('display', 'none').css('visibility', 'visible');

	jQuery('ul.main-navigation > li').hoverIntent({
		interval: 85,
		sensitivity: 2,
		timeout: 80,
		over: function() {
			jQuery(this).children('ul').slideDown(255);
		},
		out: function() {
			jQuery(this).children('ul').slideUp(200);
		}
	});

	jQuery('#footer .poplink').click(function() {
		jQuery(this).bind('mouseleave', function() {
			var $this = $(this);

			$this.removeClass('open-popup');
			$this.children('.popup').slideUp(200);
			
		}).addClass('open-popup').children('.popup').slideDown(200);
	});

	jQuery('.ajax_tabbed_panel ul.ajax_tabbed_panel_selector>li').live('click', function loadEpisodes(url) {
		var url = jQuery(this).find('a').attr('href');

		jQuery(this).siblings().removeClass('active');
		jQuery(this).addClass('active');

		jQuery(this).parents('.ajax_tabbed_panel:first').children('.ajax_tabbed_panel_content').slideUp('fast', function(){
			jQuery(this).load(url, function() {
				jQuery(this).slideDown('fast');
			});
		});

		return false;
	});

	jQuery('#jplayer_stream').jPlayer({
		ready: function() {
			jQuery(this).jPlayer('setMedia', { mp3:'http://141.217.119.35:8000/' }).jPlayer('play');
		},
		ended: function() {
			jQuery(this).jPlayer('play');
		},
		supplied: 'mp3',
		swfPath: 'media/jplayer'
		//errorAlerts:true
	});
});

