$(document).ready(function() {
	/*
	 * HEADER
	 */
	$('#who, #why, #where, #how').hide();
	var id;
	$('.who, .why, .where, .how').click(function() {
			resetShell();
				
			id = "#"+ $(this).attr('class');
			bgClass = $(this).attr('class') +"_bg";
			$(this).addClass(bgClass);	

			$('#shell_bg').animate({display : 'block', height : 500}, 200, function() {
				$('#close').css({display : 'block'});
				$(id).css({display : 'block'}).fadeTo(700,1);
			});
	})
	
	function resetShell() {
		//reset header link bg color
		$('#header > a').each(function() {
			if (this.id != "logo") {
				bgClass = $(this).attr('class').split(" ");
				for (i=0; i < bgClass.length; i++) {
					if ($(this).hasClass(bgClass[i])+"_bg") {
						$(this).removeClass(bgClass[i] +"_bg");
					}
				}
			}
		});
		
		//reset shell containers
		$('#shell_bg').animate({height : 0, display : 'none'}, 300);
		$('#close').css({display : 'none'});
		$('.shell > div').each(function() {
			if (this.id != "shell_bg" && this.id != "close") {
				$(this).fadeTo(1, 0).css({display : 'none'});
			}
		});
	}
	
	$('#close').click(function() {
		resetShell();
	}).mouseover(function() {
		$(this).css('opacity', '.5');
	}).mouseout(function() {
		$(this).css('opacity', '1');
	});
	
	/* 
	 * TABS WIDGET
	 */
	$('.tw-nav-list > li > a > span').each(function() {
		html = $(this).html();
		if (html == "Popular") {
			$(this).parent('a').addClass('popular-link');
			$(this).html('&nbsp;').css({width : '70px', display : 'block'});
		} else if  (html == "Recent Comments") {			
			$(this).parent('a').addClass('recent-comments-link');
			$(this).html('&nbsp;').css({width : '129px', display : 'block'});
		}
	});
	$('#popular-posts > ul > li:last-child').children('a').css({'border-bottom': 'none', 'padding-bottom' : '0'});
	$('#recentcomments > li:last-child').css({'border-bottom': 'none', 'padding-bottom' : 'none !important'});
	
	/*
	 * WIDGET OPTIN
	 */
	$('input.wpsb_form_btn').val(' ');
	$('.wpsb_form_txt').focus(function() {
		resetOptin();
		$(this).css('color', '#333');
		if ($(this).val() == "E-mail" ||
			$(this).val() == "Name" ||
			$(this).val() == "Zip/Postal"
		) {
			$(this).val('');
		}		
			
	})
	.blur(function() {
		resetOptin();
	});
	function resetOptin() {
		$('.wpsb_form_txt').each(function() {
			if ($(this).val() == "") {
				if (this.id == "wpsb_email") {
					$(this).val('E-mail');
					$(this).css('color', '#ccc');
				} 
				else if (this.id == "wpsb_fld_2") {
					$(this).val('Name');
					$(this).css('color', '#ccc');
				} 
				else if (this.id == "wpsb_fld_3") {
					$(this).val('Zip/Postal');
					$(this).css('color', '#ccc');
				}
			}
		});
	}
	
	/*
	 * FACEBOOK WIDGET
	 */ 
	$('li.widget_facebook div a').each(function() {
		$(this).mouseover(function() {
			$(this).css('opacity', '.5');
		}).mouseout(function() {
			$(this).css('opacity', '1');
		});
	});

});