$.ajaxSetup({
  beforeSend: function(xhr) {
    xhr.setRequestHeader("Accept", "text/javascript");
  }
});

$(document).ready(function () {
  /* share this links should open in a new window */
  $('.social-bookmarks').click(function (event) {
    var element = event.target;
    if (element.tagName == 'IMG') {
      element = element.parentNode;
    }
    
    if (element.href && element.href == 'javascript:void(0)') {
      return true;
    } else {
      window.open(element.href, "Recommend", "height=300,width=600");
      return false;
    }

  });
  
  $('a[rel=external]').click(function (event) {
    window.open(event.target.href);
    return false;
  });
  
  $('#subscriber-form').submit(function (event) {
    $.post(event.target.action + '.js', $(this).serialize(), null, 'script');
    // $('#subscriber-form').hide();
    return false;
  });
  
  $('#subscriber_email').click(function (event) {
    if (event.target.value == 'Enter Email') {
      event.target.value = '';
    }
  });
  
  $('.social-bookmarks .twitter').click(function (event) {
    return TweetAndTrack.open(this, $(this).attr('href'));
  });

  $('#redeemer_gender').clearSearch();  

  if (typeof $.fn.jPicker == 'function'){
    $('#promotion_custom_bg_colour').jPicker();
  }
});

$.fn.clearSearch = function() {
	return this.each(function(){
		var initialValue = $(this).attr('value');
		
		$(this).focus(function(){
			if ($(this).attr('value') == initialValue) $(this).attr('value','');
		}).blur(function(){
			if ($(this).attr('value') == "") $(this).attr('value',initialValue);
		});
	});
}
