/* Storyimp-effects.js */
/* Version: 1.3 - 20100204 */

$(document).ready(function(){

	//CSS settings onload
	$(".defaultText").css({'background-position':'-1399px -99px'});

	//Scroll to #
	$.localScroll();
	
	//Title Hide
	$(".titleHide").hover(function() {
		$(this).attr({title: ""});
		}, function() {
	});
	
	//Mailbox refresh
	$(".impReloader").click(function(){
		location.reload();
	});

	//Clear header search when clicked
	$("#headSearch").click(function(){
		$check = $("#headSearch").val();
		if($check == "Search"){
			$("#headSearch").val("");	
		}
	}).blur(function(){
		$check = $("#headSearch").val();
		if($check == ""){
			$("#headSearch").val("Search");	
		}
	});
	
	//Clear bar search when clicked
	$("#barSearch").click(function(){
		$check = $("#barSearch").val();
		if($check == "What do you want to read?"){
			$("#barSearch").val("");	
		}
	}).blur(function(){
		$check = $("#barSearch").val();
		if($check == ""){
			$("#barSearch").val("What do you want to read?");	
		}
	});
	
	//Clear read search when clicked
	$("#storySearch").click(function(){
		$check = $("#storySearch").val();
		if($check == "Search stories?"){
			$("#storySearch").val("");	
		}
	}).blur(function(){
		$check = $("#storySearch").val();
		if($check == ""){
			$("#storySearch").val("Search stories?");	
		}
	});
	
	//Clear group search when clicked
	$("#groupSearch").click(function(){
		$check = $("#groupSearch").val();
		if($check == "Search groups?"){
			$("#groupSearch").val("");	
		}
	}).blur(function(){
		$check = $("#groupSearch").val();
		if($check == ""){
			$("#groupSearch").val("Search groups?");	
		}
	});
	
	//Clear user search when clicked
	$("#userSearch").click(function(){
		$check = $("#userSearch").val();
		if($check == "Search users?"){
			$("#userSearch").val("");	
		}
	}).blur(function(){
		$check = $("#userSearch").val();
		if($check == ""){
			$("#userSearch").val("Search users?");	
		}
	});

	
	//Clear write boxes when clicked
	$("#barTitle").click(function(){
		$check = $("#barTitle").val();
		if($check == "Title"){
			$("#barTitle").val("");	
		}
	}).blur(function(){
		$check = $("#barTitle").val();
		if($check == ""){
			$("#barTitle").val("Title");	
		}
	});
	$("#barIntro").click(function(){
		$check = $("#barIntro").val();
		if($check == "Introduction"){
			$("#barIntro").val("");	
		}
	}).blur(function(){
		$check = $("#barIntro").val();
		if($check == ""){
			$("#barIntro").val("Introduction");	
		}
	});
	$("#barTags").click(function(){
		$check = $("#barTags").val();
		if($check == "Genre"){
			$("#barTags").val("");	
		}
	}).blur(function(){
		$check = $("#barTags").val();
		if($check == ""){
			$("#barTags").val("Genre");	
		}
	});
	
	//Clear comment title when clicked
	$("#commentTitle").click(function(){
		$check = $("#commentTitle").val();
		if($check == "Title (optional)"){
			$("#commentTitle").val("");	
		}
	}).blur(function(){
		$check = $("#commentTitle").val();
		if($check == ""){
			$("#commentTitle").val("Title (optional)");	
		}
	});
	
	//Clear blog title when clicked
	$("#blogTitle").click(function(){
		$check = $("#blogTitle").val();
		if($check == "Title (required)"){
			$("#blogTitle").val("");	
		}
	}).blur(function(){
		$check = $("#blogTitle").val();
		if($check == ""){
			$("#blogTitle").val("Title (required)");	
		}
	});
	
	//Clear blog introduction when clicked
	$("#blogIntro").click(function(){
		$check = $("#blogIntro").val();
		if($check == "Introduction (required)"){
			$("#blogIntro").val("");	
		}
	}).blur(function(){
		$check = $("#blogIntro").val();
		if($check == ""){
			$("#blogIntro").val("Introduction (required)");	
		}
	});
	
	//Write box help hover
	$("#writeBoxHelp").bind("mouseenter", function(){
		if($.browser.msie){
			$("#writeBoxHelpText").css({display:"block"});
		}else{
			$("#writeBoxHelpText").addClass("alpha");
			$("#writeBoxHelpText").css({display:"none"}).fadeIn(200);
		}
	}).bind("mouseleave", function(){
		if($.browser.msie){
			$("#writeBoxHelpText").css({display:"none"});
		}else{
			$("#writeBoxHelpText").fadeOut(400);
		}
	});
	
	//Create wizard help hover
	$(".helpFocus").bind("mouseenter", function(){
		if($.browser.msie){
			$("#createStepHelpText").css({display:"block"});
		}else{
			$("#createStepHelpText").addClass("alpha");
			$("#createStepHelpText").css({display:"none"}).fadeIn(200);
		}
	}).bind("mouseleave", function(){
		if($.browser.msie){
			$("#createStepHelpText").css({display:"none"});
		}else{
			$("#createStepHelpText").fadeOut(400);
		}
	});

	
	//Clear login boxes when clicked
	$("#username").click(function(){
		$check = $("#username").val();
		if($check == "Pen Name"){
			$("#username").val("");	
		}
	}).blur(function(){
		$check = $("#username").val();
		if($check == ""){
			$("#username").val("Pen Name");	
		}
	});
	$("#password").click(function(){
		$check = $("#password").val();
		if($check == "Password"){
			$("#password").val("");	
		}
	}).blur(function(){
		$check = $("#password").val();
		if($check == ""){
			$("#password").val("Password");	
		}
	});
	
	//Change text size to small
	$(".smallText").click(function(){
		$(".story.single p").css({'font-size':'12px', 'line-height':'20px', 'margin-bottom':'18px'});
		$(".story.single p.author").css({'font-size':'12px', 'line-height':'26px'});
		$(".smallText").addClass("select");
		$(".defaultText").removeClass("select");
		$(".largeText").removeClass("select");
		return false;
	})
	
	//Change text size to default
	$(".defaultText").click(function(){
		$(".story.single p").css({'font-size':'16px', 'line-height':'26px'});
		$(".story.single p.author").css({'font-size':'12px', 'line-height':'26px', 'margin-bottom':'22px'});
		$(".smallText").removeClass("select");
		$(".defaultText").addClass("select");
		$(".largeText").removeClass("select");
		return false;
	})
	
	//Change text size to large
	$(".largeText").click(function(){
		$(".story.single p").css({'font-size':'20px', 'line-height':'30px', 'margin-bottom':'30px'});
		$(".story.single p.author").css({'font-size':'12px', 'line-height':'26px'});
		$(".smallText").removeClass("select");
		$(".defaultText").removeClass("select");
		$(".largeText").addClass("select");
		return false;
	})
	
	//Manage publish text change
	$(".manage .unpub .publish").hover(function(){
		if ($(this).attr("rel") == "") {
			$(this).attr("rel", $(this).css("color"));
		}
		$(this)	.stop()
			.animate({"color": "#007192"}, 300);
			$(this).text("Publish +");
	},function(){
		$(this)	.stop()
			.animate({"color": $(this).attr("rel")}, 500);
			$(this).text("Unpublished");
	});
	//Manage unpublish text change
	$(".manage .pub .unpublish").hover(function(){
		if ($(this).attr("rel") == "") {
			$(this).attr("rel", $(this).css("color"));
		}
		$(this)	.stop()
			.animate({"color": "#666"}, 300);
			$(this).text("Unpublish -");
	},function(){
		$(this)	.stop()
			.animate({"color": $(this).attr("rel")}, 500);
			$(this).text("Published");
	});
	
	//Message fade
	$(".boxMessageFade").css({'display':'none'}).slideDown(500).delay(5000).fadeOut(500, function() {
		$("div").remove(".boxMessageFade");
	});
	
	//Old browser message close and cookie set
	$("#closeBrowserMessage").click(function(){
		//Write session cookie
		createCookie('StoryimpMessage','oldBrowserClosed',0)		
		//Close message
		$("#oldBrowserMessage").fadeOut(500);
	});
	
	//Create Cookie
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	// BETA STUFF BELOW HERE ->>
	//Clear signup boxes when clicked
	$("#barName").click(function(){
		$check = $("#barName").val();
		if($check == "Name"){
			$("#barName").val("");	
		}
	}).blur(function(){
		$check = $("#barName").val();
		if($check == ""){
			$("#barName").val("Name");	
		}
	});
	$("#barEmail").click(function(){
		$check = $("#barEmail").val();
		if($check == "Email Address"){
			$("#barEmail").val("");	
		}
	}).blur(function(){
		$check = $("#barEmail").val();
		if($check == ""){
			$("#barEmail").val("Email Address");	
		}
	});
	$("#barWebsite").click(function(){
		$check = $("#barWebsite").val();
		if($check == "Website (optional)"){
			$("#barWebsite").val("");	
		}
	}).blur(function(){
		$check = $("#barWebsite").val();
		if($check == ""){
			$("#barWebsite").val("Website (optional)");	
		}
	});

});
