twttr.anywhere("1", function(T) {
	ch = $("meta[property=og:title]").attr("content");
	$("img.1").click( function(){
	$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " looks very good for higher prices from here");					   
	})
	$("img.2").click( function(){
	$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " appears to be breaking out and may be headed higher from here");					   
	})
	$("img.3").click( function(){
	$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " is putting in some sideways action for now");					   
	})
	$("img.4").click( function(){
	$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " appears to be breaking down and may be headed lower from here");					   
	})
	$("img.5").click( function(){
	$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " is in big trouble here");					   
	})
	
	T("#tbox").tweetBox( {
	height : 42,
	width : 515,
	label : "What's Happening With " + ch + "?",
	defaultContent : "$" + ch,
	onTweet : function() {
		$('#tweep').append('<div align="center" id="thanks" class="style4">Thanks For Tweeting!</div>');
		$('#thanks').fadeOut(2000, function() {
			window.location.reload();
		});
	}
	});

	T("#hover").hovercards( {
	expanded : true,
	username : function(node) {
	return node.alt;
	}
	});
		
	T.hovercards( {
	expanded : true
	});

	if (T.isConnected()) {
		$("#login-logout").append('<button id="signout" type="button">Sign Out</button>');
		$("#signout").bind("click", function() {
			twttr.anywhere.signOut();
		});

		$("a.reply").click(function() {
			if ($('iframe.twitter-anywhere-tweet-box').contents().find('#tweet-box').size() == 1) {
				inreplyto = $(this).attr("id");
				tweepsname = $(this).attr("title");
				$('#tbox').fadeOut('fast');
				twttr.anywhere("1.1", function(T) {
					T("#replytweetbox").tweetBox( {
					data : {
						in_reply_to_status_id : inreplyto
					},
					height : 42,
					width : 515,
					label : 'Reply To ' + tweepsname,
					defaultContent : "$" + ch + " " + tweepsname,
					onTweet : function() {
						$('#replytweetbox').append('<div align="center" id="thanks" class="style4">Thanks For Tweeting!</div>');
						$('#thanks').fadeOut(2000);
					}
				    });
			    });
			}
		});
		
		currentUser = T.currentUser;
		screenName = currentUser.data('screen_name');
		profileImage = currentUser.data('profile_image_url');
		description = currentUser.attributes.description;
		if(description == null) {
			description = "";
		}

		profileImageTag = '<img id="userloggedin" width="48" height="48" align="top" src="' + profileImage + '"/>';
		$('#tweep').append('<table class="striped" height="48" width="815px"><tr><td width="195">' + profileImageTag + ' <span class="style4">' + screenName + '</span></td><td><span id="thanksfortweeting" class="tagstyle2">' + description + '</span></td></tr></table>');

		$("img.upordown").click(function() {
			ticker = $(this).attr("title");
			direction = $(this).attr("alt");
			//sendToTwitter = "$" + ticker + " chart says " + direction + " http://www.bigmovingstock.com/index.php?ch=" + ticker;
			//T.Status.update(sendToTwitter);
			$.get("updown.php", {
			ch : ticker,
			chartsays : direction
			});
			$('#tweep').append('<div align="center" id="thanks" class="style4">Thanks For Your Stock Pick!</div>');
			$('#thanks').fadeOut(2000, function() {
				window.location.reload();
			});
		});

		$("a.retweet").click(function() {
			status = $(this).attr("id");
			T.Status.retweet(status);
			$('#tweetThanks').append('<div align="center" id="thanks" class="style4">Thanks For Retweeting!</div>');
			$('#thanks').fadeOut(2000);
		});

		T.bind("signOut", function(e) {
			$('#login-logout').append('<br><br><div id="bye" class="style4">Thanks For Visiting!</div>');
			$('#bye').fadeOut(2000, function() {
				window.location.reload();
			});
		});

	} else {
		T("#tweep").connectButton( {
			size : "medium"
		});

		//$("img.upordown").click(function() {
		//	T.signIn();
		//});
		
		$("img.upordown").click(function() {
			ticker = $(this).attr("title");
			direction = $(this).attr("alt");
			//sendToTwitter = "$" + ticker + " chart says " + direction + " http://www.bigmovingstock.com/index.php?ch=" + ticker;
			//T.Status.update(sendToTwitter);
			$.get("updown.php", {
			ch : ticker,
			chartsays : direction
			});
			$('#tweep').append('<div align="center" id="thanks" class="style4">Thanks For Your Stock Pick!</div>');
			$('#thanks').fadeOut(2000, function() {
				window.location.reload();
			});
		});

		$("a.retweet").click(function() {
			T.signIn();
		});

		$("a.reply").click(function() {
			T.signIn();
		});

	}

	T.bind("authComplete", function(e, user) {
		//setTimeout(window.location.reload(), 2500);
	});
});	 //end twttr anywhere 

$(function effects() {
	$('a[hreflang|=en]').click(function() {
	createCookie('sh',pageYOffset,0)	
	})
	
	$(document).ready( function(){
	scrollTo(0,readCookie('sh'));
	eraseCookie('sh');
	});
	
	$("img.upordown").hover(function() {
		$(this).animate( {
			opacity: "2"
		}, 400);
	}, function() {
		$(this).animate( {
			opacity: ".5"
		}, 400);
	});

	$('#centerbody').toggle(function() {
		$(this).fadeOut('fast', function() {
			ticker = $('#chart').attr("alt");
			$('#centerbody').load('oneyear.php', {
				info : ticker
			}).fadeIn('slow');
		});
	}, function() {
		$(this).fadeOut('fast', function() {
			ticker = $('#chart').attr("alt");
			$('#centerbody').load('sixmonth.php', {
				info : ticker
			}).fadeIn('slow');
		});
	});
	
	$("#centerheader").hover( function(){
		$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css("border","1px solid #00CC00");
		}, function (){
		$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css("border","1px solid #AAAAAA");
		}
	);
	
	$("#replytweetbox").hover( function(){
 		$("#replytweetbox>iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css("border","1px solid #00CC00");
  		}, function (){
  		$("#replytweetbox>iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css("border","1px solid #AAAAAA");
 		}
	);

	$("div.lighter:even").addClass("striped");
	$("div.lighter2:even").addClass("striped2");

	var x_offset = 190;
	var y_offset = 20;
	$('a.preview').live('mouseover', function(e) {
		this.t = this.title;
		this.title = "";
		var c = (this.t !== "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='" + this.rel + "' alt='Chart preview' />" + c + "</p>");
		$("#preview").css("top", (e.pageY - x_offset) + "px").css("left", (e.pageX + y_offset) + "px").fadeIn("fast");
	});
	$('a.preview').live('mouseout', function(e) {
		this.title = this.t;
		$("#preview").remove();
	});
	$('a.preview').live('mousemove', function(e) {
		$("#preview").css("top", (e.pageY - x_offset) + "px").css("left", (e.pageX + y_offset) + "px");
	});
}); //end effects() self executing function

//handle cookies
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=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}