function testSecure() {
	arrow_off = location.protocol + "//img.sparknotes.com/images/icon_arrow_off.gif";
	arrow_on = location.protocol + "//img.sparknotes.com/images/icon_arrow_on.gif";
	arrow_black = location.protocol + "//img.sparknotes.com/images/icon_arrow_black.gif";
	arrow_white = location.protocol + "//img.sparknotes.com/images/icon_arrow_white.gif";
}
function hideTopMenu() {
	jQuery("div.top_menu_sub").slideUp(100);
}

function hideMainMenu() {
	jQuery("div.menu_sub").slideUp(100);
	jQuery("img.menu_arrow").attr("src", arrow_off);
	unHideTopAd();
}

jQuery(document).ready(function() {
	testSecure();
	jQuery("#BlogModuleContainer").tabs(); /* Blog Module Tabs */
	jQuery("#BlogModuleCenterContainer").tabs({ selected: Math.floor(Math.random()*3) }); /* Home page Module Tabs */
	jQuery("#AllBlogsContainer").tabs(); /* All Blogs Module Tabs */
	jQuery("#BlogModuleContainer").tabs(); /* Blog Module Tabs */
    if(typeof tabIndex !== 'undefined')
    {
	    jQuery("#BlogModuleContainerMostCommented").tabs({ selected: tabIndex }); /* Most Commented Blog Module Tabs */
    }
	jQuery("#FaqModuleContainer").tabs(); /* FAQs Module Tabs */
	jQuery("#QuizModuleContainer").tabs(); /* Quiz Module Tabs */
	jQuery("#CollegeAdvisorContainer").tabs();
	jQuery("#TestPrepModuleContainer").tabs();
	fixAds();
	
	jQuery("li.menu_head,div.menu_sub").mouseleave(
		function() {
			hideMainMenu();
		}
	);

	jQuery("#container_topBar").mouseleave(
		function() {
			hideTopMenu();
		}
	);

	jQuery("img.menu_arrow").hover(
		function() {
			jQuery(this).attr("src", arrow_on);
		},
		function() {
		    selectedSubmenu = jQuery(this).parent().parent().find("div.menu_sub");
			if(selectedSubmenu.is(":hidden")) {
		        jQuery(this).attr("src", arrow_off);
			}
		}
	);

	jQuery("a.topNavTab").hover(
		function() {			
			jQuery(this).find("img.top_menu_arrow").attr("src", arrow_black);
		},
		function() {
			jQuery(this).find("img.top_menu_arrow").attr("src", arrow_white);
		}
	);

	jQuery("img.menu_arrow").click(
		function() {
			selectedSubmenu = jQuery(this).parent().parent().find("div.menu_sub");
			if(selectedSubmenu.is(":hidden")) {
				selectedSubmenu.slideDown(100);
				jQuery(this).attr("src", arrow_on);
			} else {
				selectedSubmenu.slideUp(100);					
				jQuery(this).attr("src", arrow_off);

			}
			jQuery("div.menu_sub").not(selectedSubmenu).slideUp(100);
			jQuery("img.menu_arrow").not(jQuery(this)).attr("src", arrow_off);
			hideTopMenu();
			hideTopAd(); //so flash wont stomp on menu
			return false;
		}		
	);

	jQuery("li.top_menu_head").click(
		function() {
			selectedSubmenu = jQuery(this).find("div.top_menu_sub");
			if(selectedSubmenu.is(":hidden")) {
				selectedSubmenu.slideDown(100);
			} else {
				selectedSubmenu.slideUp(100);					
			}
			jQuery("div.top_menu_sub").not(selectedSubmenu).slideUp(100);				
			hideMainMenu();
			return true;
    }); 

	jQuery("input.search_field").focus(function () {
		jQuery("div.searchbg").css({ "background" : "url(http://img.sparknotes.com/images/search_box_on.gif) no-repeat 0 0" });
   	});
	
	jQuery("input.search_field").blur(function () {
	    if(jQuery("input.search_field").attr("value") == "") {
			jQuery("div.searchbg").css({ "background" : "url(http://img.sparknotes.com/images/search_box_off.gif) no-repeat 0 0" });
		}			
	});
	
	jQuery("input.search_field2").focus(function () {
    	if(jQuery("input.search_field2").attr("value") == "Search SparkLife") {
			jQuery("input.search_field2").attr("value", "");
		}			
   	});
	
	jQuery("input.search_field2").blur(function () {
	    if(jQuery("input.search_field2").attr("value") == "") {
			jQuery("input.search_field2").attr("value", "Search SparkLife");
		}			
	});
});

function hideTopAd()
{
	jQuery("div.adTarget").css({'z-index' : '0'});
}

function unHideTopAd()
{
	//jQuery("div.adTarget").css({'z-index' : '1000'}); we don't need to be nice to them cuz they aren't nice to us. dont give back z-index
}

function fixAds()
{
	//adds a class to rude ad units so we can easily grab them
	var containers = jQuery("#topAd div");
	for(i=0;i<containers.length;i++)
	{
		target = jQuery(containers[i]);
		if(target.css('z-index') > 6000)
		{
			target.addClass("adTarget");
		}
	}
	hideTopAd(); //revoke z-index right away.
}

