/* Barringer Crater Co. homepage-only effects */
/* Requires jQuery 1.4+ */

$(function() { // on DOM ready
	// Set up feature credit
	var credit = $('#feature_credit');
//	credit.find('#feature_credit_credit').html(panorama.credit);
//	credit.find('#feature_credit_link').attr('href',panorama.link);
	var credit_top = credit.find('#feature_credit_top'),
		credit_more = credit.find('#feature_credit_more'),
		credit_right = credit_top.width()-credit.width(),
		credit_bottom = credit_top.height()-credit.height(),
		credit_timer,
		credit_lock=true, // the credit won't auto-hide
		hideCredit = function() {
			credit_more.fadeTo(600,1);
			credit.animate({right:credit_right,bottom:credit_bottom});
			credit_lock = true;
		};
	hideCredit();
	credit_more.click(function(e) {
			e.preventDefault();
			credit_more.fadeTo(600,0);
			credit.animate({right:0,bottom:0},600,function() {
				setTimeout(function() { credit_lock = false; },1000); // unlock the credit to hiding onmouseoff in 3 seconds
			});
		});
	credit.hover(function() {
			clearTimeout(credit_timer);
		},function() {
			if(!credit_lock) {
				credit_timer = setTimeout(hideCredit,1000);
			}
		});
	$('input[placeholder]').placeholder();
});

$.fn.extend({ // add plugins
	placeholder:function(options) { // bootstrap HTML5 placeholder attributes for browsers that don’t support it
		options = options || {};
		var s = {
			style:options.style || 'lw_placeholder', // the class to add when the element is operating as a placeholder
			clear:options.clear || false // the elements which, when clicked, should wipe the placeholder
		};
		return this.each(function() { // with each matched element
			var self = $(this);
			if (this.placeholder && 'placeholder' in document.createElement(this.tagName)) return; // if the browser supports placeholders for this element, abort
			if(self.data('placeholder')) { // if a placeholder has already been set on this element
				return; // abort to avoid double-binding
			}
			self.data('placeholder',true); // flag this element as having a placeholder, so we'll never double-bind
			var placeholder = self.attr('placeholder'),
				clear = function() { // to clear the placeholder
					if(self.val()==placeholder) { // if the text is the placeholder
						self.removeClass(s.style).val(''); // blank the text and remove the placeholder style
					}
				};
			self.focus(clear)
				.blur(function() {
					var val = self.val();
					if(!val||val==placeholder) { // if thereâ€™s no text, or the text is the placeholder
						self.addClass(s.style).val(placeholder); // set the text to the placeholder and add the style
					}
				}).blur(); // and do it now
			self.parents('form').submit(clear);
			$(s.clear).click(clear);
		});
	}
});
