//simple search, advanced search and search results functions

$(document).ready(function(){

	//jq tooltips  --  commented out because it's crashing IE7 on results page.

	$(".searchpage a.tooltip,.searchresults a.tooltip,a.tooltip").Tooltip({track: true, showURL: false});
	$("a.tooltip").click(function () {		return false;	})//turn off clicking through if JS in enabled.
	//$("#donor_results th a").Tooltip({track: true, showURL: false});
	//$("#printresults").Tooltip({track: true, showURL: false});
	if (typeof document.body.style.maxHeight == 'undefined')  { // implement iframe tooltip fix in ie6 only
		$("#tooltip").bgiframe();
	}
	
	// donor page - mimic table striping on dls.
	$("#profile .infolisting dt:even, #profile .infolisting dd:even").addClass("evenrow");
	$("#profile .infolisting dt:even")
	.each(function(){
		var current = $(this);
		if(current.height() < current.next("dd").height()) current.height(current.next("dd").height());
	});





	// print function
	// (disabled by kf: using a url param to allow page expansion...)
	//$("#printresults").click(function () 	{window.print();}  	);

	//stripe donor results tables by adding a class to each even row
	//$("#donor_results tr:even, .data_chunk tr:even").addClass("evenrow");
	$("#donor_results, .data_chunk, #donor-level").each(function(){
		$(this).find("tbody tr:odd").addClass("odd");
	});
	$(".donor-info").each(function(){
		$(this).find("tbody .odd").removeClass("odd");
		$(this).find("tbody tr:odd").addClass("odd");
	});

	//
	$("#donor-level .col, .level .col").each(function(){
		$(this).find("li:first").addClass("head");
		$(this).find("li:last").addClass("footer");
	});
	//
	$("#donor-level .col ul, .data_chunk .col ul").each(function(){
		$(this).find("li:odd").addClass("odd");
		$(this).find("li:last").addClass("last");
	});
	//
	$(".data_chunk ul.col ").each(function(){
		$(this).find("li:last").addClass("last");
	});
	
	$(".col ul").each(function(){
		$(this).find("li:last").removeClass("last");
	});
	
	
	// make the class stick when a 'must have' button is checked
	
	$("div.musthave label").click(function() {
	    $(this).toggleClass('musthavechecked');
	});


	$('.rotator').rotator();

	// show/hide save search form
	$("#ImAHiddenDiv").toggleClass('hide2');
	$("#savesearch a").click( function() { $("#ImAHiddenDiv").toggleClass('hide2'); return false; });

	// remove tabs
	//$('#tabwrap li a').unbind("click");

	//$(".simplesearch #savesearch").click( function() { $("#ImAHiddenDiv").toggleClass('hide2'); });/*This one is a label - need it to return true.*/


	//load form customizer
/*
	$(".customize a").click(function () {
	 	$(".customizewrap").load("#APPLICATION.webroot#/Donor-Search/Search-Results/settingsForm.cfm",
			function() {
				$(this).slideToggle();
   			}//load func
		);//load

		return false;
	});
*/


/*
	//load form customizer
 	$(".customizewrap").load("#APPLICATION.webroot#/Donor-Search/Search-Results/settingsForm.cfm");//load

	$('.customizewrap').jqm({
		//ajax: '#APPLICATION.webroot#/Donor-Search/Search-Results/settingsForm.cfm',
		overlay: 50,
	    overlayClass: 'modal_overlay'
		});
*/
});//doc ready



// very simple rotator

jQuery.fn.rotator = function(){
	var $rotator = $(this),
		$slides = $('.slide:not(#default)', this),
		$default = $('#default', this)
		showDefault = function(){if ($default.css('display') == 'none') $default.css('display', 'block');},
		hideSlides = function(){$($slides).css({'display' : 'none', 'z-index' : '1'}); setTimeout('showDefault()', 5);}
		timer = setTimeout('', 1);
		
	
	//initialize
	$slides.css('display', 'none');
	
	// bind behavior to subscription callouts
	// also, this is a mess b/c only mouseout appears to be available to this plugin.  making some concessions, sorry if this looks like it was built by angry monkeys.
	//$('.data_chunk .level.one').mouseover( function() { $default.css('display', 'none'); } );
	//$('#innercontent .inner').mouseover( function() {  setTimeout("showDefault", 100);  });
	
	$('.subscription-offer').each(function(){
		var $this = $(this);
		var identity = this.id;
		identity = (identity.match(/full-access/)) ? 2 : (identity.match(/essentials/)) ? 1 : 0;
		
		$this.hover( function(){ clearTimeout(timer); hideSlides(); $($slides[identity]).css({'display' : 'block', 'z-index' : '100'}); }, 
					 function(){ timer = setTimeout("hideSlides()", 100); } 
		);
	});
	

};

