//$(document).ready(function(){
  //$('.form-item-pass .description').append('.password-strength');
//});

(function ($) {
  
  $(document).ready(function(){
  
    $('.node-form #edit-submit').add('.comment-form #edit-submit').click(function(){
      $(this).after('<span>Submitting...</span>');
      $(this).hide();
    });
    
    $('.field-name-og-node-link a').text('Start a discussion thread');
     
    $('a#most-recent-comment').click(function(){
      count = $(this).attr('commentcount');
      cid = $(this).attr('cid');
      if(count<=50) {
        $('html, body').animate({ scrollTop: $(".comment:last").offset().top}, 2000);
      } else {
        lastpage = $('.pane-node-comments li.pager-last a').attr('href');
        window.location = lastpage + '#comment-' + cid;
      }
      return false;
      
    });
    
    
     
    $('.header-search-wrapper #edit-section-keys').click(function(){
      $(this).val('');
      $(this).css({'color':'#222', 'font-style': 'normal'});
    });

    $('.custom_login a').click(function(){
      if($('.custom_popup_login').length>0) {
        $('.custom_popup_login').remove(); 
        $('.custom_login').removeClass('custom_active');     
      } else {
        $('.custom_login').addClass('custom_active');  
        popuphtml = '<div class="custom_popup custom_popup_login"><div class="tab"></div><div class="content"></div></div>';
        $('#main-menu').append(popuphtml);
      }
      put_this_here('/user/accountingwebuk_registration/loginform','.custom_popup_login .content');
      return false;   
    });
    
    $('a.account-drop-down').click(function() {
      if($('.custom_popup').length>0) {
        $('.custom_popup').remove(); 
        $('.account-drop-down').removeClass('drop-down-active');     
      } else {
        $('.account-drop-down').addClass('drop-down-active');  
        popuphtml = '<div class="custom_popup custom_popup_account"><div class="content"></div></div>';
        $('.user-cp').append(popuphtml);
      }
      put_this_here('/user/accountingwebuk_registration/myaccount','.custom_popup_account .content');
      return false;   
    });
    
    function put_this_here(_this, here) {
      $(here).html('<div class="loading">Loading...</div>');
      
      jQuery.getJSON(_this, function(json) {
        $(here).html(json);
      });
    }

    
		/* any answers back button hack */
		
		if ($("#quicktabs-qt_aa_home").length > 0){
			
			lastTabClicked = 0;
			currentHash = 0;
			previousHash = 0;
			
			$('#quicktabs-qt_aa_home a.qt_ajax_tab').click(function(){
				var url = this.href;
				var query = new Array();
				queryAr = url.split('?');
				query = queryAr[1].split('#');
				tab = query[0].split('=');
				if (tab[1] != lastTabClicked){
					updateTabs(tab[1]);
				}
			});	
			
			updateTabs = function(tabNo){
				if (tabNo != lastTabClicked){
					lastTabClicked = tabNo;
					window.location.hash = tabNo;
					$('#quicktabs-qt_aa_home a.qt_ajax_tab').click(function(){
						var url = this.href;
						var query = new Array();
						queryAr = url.split('?');
						query = queryAr[1].split('#');
						tab = query[0].split('=');
						if (tab[1] != lastTabClicked){
							updateTabs(tab[1]);
						}
					});
				}
			}
			
			checker = setInterval("checkHash()",200);	
			
			checkHash = function(){
				currentHash = Number(window.location.hash.replace('#',''));
				if (!$('#quicktabs-qt_aa_home ul li:nth-child(' + (currentHash+1) + ')').hasClass('active') && previousHash != currentHash){
					$('#quicktabs-qt_aa_home ul li:nth-child(' + (currentHash+1) + ') a').click();
					previousHash = currentHash;
				}	
			};
			
		}
		
		/* / qt hack */
		
  });
  
})(jQuery);;

