window.addEvent("domready", function() {
  loginBox();
  
  faqs();
});

function loginBox() {
  $("login-link").addEvent("click", function(e) {
    e.stop();
    
    if ($("sign-in-form").getStyle("display") == "none" && $("forgot-password-form").getStyle("display") == "none") {
      $("sign-in-form").setStyle("display", "block");      
      initOverText();
    } else {
      $("sign-in-form").setStyle("display", "none");      
      $("forgot-password-form").setStyle("display", "none");
    }
  });
  
  $("sign-in-forgot-password").addEvent("click", function(e) {
    e.stop();
    
    $("sign-in-form").setStyle("display", "none");
    $("forgot-password-form").setStyle("display", "block");
  });	
  
  checkLoggedIn();
}

function checkLoggedIn() {
  new Request.JSON({
    url: "http://curationstation.com/front/is_logged_in",
    onSuccess: function(r) {
      if (r.logged_in == "1") {
        $("login").set("html", "Welcome, "+r.first_name+"&nbsp;|&nbsp;<a href='/dashboard'>Go to Dashboard</a>");
      }
    }
  }).send();
}

function initOverText() {
  new OverText($("sign-in-email"), {
    poll:true, 
    textOverride:"email address",
    positionOptions: {
      offset: {
        x: 6,
        y: 4
      }
    },
    onTextHide:function(ot, el) {
      el.addClass("focus");
    },
    onTextShow:function(ot, el) {
      el.removeClass("focus");
    }
  });
  new OverText($("sign-in-password"), {
    poll:true, 
    textOverride:"password",
    positionOptions: {
      offset: {
        x: 6,
        y: 4
      }
    },
    onTextHide:function(ot, el) {
      el.addClass("focus");
    },
    onTextShow:function(ot, el) {
      el.removeClass("focus");
    }
  });
}

function faqs() {
  if (!$('answers')) return;
  
	var faqs = new Accordion($('post-expand'), 'h4.question', 'div.content-expand',{
		alwaysHide: true,																
		opacity: false,
		display: -1,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#84e00d');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#666');
		}
	});
}