twttr.anywhere("1", function(T) {
	state = $("div.striped:first>b").html();
	ch = $('h1').html();
	$("img.1").click(function() {
		$.get('bitly.php', {
			ch : ch
		}, function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " Chart Looks #Bullish " + data);
		});
	});
	// $("img.3").mouseover( function(){
	// $("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " Chart Looks Neutral");})
	$("img.5").click(function() {
		$.get('bitly.php', {
			ch : ch
		}, function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val("$" + ch + " Chart Looks #Bearish " + data);
		});
	});
	T("#tbox").tweetBox( {
	height : 70,
	width : 550,
	label : "<b>What's up with " + ch + "?</b>",
	defaultContent : "$" + state,
	onTweet : function() {
		$('#messages').append('<div class="style4" align="center" id="thanks" style="-moz-border-radius:8px;-webkit-border-radius:8px;background-color:#CEFFCE; border: 1px solid rgb(0, 204, 0);">Tweet Sent!</div>');
		$('#thanks').fadeOut(5000);
	}
	});

	T("img.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("name");
				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 class="style4" align="center" id="thanks" style="-moz-border-radius:8px;-webkit-border-radius:8px;background-color:#CEFFCE; border: 1px solid rgb(0, 204, 0);">Reply Sent!</div>');
						//$('#thanks').fadeOut(3000);
						$('#replytweetbox').fadeOut(5000, function() {
						window.location.reload();
						});
					}
				    });
			    });
			}
		});
		
		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(profileImageTag + ' <span class="style4">' + screenName + '</span>');

		$("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
			});
			$('#messages').append('<div class="style4" align="center" id="thanks" style="-moz-border-radius:8px;-webkit-border-radius:8px;background-color:#CEFFCE; border: 1px solid rgb(0, 204, 0);">Nice Pick!</div>');
			$('#thanks').fadeOut(5000, function() {
				window.location.reload();
			});
		});

		$("a.retweet").click(function() {
			status = $(this).attr("name");
			T.Status.retweet(status);
			$('#tweetThanks').append('<div class="style4" align="center" id="thanks" style="-moz-border-radius:8px;-webkit-border-radius:8px;background-color:#CEFFCE; border: 1px solid rgb(0, 204, 0);">Retweet Sent!</div>');
			$('#thanks').fadeOut(5000, function() {
				window.location.reload();
			});
		});

		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 : "small"
		});
//
		$("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, bridge_code) {
				$.post('convert.php', {
					'bridge_code' : bridge_code
					   });
		//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);
	});

	$('#stockchart').toggle(function() {
		$(this).fadeOut(200, function() {
			ticker = $('#chart').attr("alt");
			$('#stockchart').load('sixmonth.php', {
				info : ticker
			}).delay(700).fadeIn(1000);
		});
	}, function() {
		$(this).fadeOut(200, function() {
			ticker = $('#chart').attr("alt");
			$('#stockchart').load('oneyear.php', {
				info : ticker
			}).delay(700).fadeIn(1000);
		});
	});
	
	$("#tbox").hover( function(){
		$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css({"border" : "1px solid #00CC00", "background-color" : "#CEFFCE", "font-weight" : "bold"});
		}, 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");
 		}
	);

	$("label.lightertweet").addClass("striped2");
	$("div.lighter:even").addClass("striped");
	$("div.lighter2:even").addClass("striped2");
	$("div.lightertweet:odd").addClass("striped");
	$("div.lightertweet:even").addClass("striped2");
	$("li.lightertweet:odd").addClass("striped");
	$("li.lightertweet:even").addClass("striped2");
	
	$('input.striped').click(function(){$(this).focus().val('');});

	
	
	$("label.lightertweet").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);
	
	$("input.striped").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);
	
	$("div.stripedtweet").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);
	
	$("div.lightertweet").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);

	$("li.lightertweet").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);
	
	$("table.striped").hover( function(){
 		$(this).css("border","1px solid #00CC00");
  		}, function (){
  		$(this).css("border","1px solid #F5F5FF");
 		}
	);

	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");
	});
	
		
	$("#ttmostactive").click(function() {
		$.get('getmostactive.php', function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css({"border" : "1px solid #00CC00", "background-color" : "#CEFFCE", "font-weight" : "bold"});
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val(data);
		});
	});
	
	$("#ttadvancers").click(function() {
		$.get('getadvancers.php', function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css({"border" : "1px solid #00CC00", "background-color" : "#CEFFCE", "font-weight" : "bold"});
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val(data);
		});
	});
	
	$("#ttdecliners").click(function() {
		$.get('getdecliners.php', function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css({"border" : "1px solid #00CC00", "background-color" : "#CEFFCE", "font-weight" : "bold"});
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val(data);
		});
	});
	
	$("#ttnewhighs").click(function() {
		$.get('getnewhighs.php', function(data) {
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").focus().css({"border" : "1px solid #00CC00", "background-color" : "#CEFFCE", "font-weight" : "bold"});
			$("iframe.twitter-anywhere-tweet-box").contents().find("#tweet-box").val(data);
		});
	});
}); //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);
}
*/
