$(function(){

	if(typeof console === "undefined") {
		console = { log: function() { } };
	}
	
	var $ = jQuery;
	
	var FRR	=	{

		forms: function(){
			// CLEAR DEFAULT FIELD VALUES
			if ($('.default').length > 0) {
				$('.default').each(function() {
					var default_value = this.value;
					$(this).focus(function() {
						if(this.value == default_value) {
						this.value = '';
						}
					});
					$(this).blur(function() {
						if(this.value == '') {
						this.value = default_value;
						}
					});
				});
			}
			if ($('#search-wrapper .toggle').length > 0) {
				$('#search-wrapper .toggle').click(function() {
					$('#search-wrapper').toggleClass('open');
					return false;
				});
			}
			if($('form').length > 0) {
				$('input.submit').click(
					function(event){
						FRR.placeholders.clearPlaceholders();
					}
				);
			}
		},

		placeholders: function() {
			var showPlaceholder = function() {
				if ('placeholder' in document.createElement('input')) return;
					var input = $(this);
					var placeholderText = input.attr("placeholder");
				if ( input.val() === "" || input.val() === placeholderText ) {
					input.val(placeholderText);
				}
			};
			var clearPlaceholder = function() {
				var input = $(this);
				if (input.val() === input.attr("placeholder")) {
					input.val("");
				}
			};
			$("input[type=text][placeholder]")
				.each(showPlaceholder)
				.blur(showPlaceholder)
				.focus(clearPlaceholder);
			return {
				showPlaceholders: function() {
					$("input[type=text][placeholder]").each(showPlaceholder);
				},
				clearPlaceholders: function() {
					$("input[type=text][placeholder]").each(clearPlaceholder);
				}
			};
		},

		init: function(){
			FRR.forms();
			this.placeholders = FRR.placeholders();
			FRR.ui();
		}
			
	};
	
	FRR.init();

});
