// various functions executed on page load


// custom fade toggle (IE6 specific)
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

$(document).ready(function(){
    
    // inititate menu
    $("ul.sf-menu").superfish({
        delay: 200,
        autoArrows: false,
        disableHI: false
    });
    
    // open the login panel
    $('#login_closed p.login a').click(function() {
        $('#login_open').slideDown('fast');
        return false;
    });
    // close the login panel
    $('#login_open .close a').click(function() {
        $('#login_open').slideUp('fast');
        return false;
    });
    
    if ($.browser.msie && $.browser.version == 6){
         // show hide the small retrieve a quote form
        $('a#retrieve_toggle').click(function() {
            $('div.closed').toggleClass('opened');
            $('.raq_control').fadeToggle('fast');
            return false;
        });
    } else { 
        // show hide the small retrieve a quote form
        $('a#retrieve_toggle').click(function() {
            $('div.closed').toggleClass('opened');
            $('.raq_control').slideToggle('fast');
            return false;
        });
    }
    
    // fix for IE6 hover issues
    $('ul .hover').hover(function() {
      $(this).prevAll('a').addClass('activate');
    }, function() {
      $(this).prevAll('a').removeClass('activate');
    });
    
    // page menu hovers and arrows
    $('#page_menu_list > li').hover(function() {
      $(this).addClass('arrow');
    }, function() {
      $(this).removeClass('arrow');
    });
    
    // main menu hovers
    $('.submenu').hover(function() {
      $(this).prevAll('a').addClass('override_current');
    }, function() {
      $(this).prevAll('a').removeClass('override_current');
    });
    
    $('.subform').hover(function() {
      $(this).prevAll('a').addClass('override_current');
    }, function() {
      $(this).prevAll('a').removeClass('override_current');
    });
    
    /* --- DELTE THIS COMMENT TO COLLAPSE CATEGORIES ON ARTICLE INDEX PAGE
    // article index section toggle
    // on load, hide category lists 
    $('.container-category dl').hide();
    $('.container-category .opened').hide();
    // toggle controls
    $('.container-category .section-name a').toggle(function() {
    	// switch the caret image
    	//$(this).find('img.').attr('src','images/article-index-caret-open.png');
  		$(this).find('img.closed').hide();
  		$(this).find('img.opened').show();
  		// show the category list
  		$(this).closest('div').next('dl').show();
	}, function() {
  		// switch the caret image
    	//$(this).find('img').attr('src','images/article-index-caret-closed.png');
  		$(this).find('img.closed').show();
  		$(this).find('img.opened').hide();
  		// hide the category list
  		$(this).closest('div').next('dl').hide();
	});
	*/
	// state listing section toggle
   	// on load, hide list columns 
    $('div.column').hide();
    // toggle controls
    $('.toggle-link a').toggle(function() {
  		$('div.column').show();
	}, function() {
  		$('div.column').hide();
	});
	
});
