/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)written by Alen Grakalic (http://cssglobe.com) for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
 

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 50;
		yOffset = -50;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("medium");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
						   
		//Left Nav min height
		if($("#navSub").height()< 200){
			$("#navSub").css("height", "200px");
		}
						   
	//formerly asrm_nav.js
	// remove link background images since we're re-doing the hover interaction below 
		// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
		// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
	
	/*
		$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each nav item
		attachNavEvents(".nav", "home");
		attachNavEvents(".nav", "about");
		attachNavEvents(".nav", "news");
		attachNavEvents(".nav", "resources");
		attachNavEvents(".nav", "events");
		attachNavEvents(".nav", "topics");
		attachNavEvents(".nav", "membership");
		attachNavEvents(".nav", "myInfo");
	

		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}
		*/
	
//end asrm_nav.js

	$("ul.nav li").hover(function(){
		$(this).children("a").addClass("active");
		$(this).children("ul").css("display", "block");
	},function(){
		$(this).children("a").removeClass("active");
		$(this).children("ul").css("display", "none");		  
	});
						   
						   
	tooltip();
	$(".breadcrumbLink").css({"position" : "absolute", "margin-top": "3px"});
	$("table.toggle tr:last").addClass("last-tr");
	$("h5.toggle").click(function(){
		$(this).next("table.toggle").slideToggle();	
		$(this).toggleClass("toggle-active");
	});
	
	
	$("h5.toggle").each(function(){
		//ptr = $(this).prev("table.toggle").find("tr:last").attr("class");
		//alert(ptr);							 
	});
	/* Print Button function */
	$(".tools ul li").hover(function(){
		theID = "#"+ $(this).attr("id") + "Callout";
		//alert(theID);
		$(theID).css("visibility", "visible");
	},function(){
		$(theID).css("visibility", "hidden");
	});
	
	/*Expandable box */
	$(".switchMenuClosed").toggle(
		function(){
			toggleWhat = $(this).attr("rel");
			$("#"+toggleWhat).slideDown();
			$(this).addClass("switchOpened").text("Hide details");
		},
		function(){
			$("#"+toggleWhat).slideUp();
			$(this).removeClass("switchOpened").text("View details");
	});
	
	/* Search Text */
	
	swapValues = [];
    $("input.searchText-field").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });
	//formerly sprinkle.js
	$('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	
	//formerly embedded
	$("#miniNavs > ul").tabs();
	
	//View 4 view all
	$("div.view-all").toggle(function(){
		$(this).children("p").text("View Top 4");
		$(this).removeClass("view-all").addClass("view-four");	
		$(this).parent().children("div.view-all-content").slideDown();
	},function(){
		$(this).children("p").text("View All");
		$(this).removeClass("view-four").addClass("view-all");	
		$(this).parent().children("div.view-all-content").slideUp();
	});
	
	$("div.view-four").toggle(function(){
		$(this).children("p").text("View All");
		$(this).removeClass("view-four").addClass("view-all");	
		$(this).parent().children("div.view-all-content").slideUp();
	}, function(){
		$(this).children("p").text("View Top 4");
		$(this).removeClass("view-all").addClass("view-four");	
		$(this).parent().children("div.view-all-content").slideDown();
	});
	
	
	//IE6 fix
	$("div.more-info p:last").addClass("last-item");
	
	//Poll results
	$(".percent").each(function(){
		var percent = parseFloat($(this).text());
		var finishedSize = 432 * (percent/100);
		
		$(this).next().next().css("width", finishedSize);
	});

	$("input.archive-arrow").hover(function(){
		$(this).attr("src", "/images/icons/archive-arrow-hover.png");
	},function(){
		$(this).attr("src", "/images/icons/archive-arrow.png");											
	});

});