
/**
 * Load the personality content and 
 * process scheduled content.

$(function(){
	$('#personality').load(SITE_URL+'/content/STATIC/ONAIR-NOW.html',{},function(){
		$('.schedule').schedule();
	});
}); */
$(function(){ $('.schedule').schedule(); });

/**
 * Format all dates identified by the date class.
 *  - Expects dates in the format: YYYY-MM-DD
 *
 * BEFORE:
 * <span class="date">2007-08-16</span>
 *
 * AFTER:
 * <span class="date">Thursday, August 16th, 2007</span> 
 */
$(function(){
	if( FLAG_CONVERT_DATES ) {
		$(".dates li").each(function(){
			var date = $(this).text();
			if(date != null && date != ""){
				var d = new Date(date.substring(0,4),date.substring(5,7)-1,date.substring(8,10));
				$(this).text(d.formatDate("l, F jS, Y"));
			}
		});
	}
});


/**
 * Add NowPlaying to the page
 */
var np_targetid = 'np-song-info';
$(function(){
	if( FLAG_NOWPLAYING ) {
		$.getScript("http://nowplaying.rogersradiointernet.com/public/widgets/nowplaying.json.js");
	}
	npframe = document.createElement("iframe");
	npframe.src = NOWPLAYING_IFRAME_URL;
	$npframe = $(npframe);
	// frameBorder <- camel casing mandatory for Internet Explorer
	$npframe.attr( {scrolling: "no", marginWidth: "0", marginHeight:"0", frameBorder:"0", border:"0", allowtransparency: "true", align: "center"} );
	$npframe.width("100%");
	$npframe.height(25);
	$npframe.css({width:"100%",height:"25px"});
	$("#bds-np").append(npframe);
});

/**
 * Google Analytics
 * Depends on jquery.ga.js and urchin.js
 */
$(function(){
	if( FLAG_GOOGLE_ANALYTICS ) {
		options = {
			domains: ANALYTICS_TRACKED_DOMAINS,
			restricted: ['ad.doubleclick.net'],
			fileTypes : ['zip','wmv','gz','mov','txt','ppt','doc','xls','mpg','mpeg','mp3','pdf','avi'],
			trackAnchors : true,
			trackFiles : true,
			trackForms : true,
			debug: FLAG_DEBUG
		};
		$(document).ga(_uacct,options);
	}
});

/**
 * Look for media - convert to tabs and appropriate display
 */
$(function(){
	var tabinst = 0;
	$('ul.media').each(function(){
		
		$links = $(this).find('li a');
		if($links.length == 0) return;
		
		var count = 0;
		var mediatabs = $('<ul id="#mediatabs-'+tabinst+'"></ul>');
		tabinst++;
		
		if($links.length > 1) {
			$links.each(function(){
				count++;
				var tabid = 'tab-'+tabinst+'-'+count;
				$(this).parent().attr("id",tabid);
				$(this).media();
				mediatabs.append('<li><a href="#'+tabid+'" title="'+this.text+'">&nbsp;'+count+'&nbsp;</a></li>');
			});
			$(this).before(mediatabs);
			mediatabs.tabs({ fxFade: true });
		} else {
			$links.media();
		}
	});
});


/**
* Greybox links (aka Lightbox)
*
*/
var GB_ANIMATION = true;
$(function(){
	$("a.greybox").click(function(){
		var t = this.title || $(this).text() || this.href;
		var meta = $.metadata.get(this);
    var h = meta.h || 470;
    var w = meta.w || 600;
		GB_show(t,this.href,h,w);
		return false;
	});
});

/*
$(function(){
	$(".aintro .title").hoverIntent({
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
		 interval: 50, // number = milliseconds for onMouseOver polling interval
		 over: showSub, // function = onMouseOver callback (required)
		 timeout: 150, // number = milliseconds delay before onMouseOut
		 out: hideSub // function = onMouseOut callback (required)
	});
});

function showSub() {
	$(this).find(".subnav").fadeIn("fast");
}

function hideSub() {
	$(this).find(".subnav").fadeOut("fast");
}*/

function openListenLive(file) {
	var location = "";
	if(file != null && file.length > 0) {
		location = MEDIAPLAYER_URL + "?file=" + file;
	} else {
		location = (MEDIAPLAYER_GATEWAY == true) ? MEDIAPLAYER_GATEWAY_URL : MEDIAPLAYER_URL;
	}
	var win = window.open(location,'ListenLiveWindow','width='+MEDIAPLAYER_WIDTH+',height='+MEDIAPLAYER_HEIGHT+',status=0,scrollbars=0,resizable=0');
	win.focus();
	return false;
}

/**
 * Schedule Display
 *
 */
var schedule;
var currentDate = new Date();
function showSchedule(view) {
	var target;
	if(schedule) {
		schedule.options.view = view;
		schedule.display("#"+view);
	} else {
		$.get( "/shared/schedule.xml", function(xml, statusText){ 
			if(statusText == "success")	{
				schedule = new Schedule(xml, { now: currentDate });
				showSchedule(view);
			} else {
				// XML not successfully retrieved
			}
		});
	}
}




