// JavaScript Document

var DoDropMenu;

// http://code.google.com/apis/ajaxlibs/documentation/
google.load("jquery", "1.3");
google.load("jqueryui", "1.7");

google.setOnLoadCallback(function(){
	
	// PNG Fix
	$.getScript('/bobrobb/wp-content/themes/bushnell2009/js/supersleight.plugin.js',function(){
		$('#logo, #buttonLogo').supersleight();
	});


	// Region Drop Menu
	$('.changeRegion').mouseenter(function(){
		$('.regions').show(); //.slideDown('fast');
	});
	$('.changeRegionLi').mouseleave(function(){
		$('.regions').hide(); //.slideUp('fast');
	});
	
	// mainNav sub menus
	$('#mainNav ul.subnav').each(function(){
		var me = $(this);
		var parent_subnavs = me.parents('ul.subnav');
		var parent_li = $(me.parents('li').get(0));
		var widest_li = null;
		parent_li.mouseenter(function(){
			var me = $(this);
			me.children('ul.subnav').show(); //.show('fast');
		});
		parent_li.mouseleave(function(){
			var me = $(this);
			me.children('ul.subnav').hide(); //.hide('fast');
		});
		// draw all parent subnavs so widths can be determined
		parent_subnavs.show();
		me.show();
		me.children('li').each(function(){
			var me = $(this);
			if (widest_li==null || me.width()>widest_li.width()) {
				widest_li = me;
			}
		});
		// make all LIs the same width
		//widest_li.siblings('li').width(widest_li.width());
		/* IE 6 doesn't expand a tag on secondary subnav? so do this instead */
		widest_li.children('a').width(widest_li.width()-24);
		widest_li.siblings('li').each(function(){
			var me = $(this);
			me.width(widest_li.width());
			me.children('a').width(widest_li.width()-24);
		});
		/* end work around for dumb IE 6 */
		widest_li = null;
		// cascade secondary subnav to the right
		if (parent_subnavs.length) {
			me.css('right','auto');
			me.css('top',0);
			me.css('left',parent_li.width());
		}
		me.hide();
		parent_subnavs.hide();
	});
	
	$('a.leftNavAtag').next('ul').each(function(){
		var me = $(this);
		var parent = me.prev('a');
		var active_li = me.find('li.active');
		if (active_li.length) {
			parent.addClass('open');
		} else {
			parent.addClass('closed');
		}
	});
	$('a.leftNavAtag').click(function(eventObject){
		var me = $(this);
		var ul = me.next('ul');
		if (ul.length) {
			if (ul.is(':visible')) {
				ul.slideUp('fast');
				me.removeClass('open');
				me.addClass('closed');
			} else {
				ul.slideDown('fast');
				me.removeClass('closed');
				me.addClass('open');
			}
			return false;
		}
	});

});
