$(function (){  
	// Page load defaults
		$('.subMenu span').hide();
		$('.sideRSSlist').hide();
		$('.SubscribeSubmit').hide();
	// Search width animation
    $('.rightEnd').css('width','81px');
    $('input#searchInput').focus(function() {
		$('.rightEnd').animate({ width: 141 }, 500);
  	}).blur(function() {
		$('.rightEnd').animate({ width: 81 }, 500);
	});
	
	// Forums search
	$('.search .rightEnd').animate({ width: 141 }, 500);
	
	// Sub Menu Drop Down Fast
	var subdrop = function() {
		$(this).children('.subMenu').show();
		$('.subMenu .firstBubble').show();
		$('.subMenu .secondBubble').show();
		$('.subMenu .topBubbles').show();
		$('.subMenu li').show();
	}
	var subup = function() {
		$(this).children('.subMenu').fadeOut('fast');
	}
	
    $('.menu_pregnancy').hover(subdrop, subup);
    $('.menu_parenting').hover(subdrop, subup);
    $('.menu_community').hover(subdrop, subup);

	var curlin = function() {
		$(this).children('.hpBoxCorner').fadeIn('fast');
	}
	var curlout = function() {
		$(this).children('.hpBoxCorner').fadeOut('fast');
	}
	$('.#leftcolumn .singlePost').hover(curlin, curlout);

    // InnerFades
    $('#titleRotate').after('<div id="titleControl">').cycle({ 
	    fx:     'scrollLeft', 
	    speed:  'fast', 
	    timeout: 5000, 
	    cleartypeNoBg: true,
	    pager: '#titleControl'
	});
	$('#titleControl').append('<a href="" class="titleControlText">Read This &raquo;</a>');
		
	//Footer NavBar
	$('#footerNav').css({backgroundPosition: '0px 0px'}); // Set for background animation plugin bug
	$('#footerStage .stages').hide();
	$('#footerStage .a1').show();
	$('#footerNav li').each(function(num){
		var hyt = $(this).attr('id');
		if (hyt == 'a1') { var hytt = 0; }
		if (hyt == 'a2') { var hytt = 64; }
		if (hyt == 'a3') { var hytt = 128; }
		if (hyt == 'a4') { var hytt = 192; }
		$(this).mouseover(function() {
			$('#footerStage .stages').hide();
			$('#footerNav').animate({backgroundPosition: '(0px '+hytt+'px)'})
		    $('#footerStage .'+hyt).fadeIn(500);
		    $(this).siblings().removeClass('current');
		    $(this).addClass('current');
		})
	})
	
	// Menu highlighting
	/*
	.menu_community
	.current
    */

    // RSS list
    $('.RSSSubscribe').hover(function() {
		$('.sideRSSlist').slideDown('fast');
	}, function() {
		$('.sideRSSlist').slideUp('fast');
	});

    $('.RSSSubscribe').click(function() {
		window.open("http://pregg.net/get-updates/");
	});
	
	// Newsletter
	// Clear the input on focus
	$('input#sideSubInput').focus(function() { //.sideSubscribe
		$(this).val('');
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this)[0].defaultValue);
		}
	});
	// slide down more info
	/*$('.sideSubscribe').hover(function() { //.sideSubscribe
		$('.SubscribeSubmit').slideDown('fast');
	}, function() {
			$('.SubscribeSubmit').slideUp('fast');
		}
	);*/
	// submit
	$("#submitNewsletter").click(function() {  
		var newsltEmail = $("input#sideSubInput").val();  
			    if (newsltEmail == "") {  
			  		$("input#sideSubInput").focus();  
			  		return false;  
				}
				if (newsltEmail == "Enter Your E-mail...") {  
			  		$("input#sideSubInput").focus();  
			  		return false;  
				}

//		var nlcheck1 = $("input:checkbox:checked");
		var valArray = $('input:checkbox:checked').val();
		
		//var nlcheck2 = $("input#nlcheck2").val();  
		//var nlcheck3 = $("input#nlcheck3").val();  
		
			// ajax submission
				 var dataString = 'newsltEmail='+ newsltEmail + '&valArray='+ valArray;  
				 //alert (dataString);return false;  
				 $.ajax({  
				   type: "POST",  
				   url: "http://pregg.net/wp-content/themes/pregg01/subscribe/process-form.php",  
				   data: dataString,  
				   success: function() {  
				     $('.SubscribeSubmit').hide();
				     $('.SubscribeThanks').fadeIn('fast');
				   }
				 });  
				 return false;
	});  
	
	// Detect fonts....
 	var detective = new Detector();
 	var helvetica = detective.test('Helvetica');
    if (!helvetica) {
		$('.hpBox h2').css("lineHeight","22px");
	}
	
/* Remove all this since we're using css for shadows....
	// Inserting spaces into tag cloud, to fix float:left applied for shadowing
	$(".tagOrder a:eq(3)").prepend('<a href="">&nbsp;&nbsp;&nbsp;</a>'); // Note that the shadows also -count- as elements
	//$(".tagReverse a:eq(6)").apend('<a href="">&nbsp;&nbsp;&nbsp;</a>'); 
	//$(".tagReverse a:last").apend('<a href="">&nbsp;&nbsp;&nbsp;</a>'); 
	$(".tagOrder2 a:eq(3)").prepend('<a href="">&nbsp;&nbsp;&nbsp;</a>'); 

	// Tag Cloud Drop Shadow	
	//$("#tagCloud a").dropShadow({left: -7, top: 1, opacity: 1.0, blur: 0, color: "#333"});	
*/
	// Open external links in new window - fix for target=”_blank”
	$("a[@rel~='external']").click(function(){
	window.open($(this).attr("href"));
	return false;
	});
	
});

