$(document).ready(function(){
	$('.listen a, .sl_listen a, a.play').live('click', playAudio);
   	$('a.watch, .sl_video a, .sl_watch a, #watch a, a.video').live('click', playVideo);
   	$('#events-calendar caption a').live('click', switchCalendar);
   	$('a[href^="http://cpmassets.com/video"]').live('click', playVideo);
   	$('#nav a[href^="http"]').attr('target', '_blank');
	$('.external').attr('target', '_blank');		
	$('head').append('<link rel="stylesheet" type="text/css" href="http://cpmassets.com/cpm.css" />');
});

// launch audio player
function playAudio(){
	window.open('http://cpmassets.com/audio-player.php?audio='+$(this).attr('href'), 'audioPlayer', 'width=210,height=50,status=0,toolbar=0'); 
	return false;
}

function playVideo(){

	var place = this.href.match(/cpmassets/) ? this.href : 'http://cpmassets.com/video.php?video='+this.href;
	/*
	if($(this).attr('rel').length > 1){
		var place = $(this).attr('href');
	} else {
		var place = 'http://cpmassets.com/video.php?video='+$(this).attr('href');
	}
	*/
	window.open(place, 'videoPlayer', 'width=640,height=320,scrollbars=0,statusbar=0,address=0');
	return false;
}

function switchCalendar(){
	var parts = $(this).attr('href').split('/');
	var month = parts.pop();
	var year  = parts.pop();
	$.get('/ajax/events/', { month:month, year:year }, function(data){
		var cal	= $('#events-calendar'),
			cat = $('#event-cat').val();
		cal.html(data);				
		
		if(cat && cat !== '0') cal.find('li').not('.category_'+cat).hide();
	});
	return false;
}
