$(function () {
	$('[target][trigger]').expander();
	$('[submit]').click(function (e) {
		e.preventDefault();
		var w = $(this).attr('submit');
		$(w).submit();
	});
});




$(document).ready(function() {
	Shadowbox.init();
  // set up all anchor elements with a "movie" class to work with Shadowbox
  Shadowbox.setup("a.zoom", {
  });

	$('#newsletter input').one('focus',function () { $(this).val(''); });
});

$('.nsltrsbmt').live('click', function (e) {
	e.preventDefault();
	var n = $('#newsletter input').val();
	$.post(location.href,{ newsletter_signup: n, mode: 'json' },function (d) {
		if (d.ok)
			$('#newsletter').empty().text(d.newsletter_response);
		else
			alert(d.newsletter_response);
	});
});

(function( $ ){

  $.fn.expander = function() {
  	this.each(function () {
  		var o = $(this);
  		var toggle = (o.attr('toggle')) ? o.attr('toggle').split(' ') : [];
  		var target = o.find(o.attr('target'));
  		var trigger = o.find(o.attr('trigger'));
  		trigger.disableSelection();
  		if (target.size() == 0 || trigger.size() == 0)
  			return;
  		if (trigger.filter(':not(:visible)').size() > 0)
  			trigger.click(function () { trigger.toggle(); });
  		trigger.css({cursor:'pointer'}).click(function (e) {
  			e.preventDefault();
  			if (target.is(":visible"))
  			{
  				for (i in toggle)
  					o.removeClass(toggle[i]);
  				target.animate({opacity:0},200,function () { target.slideUp(200); });
  			}
  			else
  			{
  				for (i in toggle)
  					o.addClass(toggle[i]);
  				target.css({opacity:0}).slideDown(200,function () {target.animate({opacity:1})});
  			}
  		});
  	});
  };
})( jQuery );

(function($){
$.fn.disableSelection = function() {
    return this.each(function() {           
        $(this).attr('unselectable', 'on')
               .css({
                   '-moz-user-select':'none',
                   '-webkit-user-select':'none',
                   'user-select':'none'
               })
               .each(function() {
                   this.onselectstart = function() { return false; };
               });
    });
};

})(jQuery);


// jQuery helpers by kfrankiewicz

$.fn.setTimeout = function (fn,tm) {
  var t = $(this)[0];
  jQuery.data(t,'timeout', setTimeout(fn,tm) );
  return this;
}

$.fn.clearTimeout = function () {
  var t = $(this)[0];
  clearTimeout(jQuery.data(t,'timeout'));
  return this;
}


$.fn.store = function (n,o) {
  jQuery.data($(this)[0],n,o);
  return $(this);
}

$.fn.restore = function (n) {
  return jQuery.data($(this)[0],n);
}


