(function($) {

	$.fn.revSlider = function(options) {

		// default configuration properties
		var defaults = {
			//prevId: 		'prevBtn',
			prevText: 		'',
			//nextId: 		'nextBtn',
			nextText: 		'',
			orientation:	'', //  'vertical' is optional;
			speed: 			750
		};

		var options = $.extend(defaults, options);

		return this.each(function() {
			obj = $(this);
			var s = $("li", obj).length;
			var w = obj.width();
			var h = obj.height();
			var ts = s-1;
			var t = 0;

			var autoAnimation = "on"; // set to "off" to disable auto-animation
			var autoDirection = "next"; // default direction to begin auto animating
			var autoTime = 8200; // time between auto-scrolls, in ms
			var storedTimeout = null; // only allow one stored jump timeout at a time, and always reference it here

			var vertical = (options.orientation == 'vertical');
			$("ul", obj).css('width',s*w);
			if(!vertical) $("li", obj).css('float','left');
			
                        /*
                        $(obj).after('<span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText
						 +'</a></span> <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>');
			$("a","#"+options.prevId).hide();
			$("a","#"+options.nextId).hide();
			$("a","#"+options.nextId).click(function(){
				suspendAutoAnimation();
				animate("next");
				if (t>=ts) $(this).fadeOut();
				$("a","#"+options.prevId).fadeIn();
			});
			$("a","#"+options.prevId).click(function(){
				suspendAutoAnimation();
				animate("prev");
				if (t<=0) $(this).fadeOut();
				$("a","#"+options.nextId).fadeIn();
			});
			*/
                       
                        $(".promoBullet").click(function(){
				suspendAutoAnimation();
				animate("to", $(this).attr('value'));
				//if ($(this).attr('value')<=0) $("a","#"+options.prevId).fadeOut();
				//else $("a","#"+options.prevId).fadeIn();

				//if ($(this).attr('value')<ts) $("a","#"+options.nextId).fadeIn();
				//else $("a","#"+options.nextId).fadeOut();
			});
			function setActiveBullet(t) {
				$('.promoBullet').removeClass('selected');
				$('.promoBullet').filter(function() { return ($(this).attr('value') == t); }).addClass('selected');
			}

			function autoAnimate () {
				if (autoAnimation != "on") return true;

				if (t >= ts) { autoDirection = "prev"; }
				else if (t <= 0) { autoDirection = "next"; }

				animate(autoDirection);

				//if (t<=0) $("a","#"+options.prevId).fadeOut();
				//else $("a","#"+options.prevId).fadeIn();

				//if (t<ts) $("a","#"+options.nextId).fadeIn();
				//else $("a","#"+options.nextId).fadeOut();

				clearTimeout(storedTimeout);
				storedTimeout = setTimeout(autoAnimate, autoTime);
			}

			function resumeAutoAnimation () {
				autoAnimation = "on";
				autoAnimate();
			}

			function suspendAutoAnimation () {
				autoAnimation = "off";

				// wait a bit then resume autoAnimation
				clearTimeout(storedTimeout);
				storedTimeout = setTimeout(resumeAutoAnimation, 12000);
			}

			storedTimeout = setTimeout(autoAnimate, autoTime-500);

			function animate(dir, direct) {
				if (dir != "to") {
					if (dir == "next") {
						t = (t>=ts) ? ts : t+1;
					} else {
						t = (t<=0) ? 0 : t-1;
					};
				}
				else {
					directInt = parseInt(direct);
					if (! directInt || directInt <= 0) t = 0;
					else if (directInt >= ts) t = ts;
					else t = directInt;
				}
				setActiveBullet(t);
				if (!vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p },
						options.speed
					);
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p },
						options.speed
					);
				}
			};
			if(s>1) $("a","#"+options.nextId).fadeIn();
		});
	};
})(jQuery);

function socialise(social_url) {
    var url = window.location.href;
    var title = document.title;
        social_url = social_url.replace(/{u}/, url).replace(/{t}/, title);
        window.open(social_url);
    return false;
}

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) {
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};