$(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);
				}
			};
		},

		ui: function(){
			// MAIN NAV
			if ($('#header ul ul').length > 0) {
				$('#header ul ul').parent().addClass('drop');
				$('#header ul ul li:first-child').addClass('first');
				$('#header ul li:last-child').addClass('last');
				$('#header ul li.drop').hover(function() {
					$(this).addClass('over');
				}, function() {
					$(this).removeClass('over');
				});
			}
			// SLIDESHOW
			if ($('#slides').length > 0) {
				$('#slides').cycle({ 
					fx: 'fade',
					cleartypeNoBg: true,
					timeout: 6000,
					prev: '#slideshow a.prev',
					next: '#slideshow a.next'
				});
			}
			// PHOTO ALBUMS
			if ($('#photo-album').length > 0) {
				$('#photo-album a:nth-child(4n)').addClass('last');
				$('#photo-album a').colorbox();
			}
			// VIDEOS
			if ($('a.video').length > 0) {
				$('a.video').colorbox({inline:true});
			}
			// SIDEBAR NAV
			if ($('#sidebar #sidebar-nav ul ul').length > 0) {
				$('#sidebar #sidebar-nav ul ul a').prepend('&#9642;&nbsp;');
			}
			// CLEARING FLOATS
			$('.cleared').append('<span class="clear"></span>');
		},

		init: function(){
			FRR.forms();
			this.placeholders = FRR.placeholders();
			FRR.ui();
		}
			
	};
	
	FRR.init();

});
