$(document).ready(function() {
	$(".jk_main_menu li.jk_submenu").hover(
    function() {
      $(this).find("ul").show();
      $(this).children('a').addClass('selected');
    },
    function() {
      $(this).find("ul").hide();
      $(this).children('a').removeClass('selected');
    }
  );

  // Login form
  var textboxes = $('form#jk_login_form input');
  textboxes.each(function(index, input){
    var label = $(input).prev();
    // Check for autocomplete by browser
    if(index==0){
      setInterval(function(){
        textboxes.each(function(index,inputX){
          if($(inputX).val()!='' ) {
            $(inputX).prev().children('span').animate({opacity: 0},0);
          }
        });
      }, 100);
    }
    // Fade the label back when a field gains focus
    $(input).focus(function(){
      if($(input).val()==''){
        $(label).children('span').animate({opacity: '.5'},200);
      }
    });
    // Check if a field is empty when the user switches out
    $(input).blur(function(){
      if($(input).val()==''){
        $(label).children('span').animate({opacity: '1'},200);
      }
    });
    // Fade the label back if a field has text
    if($(input).val()!='') {
      $(label).addClass('hastext');
    }
    // Fade the label back when the user starts to type
    $(input).keypress(function(){
      $(label).children('span').animate({opacity: '0'},200);
    });
  });

  // Login
  $('#jk_login a').click(function(){
    $(this).toggleClass('selected');
    $('#jk_login_panel').toggle();
  });
});

