$(document).ready(function() {
	$(".defaultText").focus(function(srcc)
  {
      if ($(this).val() == $(this)[0].title)
      {
          $(this).removeClass("defaultTextActive");
          $(this).val("");
      }
  });
  $(".defaultText").blur(function()
  {
      if ($(this).val() == "")
      {
          $(this).addClass("defaultTextActive");
          $(this).val($(this)[0].title);
      }
  });
  $(".defaultText").blur();

	if($("ul.children li").hasClass("current-cat") == true) {
		$("li.current-cat").parent().show();
		$("li.current-cat").addClass("current-sub-cat").removeClass('current-cat');
	}
	
	//$("ul.nav li.toc").click(function() {
	//	$("#toc").slideToggle();
	//	//$("#toc").animate({	"height": "toggle", "opacity": "toggle"	}, 300);
	//	$("select").selectbox();
	//	if($(this).hasClass("active")) { $(this).removeClass("active"); }
	//	else { $(this).addClass("active"); }
	//});

});
var Home = {
	initialize: function() {
		$(".tip").tipTip({defaultPosition: "right", edgeOffset: 5, delay: 100, fadeIn: 100, fadeOut: 100});
		$(".info_tip").tipTip({defaultPosition: "top", edgeOffset: 5, delay: 100, fadeIn: 100, fadeOut: 100});
		$("#subscribe_form").validate({
		    invalidHandler: function(form, validator) {
		      var errors = validator.numberOfInvalids();
		      if (errors) {
		        var message = errors == 1
		          ? 'You missed 1 field. It has been highlighted'
		          : 'You missed ' + errors + ' fields. They have been highlighted';
		        //$("div.error span").html(message);
		        //$("div.error").hide();
				$("#subscribe_form p").addClass("error");
		      } else {
		        //$("div.error").hide();
		      }
		    },
			errorPlacement: function(error, element) { } 
		 });
	}
};
var HomeOld = {
	initialize: function() {
			$(".tip").tipTip({defaultPosition: "right", edgeOffset: 5, delay: 100, fadeIn: 100, fadeOut: 100});
			$(".info_tip").tipTip({defaultPosition: "top", edgeOffset: 5, delay: 100, fadeIn: 100, fadeOut: 100});
			$("select").selectbox();
			$(".jquery-selectbox-item").click(function() { 
				issue = $(this).attr("title");
				issue_name = $(this).text();
				$.ajax({
					url:"/wp-admin/admin-ajax.php",
					type:'POST',
					data:'action=articles_by_issue_homepage&issue='+issue,
					beforeSend: function() { $("#articles").fadeOut(); $("#table_of_contents p").fadeOut(); },
					success: function(results) {
						//alert(results);
						$("#articles").html(results).fadeIn();
						$("#table_of_contents p").fadeIn(); 
					}
				});
				$.ajax({
					url:"/wp-admin/admin-ajax.php",
					type:'POST',
					data:'action=get_cover_story&issue='+issue_name,
					beforeSend: function() { $("#cover_story").fadeOut(); },
					success: function(results) {
						//alert(results);
						$("#cover_story").html(results).fadeIn();
					}
				});
		 	});
		$("a.start_reading").attr("href", $("#articles ul.left li:first a").attr("href"));

		$("#subscribe_form").validate({
		    invalidHandler: function(form, validator) {
		      var errors = validator.numberOfInvalids();
		      if (errors) {
		        var message = errors == 1
		          ? 'You missed 1 field. It has been highlighted'
		          : 'You missed ' + errors + ' fields. They have been highlighted';
		        //$("div.error span").html(message);
		        //$("div.error").hide();
				$("#subscribe_form p").addClass("error");
		      } else {
		        //$("div.error").hide();
		      }
		    },
			errorPlacement: function(error, element) { } 
		 });
	}
};
var Article = {
	initialize: function() {
		
		$(".scrollable").scrollable({ size: 3 });

		$("div#previous_article a.closed").hover(function() {
			$("div#previous_article a.opened").show().css("display", "block");
			$(this).hide();
		});
		$("div#previous_article a.opened").mouseleave(function() {
				$(this).hide();
				$("div#previous_article a.closed").show();
		});
		$("div#next_article a.closed").hover(function() {
			$("div#next_article a.opened").show().css("display", "block");
			$(this).hide();
		});
		$("div#next_article a.opened").mouseleave(function() {
				$(this).hide();
				$("div#next_article a.closed").show();
		});
		
		$(".jquery-selectbox-item").live("click", function() { 
			issue = $(this).attr("title");
			issue_name = $(this).text();
			$.ajax({
				url:"/wp-admin/admin-ajax.php",
				type:'POST',
				data:'action=articles_by_issue_toc&issue='+issue,
				beforeSend: function() { $(".items").fadeOut(); },
				success: function(results) {
					$(".items").html(results).fadeIn();
					$(".scrollable").scrollable({ size: 3 });
				}
			});
		});
		
		$("div#album_review .right ul li").hover(function() {
			$("a", this).show();
			$(this).addClass("hover");
		}, function() {
			$("a", this).hide();
			$(this).removeClass("hover");
		});
		
	}
};
