$('li#login').each(function(){
  var loginLi = $(this)
  var loginAnchor = loginLi.find('a:first');
  var loginTab = loginLi.find('#login-tab');
  
  loginAnchor.click(function(){
    if(loginTab.is(':hidden')){
      loginLi.addClass('active');
      loginTab.animate({opacity: 'show'}, 100);
    } else {
      loginLi.removeClass('active');
      loginTab.animate({opacity: 'hide'}, 100);
    }
    return false;
  });

  $('body').click(function(){
    loginLi.removeClass('active');
    if(navigator.appVersion.indexOf("MSIE 7.")!=-1){
      loginTab.hide();
    } else {
      loginTab.animate({opacity: 'hide'}, 100);
    }
  });
   
  loginTab.click(function(event){ if(!$(event.target).is('a')){ event.stopPropagation(); }  });
  
  $("li#login").delegate('a.forgot-pw', 'click', function() {
    $(this).parent().fadeOut(function(){ 
      $('#forgot-pw-form').fadeIn(); 
      $('#form-password').show(); 
      $('#error-messages, #success-message').hide();
    });
    return false;
  });

  $("li#login").delegate('a.back-to-login', 'click', function() {
    $(this).parent().fadeOut(function(){ 
      $('#login-form').fadeIn(); 
      $('#form-login').show();
      $('#error-messages, #success-message').hide();
    });
    return false;
  });

  $('#forms').delegate(":submit", "click", function(){
    $(this).before('<div id="loader"><img src="images/ajax-loader.gif" alt="Loading..." /></div>');
    //return false;
  });
});

//HOMEPAGE USER TYPES
$("#user-types li div").click(function(){
  if($(this).parent().is('.active')){
    return false
  } else {
    $("#user-types > li").removeClass('active');
    $(this).next().animate({height: 'show'}).parent().addClass('active');
  }
});

//ABOUT US (Team Tabs)

$('.team').each(function(i,el){
  var thisTabs = $(this);
  var tabContent = thisTabs.find('.tab-content').hide(); 
  var currentTabContent = $(".tab-content.active", this).show();
  var currentTab = $('ul#tabs li a[href=#'+currentTabContent.attr("id")+']').parent().addClass('active');
  $("ul#tabs li", thisTabs).click(function() {
    if($(this).hasClass('active')){
      return false;
    } else {
      $("ul#tabs li", thisTabs).removeClass("active"); 
    	$(this).addClass("active"); 
    	tabContent.hide();
    	var activeTab = $(this).find("a").attr("href"); 
    	$(activeTab).fadeIn();
    	return false;
    }
  });
});


//FAQ

$('#faq-list li a.question').click(function(){
  var li = $(this).parent().toggleClass('active');
  $(this).next('.answer').slideToggle();
  return false;
});
;
$('.plans table tbody tr:odd').addClass('even');


//DETECT HTML5 SUPPORT FOR PLACEHOLDER ATTRIBUTE AND JS IF NOT
placeholderSupport = ("placeholder" in document.createElement("input"));
if(!placeholderSupport){
  $('#login-fields li:first-child').after('<li><input type="text" value="" placeholder="Password" id="password-clear"/></li>')
  $('#password-clear').show();
  $('#zoomuser_password').hide();

  $('#password-clear').focus(function() {
      $('#password-clear').hide();
      $('#zoomuser_password').show().focus();
  });
  $('#zoomuser_password').blur(function() {
      if($('#zoomuser_password').val() == '') {
          $('#password-clear').show();
          $('#zoomuser_password').hide();
      }
  });
  
  var phvalue;
  $("input[type=text]").each(function(){
   phvalue = $(this).attr("placeholder");
   $(this).val(phvalue);
  });
  $("input#zoomuser_username, input#zoomuser_email").focusin(function(){
   phvalue = $(this).attr("placeholder");
   if (phvalue == $(this).val()) {
   $(this).val("");
   }
  });
  $("input#zoomuser_username, input#zoomuser_email").focusout(function(){
   phvalue = $(this).attr("placeholder");
   if ($(this).val() == "") {
     $(this).val(phvalue);
   }
  });
}

//CLIENTS SCROLLER

(function($) {
  $.fn.extend({
    clientSlider: function(options) {
      var defaults = {
        width : '875px',
        height  : '50px',
        slideWidth : '930px',
        slide : '.clients-list',
        prev : '.left-nav',
        next : '.right-nav'
      }
      var settings = $.extend(defaults, options);
      
      var slideWidth = parseInt(settings.slideWidth);
      
      return this.each(function() {
        var slider = $(this);
        var slidesCollection = slider.find(settings.slide);
        slidesCollection.wrapAll('<div class="slides-container"><div class="slides" /></div>');
        var totalSlidesWidth = 0;
        slidesCollection.each(function(index,value){ totalSlidesWidth += $(this).outerWidth(true); });
        var slidesContainer = slider.find('.slides-container').css({ 
          width : settings.width,
          height: settings.height,
          position: 'relative', 
          overflow: 'hidden'
        });
        var slides = slider.find('.slides').css({ 
          position: 'absolute',
          left : '0px',
          top : '0px',
          width : totalSlidesWidth
        });
        
        var leftAmt = 0;
        var next = slider.find('.right-nav');
        var prev = slider.find('.left-nav');
        
        next.click(function() {
          prev.removeClass('disabled');
          if(leftAmt <= (-(totalSlidesWidth - slideWidth))){
            $(this).addClass('disabled');
            return false;
          } else {
            leftAmt += -(parseInt(settings.slideWidth));
            slides.animate({left:leftAmt}, function(){ if(leftAmt === (-(totalSlidesWidth - slideWidth))){ next.addClass('disabled'); }});
          }
          return false;
        });
        prev.click(function() { 
          next.removeClass('disabled');
          if(leftAmt >= 0){
            return false;
          } else {
            leftAmt += parseInt(settings.slideWidth);
            slides.animate({left:leftAmt}, function(){ if(leftAmt === 0){ prev.addClass('disabled'); }});
          }
          return false;
        });
        
      });
    }
  });
})(jQuery);

$('.clients-scroller').clientSlider();
