$(document).ready(function() {

  // Open links in new window when rel="external" is applyed to a tag
  $('a[rel="external"]').click(function(){
  	this.target = "_blank";
  });
  
  // clear input on focus, and returns on blur if nil
  $("#newsletter form input[type='text'], form#enquiry input[type='text'], #enews form input[type='text']").focus(function() {
  	if( this.value == this.defaultValue ) {
  		this.value = "";
  	}
  }).blur(function() {
  	if( !this.value.length ) {
  		this.value = this.defaultValue;
  	}
  });
  $("#newsletter form, form#enquiry, #enews form").validate();

  $('span.mailto').each(function(){
  	eLink = $(this).text().replace(' at ','@').replace(' dot ','.');
  	eSubject = encodeURI($(this).attr('title'));
  	$(this).before('<a href="mailto:'+eLink+'?subject='+eSubject+'">'+eLink+'</a>');
  	$(this).remove();
  });

	$('#banners').cycle();
	$('.colorbox').colorbox();
	$('.colorbox-frame').colorbox({width: "610px", height: "390px", iframe:true}); 
	$('.colorbox-brewframe').colorbox({width: "610px", height: "390px", iframe:true}); 

	$(".month ul.event:odd").addClass("odd");
  
  //EVENTS CALENDAR SHOW/HIDE
  $("div.event_nav ul.event a").click(function() {
    var id = $(this).parents("ul").attr("id").split("event")
    url = "/events/info/" + id[1]
    grabEvent(url)

    return false;
  });

  $("div.lineup_nav ul.event a").click(function() {
    var id = $(this).parents("ul").attr("id").split("lineup")
    url = "/daily_lineups/info/" + id[1]
    grabEvent(url)

    return false;
  });


  function grabEvent(event_url) {
    $.ajax({
     type: "GET",
     url: event_url,
     success: function(returnVal){
       $("div.selected-event").html(returnVal)
       $('.colorbox').colorbox()
     }
    });
  }
	
	$("a[rel='modal_pop']").colorbox({title: function(){
    var url = $(this).attr('href');
    return '';
}});
});