$(function(){
	/** HOW IT WORKS **/
	$("#promise_text a.tooltip_link").click(function(){ 
		if ($("#tooltip").hasClass("shown"))
		{
			$("#tooltip")
			.css("left", ($("a.tooltip_link").position().left+97)+"px")
			//.css("top", ($("a.tooltip_link").offset().top-25)+"px")
			.stop(true, true).fadeOut(300);
			$("#tooltip").removeClass("shown");
		}
		else {
			$("#tooltip").addClass("shown");
			$("#tooltip")
			.css("left", ($("a.tooltip_link").position().left+97)+"px")
			//.css("top", ($("a.tooltip_link").offset().top-25)+"px")
			.stop(true, true).fadeIn(300);
		}
		return false;
	})
	
	/** MY REWARDS **/
	$("#tab_wrapper a").click(function(){
		$("#tab_wrapper a").removeClass("current");
		$(this).addClass("current");
		$("#tabscontent_wrapper .tabcontent").removeClass("opened");  
		$("#" + $(this).attr("id") + "_content").addClass("opened"); 
		return false;
	})	
	$(".actions_cell a.check").click(function(){
		if ($(this).hasClass("check_on")) {
			$(this).removeClass("check_on");
		} else {
			$(this).addClass("check_on");
		}
		return false;
	})
	$(".delete_cell a.delete").live('click', function(){
		$(this).closest("div.wrapper").fadeOut(400, function(){
			$(this).remove(); 
		}); 
		return false;
	})
	
	function getDocumentHeight()
	{
		if($.browser.msie)
		{
			var $temp = $("<div>")
				.css("position","absolute")
				.css("left","-10000px")
				.append($("body").html());
			 
				$("body").append($temp);
				var h = $temp.height();
				$temp.remove();
				return h;
			}
		return $("body").height();
	}
	
	
	/** POPUP **/
	$("#popup_wrapper").hide().css("position", "absolute");
	$("a.see_details").click(function(){ 
		var hscroll = $(document).scrollTop(); 
		var h = getDocumentHeight();

		var userAgent = navigator.userAgent.toLowerCase();  
		$.browser.chrome = navigator.userAgent.toLowerCase().indexOf('safari'); 
		$.browser.mozilla = navigator.userAgent.toLowerCase().indexOf('mozilla'); 
		$.browser.msie = navigator.userAgent.toLowerCase().indexOf('msie');   

		if ( ($.browser.chrome > -1 || $.browser.mozilla > -1) && $.browser.msie == -1) {
			h += 41;
		}
		$("<div id='overlay' />")
				.css("opacity", .5) 
				.css("height",h+"px")
				.appendTo($("body"))
				.fadeIn(100, function(){ 
					$("#popup_wrapper")
						.css("top", hscroll) 
						.fadeIn(300, function(){
						$(this).animate({
							"top": hscroll
						}, 300, function(){ 							
						})
					});
					$("a.close_button").unbind("click").click(function(){
						$("#popup_wrapper").fadeOut(500, function(){
							$("#overlay").fadeOut(200, function(){
								$(this).remove(); 							
							});				
						});
						return false;
					})
		}); 
		return false;
	})
        $("a.click_register").click(function(){ 
		var hscroll = $(document).scrollTop(); 
		var h = getDocumentHeight();

		var userAgent = navigator.userAgent.toLowerCase();  
		$.browser.chrome = navigator.userAgent.toLowerCase().indexOf('safari'); 
		$.browser.mozilla = navigator.userAgent.toLowerCase().indexOf('mozilla'); 
		$.browser.msie = navigator.userAgent.toLowerCase().indexOf('msie');   

		if ( ($.browser.chrome > -1 || $.browser.mozilla > -1) && $.browser.msie == -1) {
			h += 41;
		}
		$("<div id='overlay' />")
				.css("opacity", .5) 
				.css("height",h+"px")
				.appendTo($("body"))
				.fadeIn(100, function(){ 
					$("#register_popup_wrapper")
						.css("top", hscroll) 
						.fadeIn(300, function(){
						$(this).animate({
							"top": hscroll
						}, 300, function(){ 							
						})
					});
					$("a.register_close_button_alt").unbind("click").click(function(){
						$("#register_popup_wrapper").fadeOut(500, function(){
							$("#overlay").fadeOut(200, function(){
								$(this).remove(); 							
							});				
						});
						return false;
					})
		}); 
		return false;
	})
	$("a.click_login").click(function(){ 
		var hscroll = $(document).scrollTop(); 
		var h = getDocumentHeight();

		var userAgent = navigator.userAgent.toLowerCase();  
		$.browser.chrome = navigator.userAgent.toLowerCase().indexOf('safari'); 
		$.browser.mozilla = navigator.userAgent.toLowerCase().indexOf('mozilla'); 
		$.browser.msie = navigator.userAgent.toLowerCase().indexOf('msie');   

		if ( ($.browser.chrome > -1 || $.browser.mozilla > -1) && $.browser.msie == -1) {
			h += 41;
		}
		$("<div id='overlay' />")
				.css("opacity", .5) 
				.css("height",h+"px")
				.appendTo($("body"))
				.fadeIn(100, function(){ 
					$("#login_popup_wrapper")
						.css("top", hscroll) 
						.fadeIn(300, function(){
						$(this).animate({
							"top": hscroll
						}, 300, function(){ 									$("#user").focus();
						})
					});
					$("a.login_close_button").unbind("click").click(function(){
						$("#login_popup_wrapper").fadeOut(500, function(){
							$("#overlay").fadeOut(200, function(){
								$(this).remove(); 							
							});				
						});
						return false;
					})
					$("a.login_close_button_alt").click(function(){
						$("#login_popup_wrapper").fadeOut(500, function(){
							$("#overlay").fadeOut(200, function(){
								$(this).remove(); 							
							});				
						});
						return false;
					})
		}); 
		return false;
	})
	/** MY SETTINGS **/
	$("#fname").val("First Name");
	$("#fname").focus(function(){
		if ($(this).val() == "First Name") {
			$(this).val("");
		}
	})
	$("#fname").blur(function(){
		if ($(this).val() == "") {
			$(this).val("First Name");
		}
	})
	$("#lname").val("Last Name");
	$("#lname").focus(function(){
		if ($(this).val() == "Last Name") {
			$(this).val("");
		}
	})
	$("#lname").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Last Name");
		}
	})
	$("#email").val("Email Address");
	$("#email").focus(function(){
		if ($(this).val() == "Email Address") {
			$(this).val("");
		}
	})
	$("#email").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Email Address");
		}
	})
	/***/
	$("#oldpass").val("Old Password");
	$("#oldpass").focus(function(){
		if ($(this).val() == "Old Password") {
			$(this).val("");
		}
	})
	$("#oldpass").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Old Password");
		}
	})
	/***/
	$("#newpass").val("New Password");
	$("#newpass").focus(function(){
		if ($(this).val() == "New Password") {
			$(this).val("");
		}
	})
	$("#newpass").blur(function(){
		if ($(this).val() == "") {
			$(this).val("New Password");
		}
	})
	/***/
	$("#rpass").val("Retype Password");
	$("#rpass").focus(function(){
		if ($(this).val() == "Retype Password") {
			$(this).val("");
		}
	})
	$("#rpass").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Retype Password");
		}
	})
	
	/** SUBMENU **/
	/*$("#right_menu_wrapper a").hover(function(e){
		$("#submenu").stop(true, true).fadeIn(200);
	}, function(e){ 
		$("#submenu").stop(true, true).fadeOut(200);
	})
	*/
	$("#right_menu_wrapper").hover(function(e){
		//$("#submenu").stop(true, true).fadeIn(200);
		$("#submenu").stop(true, true).fadeIn(200);
	},function(e){
		$("#submenu").stop(true, true).fadeOut(200);
	})
	
	
})

