jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
	jQuery("<img>").attr("src", arguments[i]);
  }
}
$(document).ready(function(){	
	var intTop;
	var intMainY;
	var intFade;
	var bolScrolled = false;
	var bolNewTop = false;
	var bolIsIE = $.browser.msie;
	var bolIsIE6 = false;
	var bolIsIphone = false;
	var bolLockIslands = true;
	if (bolIsIE && $.browser.version.substr(0,1)<7) {
	   bolIsIE6 = true;
	}
	if (navigator.userAgent.match(/iPhone/i)) {
		bolIsIphone = true;
	}
	
	$("a[href='https://ssl.arcstone.com/nonprofitsolutions/adfed/TheShow2009/index1.cfm']").click(function() {
		window.open($(this).attr("href"),'theshow_tickets','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=650');
		return false;					 
	});
	
	$("#revealer #signupor a").click(function() {
		$.loginsignup(true, false);
		return false;
	});
	
	if (bolIsIE6 == false && bolIsIphone == false) {
	  	sIFRActivate();
	}
	
	
	$(".pinkbg span").css("opacity", 0.3);
	var intAddtnWidth = 25;
	if (bolIsIE) {
		intAddtnWidth = 5;
	}
	$(".pinkbg span").each(function(i){
		$("h2", $(this).parent()).css("display", "inline");
		$(this).width($("h2", $(this).parent()).width()	+ intAddtnWidth);
		$("h2", $(this).parent()).css("display", "block");
	});
	function resetIslands() {
		bolLockIslands = true;

		$("#quitplan").css({top:"230px"});
		$("#plane").css({top:"120px"});
		$("#island16").css({top:"58px"});
		$("#island15").css({top:"363px"});
		$("#island14").css({top:"343px"});
		$("#island12").css({top:"318px"});
		$("#island11").css({top:"401px"});
		$("#island9").css({top:"453px"});
		$("#island8").css({top:"323px"});
		$("#island7").css({top:"163px"});
		$("#island6").css({top:"300px"});
		$("#island5").css({top:"293px"});
		$("#island4").css({top:"165px"});
		$("#island3").css({top:"351px"});
		$("#island2").css({top:"238px"});
		$("#island1").css({top:"245px"});
		
		$("#island13, #island10, #island0").show();
		//$("#island8, #island13, #island10, #island0").css({opacity:1});
	}
	function onScrollEvent() {
		if (bolScrolled == false) {
			bolScrolled = true;	
		}
		intTop = $(window).scrollTop();
		intMainY = $("#main").position().top;		
		
		if (intTop == 0 && bolNewTop == false && bolIsIE6 == false) {
			bolNewTop = true;
			//easter eggness!
			resetIslands();
			$("#newtop").animate({marginTop:"0px"}, 650, 'easeOutSine', function() {
				resetIslands();
			});
		}
		
		if (intTop > intMainY && intTop < intMainY + 580) {
			bolLockIslands = false;
			intTop -= intMainY;
			
			$("#quitplan").css({top:(230 - Math.round(intTop*1.2)) + "px"});
			$("#plane").css({top:(120 - Math.round(intTop*0.2)) + "px"});
			$("#island16").css({top:(58 - Math.round(intTop*0.5)) + "px"});
            $("#island15").css({top:(363 - Math.round(intTop*1.4)) + "px"});
            $("#island14").css({top:(343 - Math.round(intTop*1)) + "px"});
            $("#island12").css({top:(318 - Math.round(intTop*0.8)) + "px"});
            $("#island11").css({top:(401 - Math.round(intTop*1.6)) + "px"});
            $("#island9").css({top:(453 - Math.round(intTop*1.2)) + "px"});
           
            if (intTop > 40) {
                $("#island4").css({top:(165 - Math.round((intTop - 40)*0.4)) + "px"});
                $("#island6").css({top:(300 - Math.round((intTop - 40)*0.4)) + "px"});
                $("#island8").css({top:(323 - Math.round((intTop - 40)*0.6)) + "px"});
            }
           
            if (intTop > 80) {
                $("#island7").css({top:(163 - Math.round((intTop - 80)*0.2)) + "px"});
                $("#island3").css({top:(351 - Math.round((intTop - 80)*0.2)) + "px"});
            }
           
            $("#island5").css({top:(293 - Math.round(intTop*0.7)) + "px"});
            
            if (intTop > 100) {
            	$("#island2").css({top:(238 - Math.round((intTop - 100)*0.1)) + "px"});
            }
            
            $("#island1").css({top:(245 - Math.round(intTop*0.3)) + "px"});
			
			
			//fades
			//intFade = (1 - intTop*0.025);
			//if (intFade < 0) {
			if (intTop == 0) {
				//intFade = 0;
				$("#island13, #island10, #island0").show();
			} else {
				$("#island13, #island10, #island0").hide();
			}
			//$("#island8, #island13, #island10, #island0").css({opacity:intFade});
			
		} else if (intTop < intMainY) {
			if (bolLockIslands == false) {
				resetIslands();
			}
		}
		
	}
	
	//days left countdown
	/*
	var intDaysLeft = Math.ceil((new Date(2009, 9, 23).getTime() - new Date().getTime())/86400000);
	var strDaysLeft = "";
	if (intDaysLeft == 1) {
		strDaysLeft = intDaysLeft + " Day";
	} else if (intDaysLeft < 0) {
		strDaysLeft = "0 Days";
	} else {
		strDaysLeft = intDaysLeft + " Days";
	}
	*/
	$("#logo").before("<div id=\"daysleft\"></div>");
	
	var intIE6Top = 0;
	function harassmentIE6Scroll() {
		intIE6Top = $(window).scrollTop() + 10;
		var mainHeight = $("#main").height();
		if ((intIE6Top + $("#harassment").height()) > mainHeight) {
			intIE6Top = (mainHeight - ($("#harassment").height() + 10));
		}
		$("#harassment").css({top:intIE6Top + "px"});
	}
	function harassmentIE6Resize() {
		if ($(window).width() <= 940) {
			$(".ie6hate").css({"width":"940px"});
		} else {
			$(".ie6hate").css({"width":"100%"});
		}
	}
	function ie6hate() {
		//insert harassing lightbox. DEATH TO IE6!
		
		$("#main, #newtop").prepend("<div class=\"ie6hate\"></div>");
		
		var strIE6Hate = "<div id=\"harassment\">";
		strIE6Hate += "\t<div id=\"upperleft\"></div>\n<a href=\"#\" id=\"upperright\"></a>\n<div id=\"bottomleft\"></div>\n<div id=\"bottomright\"></div>\n";
		strIE6Hate += "\t<div id=\"top\"></div>\n<div id=\"right\"></div>\n<div id=\"bottom\"></div>\n<div id=\"left\"></div>\n";
		strIE6Hate += "\t<div id=\"assault\">\n";
		strIE6Hate += "\t\t<h1>2001 called.</h1>\n";
		strIE6Hate += "\t\t<h2>It wants its browser back.</h2>\n";
		strIE6Hate += "\t\t<p>Sure, you can access this site using Internet Explorer 6.  But to get the full experience, you need to <a href=\"http://www.microsoft.com/windows/internet-explorer\">upgrade that crap</a>. Your browser is 8 years old.  It&#8217;s time to make a clean break.</p>";
		strIE6Hate += "\t\t<p>For those of you stuck on a corporate machine you can&#8217;t upgrade, we feel your pain.  Might we make a suggestion?  Take your IT guy out for a beer or several and get him to sign a cocktail napkin promising to upgrade your company&#8217;s browser. Pronto.</p>";
		strIE6Hate += "\t\t<p>If you are one of the IT guys who has machines still running IE6, what the hell, guy?  Seriously.</p>\n";
		strIE6Hate += "\t\t<p><em>Try one of these lovely browsers for an out-of-this-world browsing experience:</em></p>\n";
		strIE6Hate += "\t\t<div class=\"images\">\n";
		strIE6Hate += "\t\t<a href=\"http://www.getfirefox.com\" title=\"Firefox\"><img alt=\"Firefox\" src=\"images/firefoxlogo.jpg\" /></a>\n";
		strIE6Hate += "\t\t<a href=\"http://www.apple.com/safari\" title=\"Safari\"><img alt=\"Safari\" src=\"images/safarilogo.jpg\" /></a>\n";
		strIE6Hate += "\t\t<a href=\"http://www.google.com/chrome\" title=\"Chrome\"><img alt=\"Chrome\" src=\"images/chromelogo.jpg\" /></a>\n";
		strIE6Hate += "\t\t<a href=\"http://www.opera.com\" title=\"Opera\"><img alt=\"Opera\" src=\"images/operalogo.jpg\" /></a>\n";
		strIE6Hate += "\t\t<a href=\"http://www.microsoft.com/windows/internet-explorer\" title=\"Internet Explorer 8\"><img alt=\"Internet Explorer 8\" src=\"images/ie8logo.jpg\" /></a>\n";
		strIE6Hate += "\t\t<div class=\"clear\"></div>\n"
		strIE6Hate += "\t\t</div>\n"
		strIE6Hate += "\t</div>\n";
		strIE6Hate += "</div>";
		
		$("body").prepend(strIE6Hate);
		
		$(".ie6hate").css({opacity:0.5});
		
		if (bolIsIE6) {
			$(window).scroll(harassmentIE6Scroll);
			$(window).resize(harassmentIE6Resize);
			$(".ie6hate").height($(document).height());
			$("#harassment").pngFix();
		}
		
		$("#harassment #upperright, .ie6hate").click(function () {
			if (bolIsIE6) {
				$(window).unbind("scroll", harassmentIE6Scroll);
				$(window).unbind("resize", harassmentIE6Resize);
			}
			$(".ie6hate, #harassment").fadeOut(function () {
				$(".ie6hate, #harassment").remove();
			});
			return false;
		});
	}
	
	if (bolIsIE6) {
		//$("body").scroll(onScrollEvent);
		
		$("#pinar, #newtop").remove();
		if ($.cookie('ie6hate') != 'seen') {
			$.cookie('ie6hate', 'seen');
			ie6hate();
		}
		
	} else if (bolIsIphone == false) {
		$(window).scroll(onScrollEvent);
	}
	if (bolIsIE6 == false && $.query.get("ie6") == "evil") {
		ie6hate();
	}
	
	if ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) {
		$(".signin .signinfield").css("paddingTop", "2px");
	}
	
	$("#signinbg").css({top:"-160px"});
	$(".signin #revealer").css({height:"50px"});
	$("ul#mainnav").css({marginTop:"20px"});
	
	$(".signinuser").focus(function() {
		if ($.trim($(this).val()) == "Enter Your Username") {
			$(this).val("");
		}
		$(".signin #revealer, #signinbg, ul#mainnav").stop(true, false);
		$(".signin #revealer").animate({height:"150px"}, 500, 'easeOutSine');
		$("ul#mainnav").animate({marginTop:"120px"}, 500, 'easeOutSine');
		$("#signinbg").animate({top:"-60px"}, 500, 'easeOutSine');
	});
	$(".signinuser").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val("Enter Your Username");
		}
		if ($.trim($(this).val()) == "Enter Your Username") {
			$(".signinpass2").hide();
			$(".signinpass").show();
			$(".signin #revealer, #signinbg, ul#mainnav").stop(true, false);
			$(".signin #revealer").animate({height:"50px"}, 500, 'easeOutSine');
			$("ul#mainnav").animate({marginTop:"20px"}, 500, 'easeOutSine');
			$("#signinbg").animate({top:"-160px"}, 500, 'easeOutSine');
		}
	});
	$(".signinpass").focus(function() {
		$(this).hide();
		$(".signinpass2").show();
		$(".signinpass2").val("");
		$(".signinpass2").focus();
	});
	$(".signinpass2").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).hide();
			$(".signinpass").show();
		}					
	});
	$(".signinpass2").hide();
	$(".signinpass").show();
	
	//augmented reality
	var bolArActive = false;
	var bolFlashActive = false;
	var bolFlashActiveAlt = false;
	var bolInsertARSifr = false;
	
	$("#tryit").click(function () {
		if (bolArActive == false) {
			bolArActive = true;
			
			if ($.browser.msie || navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
				$(this).hide();
			} else {
				$(this).stop(true, false);
				$(this).fadeOut(650);
			}
			
			$("#whatis, #webcam, #bigar").stop(true, false);
			$("#whatis").animate({top:"340px"}, 800, 'easeInBack');
			$("#webcam").animate({top:"340px"}, 800, 'easeInBack', function() {
				$("#bigarholder").show();
				
				if (bolInsertARSifr == false && bolIsIE6 == false) {
					bolInsertARSifr = true;
					sIFRAR();
				}

				$("#bigar").animate({top:"60px"}, 1000, 'easeOutBack');
			});
			pageTracker._trackPageview('/augmentedflash-tryit');
		}
		return false;
	});
	
	$("#argetstarted").click(function() {
		if (bolFlashActive == false) {
			if ($.hasFlashPlayer) {
				bolFlashActive = true;
				if (bolFlashActiveAlt) {
					bolFlashActiveAlt = false;
					$("#arflash").remove();
				}
				
				$("#main").append("<div id=\"arflash\"></div>");
				
				$('#arflash').flash({ swf:'/swf/AdFedAR.swf', width:620, height:465, params:{menu:'false', allowFullScreen:'true', allowScriptAccess:'always', wmode:'opaque'}});
				pageTracker._trackPageview('/augmentedflash-getstarted');
			}
		}
		return false;
	});
	$("#aralternative").click(function() {
		if (bolFlashActiveAlt == false) {
			if ($.hasFlashPlayer) {
				bolFlashActiveAlt = true;
				if (bolFlashActive) {
					bolFlashActive = false;
					$("#arflash").remove();
				}
				
				$("#main").append("<div id=\"arflash\"></div>");
				$('#arflash').flash({ swf:'/swf/AdFedStatic.swf', width:620, height:465, params:{menu:'false', allowFullScreen:'true', allowScriptAccess:'always', wmode:'opaque'}});
				pageTracker._trackPageview('/augmentedflash-getstarted-alt');
			}
		}
		return false;
	});
	
	$("#arclose").click(function() {
		if (bolArActive) {
			bolArActive = false;
			if (bolFlashActive == true || bolFlashActiveAlt == true) {
				bolFlashActive = false;
				bolFlashActiveAlt = false;
				$("#arflash").remove();
			}
			$("#whatis, #webcam, #bigar, #tryit").stop(true, false);
			$("#bigar").animate({top:"622px"}, 900, 'easeInBack', function() {
				$("#bigarholder").hide();
				
				if ($.browser.msie || navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
					$("#whatis").animate({top:"80px"}, 850, 'easeOutBack');
					$("#webcam").animate({top:"80px"}, 850, 'easeOutBack', function() {
						$("#tryit").show();
					});
				} else {
					$("#whatis").animate({top:"80px"}, 850, 'easeOutBack');
					$("#webcam").animate({top:"80px"}, 850, 'easeOutBack');
					$("#tryit").fadeIn(800);
				}
			});
		}
		
		return false;
	});
	
	
	$("#closear").click(function () {
		if (bolArActive) {
			bolArActive = false;
			
		}
		return false;
	});
	
	
	var refreshId;
	String.prototype.linkify = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) {
		m = m.link(m);
		m = m.replace('href="','target="_blank" href="');
		return m;
	  });
	};
	
	String.prototype.linkuser = function() {
	  return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(us) {
		var username = us.replace("@","")
		return us.link("http://twitter.com/"+username);
	  });
	};
	
	String.prototype.linktag = function() {
	  return this.replace(/[#]+[A-Za-z0-9-_]+/, function(t) {
		var tag = t.replace("#","%23");
		return t.link("http://search.twitter.com/search?q="+tag);
	  });
	
	}; 
	
	function timeAgo(timeMS, nowMS) {
		var timeAgoSec = (nowMS - timeMS)/1000;
		var strUnit = "";
		var numTimeAgo = 0;
		if (timeAgoSec < 60) {
			numTimeAgo = Math.ceil(timeAgoSec);
			strUnit = " second";
		} else if (timeAgoSec < 3600) {
			numTimeAgo = Math.round(timeAgoSec/60);
			strUnit = " minute";
		} else if (timeAgoSec < 86400) {
			numTimeAgo = Math.round(timeAgoSec/3600);
			strUnit = " hour";
		} else if (timeAgoSec < 31536000) {
			numTimeAgo = Math.round(timeAgoSec/86400);
			strUnit = " day";
		} else {
			numTimeAgo = Math.round(timeAgoSec/31536000);
			strUnit = " year";
		}
		if (numTimeAgo != 1) {
			strUnit += "s";
		}
		
		return numTimeAgo + strUnit + " ago";
	}
	
	var intTweetMS = 5000;
	var intRefreshCount = 0;
	var intLastStatusID = 0;
	function getTweets(numTweets) {
		clearInterval(refreshId);
		var strKeyword ="%23theshowmn+OR+theshowmn";
		if (numTweets == 1) {
			var url = "http://search.twitter.com/search.json?q=" + strKeyword + "&rpp=" + numTweets + "&lang=en&since_id=" + intLastStatusID + "&callback=?";
		} else {
			var url = "http://search.twitter.com/search.json?q=" + strKeyword + "&rpp=" + numTweets + "&lang=en&page=1&callback=?";
		}
		jQuery.getJSON(url, 
		function(json){
			var intEachCount = 1;
			$(json.results).each(function() {
				var strTweet = "<li id=\"" + this.id + "\">\n\t<a href=\"http://twitter.com/" + this.from_user + "\" title=\"" + this.from_user + "\" class=\"profileimg\"><img width=\"73\" height=\"73\" src=\"" + this.profile_image_url.replace("_normal.", "_bigger.") + "\" alt=\"" + this.from_user + "\" /></a><p>" + this.text.linkify().linkuser().linktag() + "<br /><a href=\"http://twitter.com/" + this.from_user + "/status/" + this.id  + "\" class=\"stamp\">(" + this.from_user + ") <span id=\"" + new Date(this.created_at).getTime() + "\"></span></a></p><div class=\"clear\"></div>\n</li>\n";
				if (numTweets == 1) {
					intLastStatusID = this.id;
					$("ul#show09twitter").prepend(strTweet);
					$("#" + this.id).css({marginTop:"-99px"}).animate({marginTop:"0px"}, 900, 'easeOutSine', function() {		
						$("ul#show09twitter li:nth-child(5)").remove();
					});
				} else {
					$("ul#show09twitter").append(strTweet);
					if (intEachCount == 1) {
						intLastStatusID = this.id;
						$("#" + this.id).css({marginTop:"-396px"}).animate({marginTop:"0px"}, 1300, 'easeOutSine');
					}
				}
				intEachCount++;
			});
			
			//update time stamps
			var now = new Date();
			$(".stamp span").each(function(i){
				$(this).text(timeAgo(this.id, now.getTime()));
			});

			
			refreshId = setInterval(function()
			{
				//throttles twitter call rate over time
				if (intRefreshCount >= 38) {
					intTweetMS = 56000;
				} else if (intRefreshCount > 30) {
					intRefreshCount++;
					intTweetMS = 43000;
				} else if (intRefreshCount > 20) {
					intRefreshCount++;	
					intTweetMS = 14000;
				} else if (intRefreshCount > 10) {
					intRefreshCount++;	
					intTweetMS = 8000;
				} else {
					intRefreshCount++;	
				}
				getTweets(1);
			}, intTweetMS);
			
		});
	}
	$("#localchatter h4:first").after("<ul id=\"show09twitter\"></ul>");
	
	
	var sndKonamiA;
	var sndKonamiB;
	if ( window.addEventListener ) {
		var hitkeys = [];
		var konami = "38,38,40,40,37,39,37,39,66,65,";
		function keyHit(e) {
			if (konami.indexOf((e.keyCode.toString() + ",")) >= 0) {
				hitkeys.push(e.keyCode);
				if ((hitkeys.toString() + ",").indexOf(konami) >= 0 ) {
					window.removeEventListener("keydown", keyHit, true);
					
					var intScrollSpeed = Math.abs(Math.round(($("#eggs").offset().top - $(window).scrollTop()) * 0.3));
					
					$("#spelunking").css({"height":"438px"});
					$("#cavebottom").css({top:"249px"});
					$("#eggs").css({"backgroundImage":"url(/images/konami_a.png)", "height":"338px"}).html("<a target=\"_blank\" class=\"carl\" href=\"http://www.carlschultze.com\"></a><a class=\"jason\" target=\"_blank\" href=\"http://www.jasonelson.com\"></a><a class=\"andrew\" target=\"_blank\" href=\"http://www.andrewnorell.com\"></a>");
					
					$.scrollTo($("#eggs"), intScrollSpeed, 'easeOutSine');
					sndKonamiA.play();
					
					setTimeout(function() {
						
						$("#eggs").css({"backgroundImage":"url(/images/konami_b.png)"});
						sndKonamiB.play();
						pageTracker._trackPageview('/konamicode');
					}, intScrollSpeed + 1800);
					
				}
			} else {
				hitkeys = [];
			}
		}
		window.addEventListener("keydown", keyHit, true);
	}
	
	soundManager.url = '/swf/';
	soundManager.debugMode = false;
	soundManager.onload = function() {
	  	sndKonamiA = soundManager.createSound({
			id: 'sndKonamiA',
			url: '/javascripts/cheer.mp3'
		});
		sndKonamiB = soundManager.createSound({
			id: 'sndKonamiB',
			url: '/javascripts/konamib.mp3'
		});
		sndKonamiA.load();
		sndKonamiB.load();
	}
	
	getTweets(4);
	$.preloadImages("/images/bigarbg.png", "/images/konami_a.png", "/images/konami_b.png");
	
	$("#moondoor").click(function() {
		var strDiatribe = "<h2>We are so over Flash</h2>\n";
		strDiatribe += "<h3>An FYI about how kick ass this site is</h3>\n";
		strDiatribe += "<p>Yeah, there&#8217;s the funky shoes. The social ineptitude. But what really sets Interactive people apart is their ability to make the work rock, while also rocking User Experience and Web Standards. Flash was cool in its day. It still is for some stuff. But ignoring usability is so 2004.</p>\n";
		strDiatribe += "<p>We&#8217;re not going to lie. We wanted to flaunt our interactive muscle on this site. We wanted to show some cool interaction, big ideas and have some fun. But doing it in Flash would be like playing baseball with steroids, and we don&#8217;t roll like that.</p>\n";
		$.alertmessage(strDiatribe);
		pageTracker._trackPageview('/moondoorclick');
		return false;
	});
	
	$(".forget").click(function() {
		$.forgotpassword();
		return false;
	});
	
	$(".forget").mousedown(function() {
		$.forgotpassword();
		return false;
	});
	
	$(".hr").each(function(i){
		$(this).prepend("<div class=\"hrleft\"></div><div class=\"hrcenter\"></div><div class=\"hrright\"></div>");
	});

});
jQuery.alertmessage = function(strHtml) {
	$("body").append("<div class=\"alertmessageboxpagebg\"></div>");
	$(".alertmessageboxpagebg").height($(document).height());
	$(".alertmessageboxpagebg").css({opacity:0.5}).hide();
	
	
	var strAlertMessage = "<div class=\"alertmessagebox\">\n";
	strAlertMessage += "\t<div class=\"message\">";
	strAlertMessage += "\t\t" + strHtml;
	strAlertMessage += "\t\t<a href=\"#\" class=\"closebutton\"><img alt=\"Close\" src=\"/images/alertmessageclose.png\" /></a>\n";
	strAlertMessage += "\t</div>";
	strAlertMessage += "</div>";
	
	$("body").append(strAlertMessage);
	$(".alertmessagebox").css({marginTop:-(($(".alertmessagebox").height() + 18)/2)}).hide();
	$(".alertmessageboxpagebg, .alertmessagebox").fadeIn("fast");
	
	$(".alertmessageboxpagebg, .alertmessagebox .closebutton").click(function () {
		$(".alertmessageboxpagebg, .alertmessagebox").fadeOut(function () {
			$(".alertmessageboxpagebg, .alertmessagebox").remove();
		});
		return false;
	});
}
jQuery.forgotpassword = function() {
	$("body").append("<div class=\"alertmessageboxpagebg\"></div>");
	$(".alertmessageboxpagebg").height($(document).height());
	$(".alertmessageboxpagebg").css({opacity:0.5}).hide();
	var strAlertMessage = "<div class=\"forgotpasswordbox\">\n";
    strAlertMessage += "\t<div class=\"message\">\n";
    strAlertMessage += "\t\t<h2>Forgot your password?</h2>\n";
    strAlertMessage += "\t\t<span class=\"alertcopy\">We'll email you a link that will allow you to reset your password.</span>\n";
    strAlertMessage += "\t\t<div class=\"containerform\" id=\"frmtxt2\">\n";
	strAlertMessage += "\t\t<form action=\"/forgot_password\" class=\"ajaxForm\" method=\"post\">\n";
	//strAlertMessage += "\t\t<input name=\"authenticity_token\" type=\"hidden\" value=\"" + encodeURIComponent(AUTH_TOKEN) + "\" />\n";
    strAlertMessage += "\t\t\t<div class=\"frmtxt2bg\">\n";
    strAlertMessage += "\t\t\t\t<input id=\"user_email\" name=\"user[email]\" maxlength=\"100\" size=\"19\" value=\"Your email\" type=\"text\" />\n";     
    strAlertMessage += "\t\t\t</div>\n";
    strAlertMessage += "\t\t\t<div id=\"resetpassword\" class=\"resetpassbutton\"><button type=\"submit\"><span>Reset My Password</span></button></div>\n";
    strAlertMessage += "\t\t\t<div class=\"clear\"></div>\n";
	strAlertMessage += "\t\t</form>\n";
    strAlertMessage += "\t\t</div>\n";
    strAlertMessage += "\t\t<div class=\"clear\"></div>\n";
    strAlertMessage += "\t\t<a href=\"#\" class=\"closebutton\"><img alt=\"Close\" src=\"/images/alertmessageclose.png\" /></a>\n";
    strAlertMessage += "\t</div>\n";
	strAlertMessage += "</div>\n";
	
	
	$("body").append(strAlertMessage);
	$(".forgotpasswordbox").css({marginTop:-(($(".forgotpasswordbox").height() + 18)/2)}).hide();
	$(".alertmessageboxpagebg, .forgotpasswordbox").fadeIn("fast");
	
	$(".forgotpasswordbox input").focus(function() {
		if ($.trim($(this).val()) == "Your email") {
			$(this).val("");
		}
	});
	$(".forgotpasswordbox input").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val("Your email");
		}
	});
	
	$(".alertmessageboxpagebg, .forgotpasswordbox .closebutton").click(function () {
		$(".alertmessageboxpagebg, .forgotpasswordbox").fadeOut(function () {
			$(".alertmessageboxpagebg, .forgotpasswordbox").remove();
		});
		return false;
	});
}
jQuery.forgotpassresponse = function(strCopy, bolClose) {
	if ($(".forgotpasswordbox").length > 0) {
		$(".alertcopy").html("<strong>" + strCopy + "</strong>");
		
		if (bolClose) {
			setTimeout(function() {
				$(".alertmessageboxpagebg, .forgotpasswordbox").fadeOut(function () {
					$(".alertmessageboxpagebg, .forgotpasswordbox").remove();
				});
			}, 1800);
		}
	}
}
jQuery.loginsignup = function(bolSignup, bolCastVote) {
	$("body").append("<div class=\"vwloginbg\"></div>");
	$(".vwloginbg").height($(document).height());
	$(".vwloginbg").css({opacity:0.5}).hide();
	
	var strLoginSignup = "<div class=\"loginsignup\">\n";
	strLoginSignup += "\t<div class=\"message\">\n";
	if ($("em.loginorsignup").length == 0) {
		strLoginSignup += "\t\t<h2>Login</h2>\n";
		strLoginSignup += "\t\t<h4>You must login to comment or cast your People's Choice vote.</h4>\n";
	} else {
		strLoginSignup += "\t\t<h2>People's Choice</h2>\n";
		strLoginSignup += "\t\t<h4>You must login to cast your People's Choice vote.</h4>\n";
	}
	strLoginSignup += "\t\t<form class=\"lbloginform\" action=\"/session\" method=\"post\">\n";
	strLoginSignup += "\t\t<div class=\"inputhalf marginright\">\n";
	strLoginSignup += "\t\t<input name=\"email\" class=\"lbemail\" maxlength=\"30\" tabindex=\"1\" size=\"23\" value=\"Username (email)\" type=\"text\">\n";
	strLoginSignup += "\t\t</div>\n";
	strLoginSignup += "\t\t<div class=\"inputhalf\">\n";
	strLoginSignup += "\t\t<input class=\"lbpassword\" maxlength=\"30\" tabindex=\"2\" size=\"23\" value=\"Password\" type=\"text\">\n";
	strLoginSignup += "\t\t<input name=\"password\" class=\"lbpassword2\" maxlength=\"30\" size=\"23\" type=\"password\">\n";
	strLoginSignup += "\t\t</div>\n";
	strLoginSignup += "\t\t<div class=\"clear\"></div>\n";
	strLoginSignup += "\t\t<em>Don't have an account? <a class=\"expand\" href=\"/signup\">Sign Up.</a></em>\n";
	strLoginSignup += "\t\t<div class=\"lblogin\"><button value=\"Login\" tabindex=\"3\" type=\"submit\"><span>Login</span></button></div>\n";
	strLoginSignup += "\t\t<img src=\"/images/loader.gif\" id=\"loading1\" alt=\"Loading...\" />\n";
	strLoginSignup += "\t\t<div class=\"clear\"></div>\n";
	strLoginSignup += "\t\t</form>\n";
	strLoginSignup += "\t\t<div class=\"hrnarrow\"><hr /></div>\n";
	
	strLoginSignup += "\t\t<h2>Signup For An Account</h2>\n";
	strLoginSignup += "\t\t<form class=\"lbnewform\" action=\"/users\" enctype=\"multipart/form-data\" method=\"post\">\n";
	
	//strLoginSignup += "\t\t<input name=\"authenticity_token\" type=\"hidden\" value=\"0be811cc984113f6993fe71e247088ddbb712fb7\" />\n";
	strLoginSignup += "\t\t<input name=\"user[agency]\" type=\"hidden\" value=\"Post View Work User\" />\n";
	strLoginSignup += "\t\t<input name=\"user[address1]\" type=\"hidden\" value=\"Default Address\" />\n";
	strLoginSignup += "\t\t<input name=\"user[address2]\" type=\"hidden\" value=\"\" />\n";
	strLoginSignup += "\t\t<input name=\"user[city]\" type=\"hidden\" value=\"Default City\" />\n";
	strLoginSignup += "\t\t<input name=\"user[state]\" type=\"hidden\" value=\"MN\" />\n";
	strLoginSignup += "\t\t<input name=\"user[zip]\" type=\"hidden\" value=\"12345\" />\n";
	
	strLoginSignup += "\t\t<div class=\"inputfull\">\n";
	strLoginSignup += "\t\t<input class=\"lbnewperson\" name=\"user[name]\" maxlength=\"60\" tabindex=\"4\" size=\"23\" value=\"Your Name\" type=\"text\">\n";
	strLoginSignup += "\t\t</div>\n";
	strLoginSignup += "\t\t<div class=\"inputfull\">\n";
	strLoginSignup += "\t\t<input class=\"lbnewemail\" name=\"user[email]\" maxlength=\"60\" tabindex=\"5\" size=\"23\" value=\"Your Email\" type=\"text\">\n";
	strLoginSignup += "\t\t</div>\n";
	
	strLoginSignup += "\t\t<div class=\"inputhalf marginright\">\n";
	strLoginSignup += "\t\t<input class=\"lbnewpass\" maxlength=\"30\" tabindex=\"6\" size=\"23\" value=\"Password\" type=\"text\">\n";
	strLoginSignup += "\t\t<input name=\"user[password]\" class=\"lbnewpass2\" maxlength=\"30\" size=\"23\" type=\"password\">\n";
	strLoginSignup += "\t\t</div>\n";
	strLoginSignup += "\t\t<div class=\"inputhalf\">\n";
	strLoginSignup += "\t\t<input class=\"lbnewpass3\" maxlength=\"30\" tabindex=\"7\" size=\"23\" value=\"Confirm Password\" type=\"text\">\n";
	strLoginSignup += "\t\t<input name=\"user[password_confirmation]\" class=\"lbnewpass4\" maxlength=\"30\" size=\"23\" type=\"password\">\n";
	strLoginSignup += "\t\t</div>\n";
	strLoginSignup += "\t\t<div class=\"clear\"></div>\n";
	
	strLoginSignup += "\t\t<div class=\"lbnewsubmit\"><button value=\"Submit\" tabindex=\"8\" type=\"submit\"><span>Submit</span></button></div>\n";
	strLoginSignup += "\t\t<img src=\"/images/loader.gif\" id=\"loading2\" alt=\"Loading...\" />\n";
	strLoginSignup += "<div class=\"clear\"></div>";
	strLoginSignup += "\t\t</form>\n";
	
	strLoginSignup += "\t\t<a href=\"#\" class=\"closebutton\"><img alt=\"Close\" src=\"/images/alertmessageclose.png\" /></a>\n";
	strLoginSignup += "\t</div>\n";
	strLoginSignup += "</div>\n";
	
	
	$("body").append(strLoginSignup);
	$(".loginsignup").css({marginTop:"-99px"}).hide();
	$(".vwloginbg, .loginsignup").fadeIn("fast", function() {
		loginsignupsifr();
		if (bolSignup == true) {
			$(".loginsignup .message").animate( { height:"510px"}, "def");
			$(".loginsignup").animate( { marginTop:"-279px"}, "def");
		}
	});
	
	if (bolSignup == false) {
		$(".expand").click(function() {
			$(".loginsignup .message").animate( { height:"510px"}, "def");
			$(".loginsignup").animate( { marginTop:"-279px"}, "def");
			$(".lbnewform .lbnewperson").attr("tabindex", "4");
			$(".lbnewform .lbnewemail").attr("tabindex", "5");
			$(".lbnewform .lbnewpass").attr("tabindex", "6");
			$(".lbnewform .lbnewpass3").attr("tabindex", "7");
			$(".lbnewform .lbnewsubmit").attr("tabindex", "8");
			return false;
		});
		$(".lbnewform input").attr("tabindex", "-1");
	} else {
		$(".expand").click(function() {
			return false;
		});
	}
	
	$(".lbemail").focus(function() {
		if ($.trim($(this).val()) == "Username (email)") {
			$(this).val("");
		}
	});
	$(".lbemail").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val("Username (email)");
		}
	});
	$(".lbpassword").focus(function() {
		$(".lbpassword").hide();
		$(".lbpassword2").show().focus();
	});
	$(".lbpassword2").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(".lbpassword2").hide();
			$(".lbpassword").show();
		}
	});
	$(".lbloginform").submit(function () {
		$("#loading1").show();
		$.post($(".lbloginform").attr("action"), $(".lbloginform").serialize(), null, "script");
		if (bolCastVote == true) {
			$.cookie("vwcv", "true");
			$.cookie("vwcvst", $(window).scrollTop());
		}
		return false;
	});
	
	
	$(".lbnewperson").focus(function() {
		if ($.trim($(this).val()) == "Your Name") {
			$(this).val("");
		}
	});
	$(".lbnewperson").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val("Your Name");
		}
	});
	$(".lbnewemail").focus(function() {
		if ($.trim($(this).val()) == "Your Email") {
			$(this).val("");
		}
	});
	$(".lbnewemail").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val("Your Email");
		}
	});
	$(".lbnewpass").focus(function() {
		$(".lbnewpass").hide();
		$(".lbnewpass2").show().focus();
	});
	$(".lbnewpass2").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(".lbnewpass2").hide();
			$(".lbnewpass").show();
		}
	});
	$(".lbnewpass3").focus(function() {
		$(".lbnewpass3").hide();
		$(".lbnewpass4").show().focus();
	});
	$(".lbnewpass4").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(".lbnewpass4").hide();
			$(".lbnewpass3").show();
		}
	});
	/*
	$('.lbnewform').submit(function() {
		if ($(".lbnewperson").val() == "Contact Person") {
			$.alertmessage("<ul><li>Please enter a contact person.</li></ul>");
			return false;
		} else {
			return true;	
		}
	});
	*/
		  
	$('.lbnewform').ajaxForm({
		beforeSubmit: function(a,f,o) {
			o.dataType = "html";
			$("#loading2").show();
			if (bolCastVote == true) {
				$.cookie("vwcv", "true");
				$.cookie("vwcvst", $(window).scrollTop());
			}
		}
		, 
		complete: function(XMLHttpRequest, textStatus) {
			$('#status_bar').html('');
			//alert(XMLHttpRequest.responseText);
			var len = XMLHttpRequest.responseText.length;
			if(len != 0) {
				var err = XMLHttpRequest.responseText;
				$.alertmessage(err);
			} else {
				//location.href="/submitwork";
				location.reload(true);
			}
		}
	});
	
	$(".vwloginbg, .loginsignup .closebutton").click(function () {
		$.cookie("vwcv", "false");
		$(".vwloginbg, .loginsignup").fadeOut(function () {
			$(".vwloginbg, .loginsignup").remove();
		});
		return false;
	});
}
/* Clear focus */ 
$(document).ready(function(){
	var clearMePrevious = '';
	$('.clearMeFocus').focus(function()
	{
		if($(this).val()==$(this).attr('title'))
		{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	$('.clearMeFocus').blur(function()
	{
		if($(this).val()=='')
		{
			$(this).val(clearMePrevious);
		}
	});
});
