Tip = function(title, body, position) {
  this.title    = title;
  this.body     = body;
  this.position = position;
}

popup_rules = function() {
	var win_rules = window.open('/sweepstakes/rules', 'win_rules', 'width=540,height=550,resizable=1,toolbar=0,scrollbars=1,status=0,location=0,directories=0');
}

popup_privacy = function() {
	var win_privacy = window.open('http://www.unileverus.com/privacy/policy.html?site=www.MakingLifeBetter.com', 'win_privacy', 'width=620,height=550,resizable=1,toolbar=0,scrollbars=1,status=0,location=0,directories=0');
}

popup_terms = function() {
	var win_terms = window.open('http://www.unileverus.com/terms/termsofuse.html?site=www.MakingLifeBetter.com', 'win_terms', 'width=540,height=550,resizable=1,toolbar=0,scrollbars=1,status=0,location=0,directories=0');
}

popup_email = function(url) {
  var win = window.open(url,'email','height=480,width=535');
  if (window.focus) { win.focus(); }
  return false;
}

pop_print = function(url) {
  var win = window.open(url,'print','height=700,width=1100,scrollbars=yes');
  if (window.focus) { win.focus(); }
  return false;
}


function toggleFavorite(checkbox, controller, params) {
  var url = '/' + controller + '/' + (checkbox.checked ? 'save' : 'unsave');
  var label = $('#toggleFavoriteStatus');
  var span = label.children('span');
  span.css('display', 'inline');
  
  $.post(url, params, function() {
    span.fadeOut({duration: 1000});
  });
}

function toggleRecipe(checkbox, id, version) {
  return toggleFavorite(checkbox, 'recipes', {id: id, version: version});
}

function toggleArticle(checkbox, id) {
  return toggleFavorite(checkbox, 'articles', {id: id});
}

function toggleTip(checkbox, id) {
  return toggleFavorite(checkbox, 'tips', {id: id});
}

function redirect(url) {
  window.location = url;
}

$(function() {
  try {
    $('input[title!=""],textarea[title!=""]').hint();  
  } catch(e) {
  }
});

User = function() {}
User.login = function() {
  User.loggedIn = true;
  $('.for-guests').hide();
  $('.for-users').show();
}

User.logout = function() {
  User.loggedIn = false;
  $('.for-guests').show();
  $('.for-users').hide();
}


User.loggedIn = false;
User.isLoggedIn = function() { return User.loggedIn; }

ExclusiveCheckboxes = function() {}
ExclusiveCheckboxes.build = function(boxes) {
  boxes.bind('click', function() {
    boxes.not(this).attr('checked', false);
  });
}

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

// smooth scroll
$(function() {
  $('a[faq*=true]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  && location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset}, 1000);
	   return false;
	  }
	}
  });
});