$(document).ready(function(){
	$('li.has_children').hover(
		function() { $(this).children("ul").stop(true, true).fadeIn(); },
		function() { $(this).children("ul").stop(true, true).fadeOut(); }
	);
	$('div.primary_links ul li').hover(
		function() { $(this).addClass('menu_hover'); },
		function() { $(this).removeClass('menu_hover'); }
	);
	
	
	$("ul.submenuclass li:first-child").addClass('first');

	// Fix IE7 z-index bug
	
	$(function() {
		var zIndexNumber = 1000;
		$('div').each(function() {
			//Do not re-order the cover flow
			if($(this).attr('id') == 'divFlow' || 
				$(this).attr('id') == 'flowTitle' || 
				$(this).attr('class') == 'moveleft' || 
				$(this).attr('class') == 'moveright' || 
				$(this).attr('class') == 'item level3Left' || 
				$(this).attr('class') == 'item level2Left' || 
				$(this).attr('class') == 'item level1' || 
				$(this).attr('class') == 'item level2Right' || 
				$(this).attr('class') == 'item level3Right' ||
				$(this).attr('class') == 'item level4'
			){
				//Do nothing
			}else{
				$(this).css('zIndex', zIndexNumber);
				zIndexNumber -= 10;	
			}
		});
	});
	
	// Hack to work around an absolutely positioned content div, which itself was a hack
	// to work around an IE7 float bug
	var  is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
 	if (!is_chrome) {
  		var maxHeight = $("#sidebar1").height();
		if ($("#sidebar2").height() > maxHeight) maxHeight = $("#sidebar2").height();
		if ($("#mainContent").height() > maxHeight) maxHeight = $("#mainContent").height();
		$("#sidebar2").height(maxHeight);
	}
/*
	$("#sidebar1 h3").each(function(index) {
		$(this).addClass('expandable');
    	$(this).next('ul').hide();
    	$(this).click(
    		function() { 
    		    $(this).next('ul').slideToggle();
			}
    	);
  	});
*/	
	$("#search-box").focus(function(){
		if ($(this).val() == "search") {
			$(this).val("");
		}
	});
	$("#search-box").blur(function(){
		if ($(this).val() == "") {
			$(this).val("search");
		}
	});
	
	/*
	* Check for Chrome and alter the url of the rss to default to google reader
	*/
	if(navigator.userAgent.match('Chrome')){
		var theRssLink = $('#gs1Rss').find('a');
		if(theRssLink.length > 0){
			var feedUrl = 'http://www.google.com/reader/view/feed/';
			var rssSrc = theRssLink.attr('href');
			theRssLink.attr('href',feedUrl+rssSrc);
		}
	}
});

