// controls the submenus  
jQuery(function(){

	// we need the immediate descendant selector here
	// this will have to be changed if/when we implement submenus
	var MenuLIs = jQuery('#nav > ul > li');
	MenuLIs.bind('mouseenter', function(){
		var realTarget = jQuery(this);
		
		// fade in the child of the target
		realTarget.children('ul').fadeIn('fast');
		return false;
	})
	.bind('mouseleave', function(){
		var realTarget = jQuery(this);
		realTarget.children('ul').fadeOut('slow');
		return false;
	});
});

// controls the tertiary menus
jQuery(function(){

	// we need the immediate descendant selector here
	// this will have to be changed if/when we implement submenus
	var MenuLIs = jQuery('#nav > ul > li > ul > li');
		
	MenuLIs.bind('mouseenter', function(){
		var realTarget = jQuery(this);
		var ParentWidth = realTarget.outerWidth() + 2;

		// fade in the child of the target
		realTarget.children('ul').css('left', ParentWidth + 'px');
		realTarget.children('ul').fadeIn('fast');
		// return false;
	})
	.bind('mouseleave', function(){
		var realTarget = jQuery(this);
		realTarget.children('ul').fadeOut('slow');
		// return false;
	});
});


// controls the tabs for the bottom-right section of the home page
jQuery(function(){

	var Tabs = jQuery('.issueAndPoll_tab');

	Tabs.bind('click', function(){
		var clickedTab = jQuery(this);
		
		if( clickedTab.attr('id') == 'spotlight_tab' && jQuery('#survey_tab').hasClass('survey_active') ){
			jQuery('#spotlight_tab').addClass('spotlight_active');
			jQuery('#issuesAndPoll_arrow').css('background-position','top left');
			jQuery('#survey_tab').removeClass('survey_active');
			jQuery('#survey').hide();
			jQuery('#spotlight').show();
		} else if( clickedTab.attr('id') == 'survey_tab' && jQuery('#spotlight_tab').hasClass('spotlight_active') ){
			jQuery('#survey_tab').addClass('survey_active');
			jQuery('#issuesAndPoll_arrow').css('background-position','bottom right');
			jQuery('#spotlight_tab').removeClass('spotlight_active');
			jQuery('#spotlight').hide();
			jQuery('#survey').show();
		}
		return false;
	});
});

// check for links with addresses ouside of this domain
jQuery(function(){

	var anchors = jQuery('a');
	var base = jQuery('base').attr('href').match(/http\:\/\/([\w\.\-]+)/)[1];
	//console.log(base);
	
	anchors.each(function(){
		var thisLink = jQuery(this);
		var thisURL = thisLink.attr('href');
		if (thisURL.indexOf('http://') !== -1 && thisURL.indexOf(base) === -1) {
			// this will open the link in a new window/tab
			thisLink.attr('target', '_blank');
		}
		
	});

});



src="_images/home/spotlight_arrow.gif"
