Masthead = {};

Masthead.init = function() {
  $(document).bind("onNowplayingChanged", Masthead.onNowplayingChanged );
  $(document).bind("onBeforeLightbox", Masthead.onBeforeLightbox);
  Masthead.createStationSelectLightbox();
  Masthead.createStationSMSLightbox();
  $('.home\-link').each(function(i, item){
  	$(item).click(function(evt){
  		document.location = '/';
  	});
  });
  $('div#bd div.programschedule_onairnow div.yui-content').show();
  $('div.module_programschedule div.paginator_wrapper').show();
}

Masthead.onNowplayingChanged = function(event, data) {
	$('#onair_track').html(data.song);
	$('#onair_artist').html(data.artist);
	$('#onair_show').html(data.showName);
	$('#masthead_host').html('<a href="'+data.showLink+'"><img src="'+data.showImage+'"/></a>');
}

Masthead.createStationSelectLightbox = function() {
  $("body").addClass("js");

  $('#header .other-stations').click(function() {
    $(document).trigger("onBeforeLightbox"); 
    $('#rs-overlay').addClass('active');
    $('#rs-popup').addClass('active').show();
    return false;
  });
  
  $('#rs-overlay').click(function() {
     $('#rs-overlay').removeClass('active');
     $('#rs-popup').removeClass('active').hide();
  });  
}

Masthead.createStationSMSLightbox = function() {

  $("body").addClass("js");

  // this fixes the problem with event not firing correctly inside of accordians
	/*$('a.text\-link').attr('onclick', "Masthead.openStationSMSLightbox();return false;");

	$('a.text\-link').click(function() {
    $('#sms-overlay').addClass('active');
    $('#sms-popup').addClass('active').show();
    return false;
  });
*/

  $('#sms-overlay').click(function() {
     Masthead.closeStationSMSLightbox();
  });
  
  $('a.close_lightbox').click(function() {
  	 Masthead.closeStationSMSLightbox();
     return false;
  });
}

Masthead.openStationSMSLightbox = function() {
	$(document).trigger("onBeforeSMSLightbox"); 
  $('#sms-overlay').addClass('active');
  $('#sms-popup').addClass('active').show();
}

Masthead.closeStationSMSLightbox = function() {
	$(document).trigger("onCloseSMSLightbox");
	$('#sms-overlay').removeClass('active');
	$('#sms-popup').removeClass('active').hide();
}

/**
 * hide all (possible) showing lightboxes
 */
Masthead.onBeforeLightbox = function() {
	$('#sms-overlay').removeClass('active');
	$('#sms-popup').removeClass('active').hide();
	$('#rs-overlay').removeClass('active');
	$('#rs-popup').removeClass('active').hide();
}
