// Google Analytics
// --------------------------------
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-21898455-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();



// Begin jQuery scripts
// --------------------------------
$(document).ready(function() { 

	// Tour Buttons
	// -------------------------------
	$('.TourNext').click(function() {
		$(this).fadeOut("fast");
	    $(this).parents(".Tour").animate({
	        left: '-50%'
	    }, 500);
	
	    $(this).parents(".Tour").next().animate({
	        left: '50%'
	    }, 500);
	});


	$('.TourPrev').click(function() {
	    $(this).parents(".Tour").animate({
	        left: '150%'
	    }, 500);
	
	    $(this).parents(".Tour").prev().animate({
	        left: '50%'
	    }, 500);
	});


	// Post Cancel Back
	// -------------------------------
	$("a.PostButton").click(function(){
        $(window.location).attr('href', '/game/posts/');
        return false;
    });
    
    // Goals Cancel Back
	// -------------------------------
	$("a#CancelGoals").click(function(){
        $(window.location).attr('href', '/game/games/');
        return false;
    });
	
	
	// Optional message for form fields
    // --------------------------------
    $(".OptionalInput").each(function() {
        $(this).val($(this).attr("title"));
        $(this).css({ color: "#999999" });
    });

    $(".OptionalInput").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).css({ color: "#666666" });
        }

    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
            $(this).css({ color: "#999999" });
        }
    });


	// Account Hover Effect
    // --------------------------------
	var AccountHide = false; 
    
     $("#Account, #AccountOn").hover(function(){ 
         if (AccountHide) clearTimeout(AccountHide); 
         $("#AccountOn").fadeIn("fast"); 
     }, function() { 
         AccountHide = setTimeout(function() { 
             $("#AccountOn").delay(500).fadeOut("fast").stop(); 
         }, 250); 
     });
     
     
	// Help Message Close Transition
    // --------------------------------
	$("#HelpMessageContainer .Button").click(function() {
		$("#HelpMessageContainer").fadeTo("fast", 0.00, function(){ //fade
			$(this).slideUp("slow", function() { //slide up
				$(this).remove(); //then remove from the DOM
        	});
    	});
	});    
    
     
    // Dashboard Goal Picker
    // --------------------------------
    $(".DashGoal").click(function () {
		var $checkbox = $(this).find(":checkbox");
       	$checkbox.attr("checked", !$checkbox[0].checked);
       	
       	if ( $checkbox.is(":checked") ) {
       		$(this).children(".Goal").addClass("Active");
       	} else {
       		$(this).children(".Goal").removeClass("Active");
       	}
       	
    });
        
    $(".DashGoal input").click(function (e) {
	    e.stopPropagation();
	    $(this).parent().toggleClass("Active");
	    return true;
	});
    
    
    // Dashboard Comments
    // --------------------------------
    $(".DashComments").click(function () {
	    $("#CommentsArrow").fadeToggle("slow");
		$("#CommentsContainer").fadeToggle("slow");
	});
	
	// Dashboard Comments Reply
    // --------------------------------
	$("#DashActivity .Reply").click(function () {
		$(this).parent().nextAll(".CommentReply:first").fadeToggle("fast");
	});
	
	
	// Social Invite Picker
    // --------------------------------
	$(".SocialInvite").click(function () {
		var $checkbox = $(this).find(":checkbox");
       	$checkbox.attr("checked", !$checkbox[0].checked);
       	
       	if ($checkbox.attr("checked") == true ) {
       		$(this).addClass("Active");
       	} else {
       		$(this).removeClass("Active");
       	}
    });
    //-- 
    
});
