/* ---------------------------------------------------------- */
/* Resize panel heights to match largest                      */
/* ---------------------------------------------------------- */
var resizeTimer = null;
$(document).ready(function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(doResize, 100);
});

$(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(doResize, 100);
});

var maxHeight = 0;  
  
function doResize() {
     setPanelHeights('#content .panels');
    
};

function setPanelHeights(row) {
	row = $(row);
	row.each(function(){
		$(this).addClass('temp');
		setPanelHeight('.temp .panel .header .content');  
		setPanelHeight('.temp .panel .body   .content');  
		setPanelHeight('.temp .panel .footer .content');
		$(this).removeClass('temp')
	});
}



function setPanelHeight(col) { 
	maxHeight = 0;
	
	col = $(col); 
	
	
	if (!($.browser.msie && $.browser.version == 6.0)) {
		col.css({'min-height': 0}); 	
		col.css({'height': 'auto'}); 	
	}
	 
	 
	 
	col.each(function() {          
		
		//alert($(this).height());
		
		if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }  
	});  
	
	
	if ($.browser.msie && $.browser.version == 6.0) { 
		col.css({'height': maxHeight}); 
		
		
	}
	col.css({'min-height': maxHeight}); 	
}

/* ---------------------------------------------------------- */
/* Navigation list handlers                                    */
/* ---------------------------------------------------------- */
$(document).ready(function() {
	var jumpURL = $("#navigation-list #navigationURL, #navigation-list #navigationDropdown, .searchform #navigationDropdown").selectedValues() + "?script=true";
	$("#navigation-list").attr("action", jumpURL);
	$("#navigation-list").attr("method", "post");
			
	$("#navigation-list #navigationURL, #navigation-list #navigationDropdown, .searchform #navigationDropdown").change(function() { 
		jumpURL = $(this).selectedValues() + "?script=true";
		if (jumpURL != '') {
			$("#navigation-list").attr("action", jumpURL);
		}
	});
			
	$("#navigation-list #navigationURL, #navigation-list #navigationDropdown, .searchform #navigationDropdown").dblclick(function() { 
		jumpURL = $(this).selectedValues() + "?script=true";
		if (jumpURL != '') {
			window.location.href = jumpURL;
		}
	});

	var jumpURL1 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_type_search_form&isFormSubmitted=true&cancertype=" + $("#cancertypeform #cancertype").selectedValues() + "&script=true";
	$("#cancertypeform").attr("action", jumpURL1);
	$("#cancertypeform").attr("method", "post");
			
	$("#cancertypeform #cancertype").change(function() { 
		jumpURL1 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_type_search_form&isFormSubmitted=true&cancertype=" + $(this).selectedValues() + "&script=true";
		if (jumpURL1 != '') {
			$("#cancertypeform").attr("action", jumpURL1);
		}
	});
			
	$("#cancertypeform #cancertype").dblclick(function() { 
		jumpURL1 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_type_search_form&isFormSubmitted=true&cancertype=" + $(this).selectedValues() + "&script=true";
		if (jumpURL1 != '') {
			window.location.href = jumpURL1;
		}
	});

	var jumpURL2 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_subject_search_form&isFormSubmitted=true&cancersubject=" + $("#cancersubjectform #cancersubject").selectedValues() + "&script=true";
	$("#cancersubjectform").attr("action", jumpURL2);
	$("#cancersubjectform").attr("method", "post");
			
	$("#cancersubjectform #cancersubject").change(function() { 
		jumpURL2 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_subject_search_form&isFormSubmitted=true&cancersubject=" + $(this).selectedValues() + "&script=true";
		if (jumpURL2 != '') {
			$("#cancersubjectform").attr("action", jumpURL2);
		}
	});
			
	$("#cancersubjectform #cancersubject").dblclick(function() { 
		jumpURL2 = "search-results/index.htm?AdvancedSearchFormType=qanda_cancer_subject_search_form&isFormSubmitted=true&cancersubject=" + $(this).selectedValues() + "&script=true";
		if (jumpURL2 != '') {
			window.location.href = jumpURL2;
		}
	});

});

/* ---------------------------------------------------------- */
/* Text resize utility                                        */
/* ---------------------------------------------------------- */
$(document).ready(function(){
	var COOKIE_NAME = "chtextsize";
	var COOKIE_OPTS = { path: '/', expires: 30 };
	var TEXT_SIZES = ['smaller', 'small', 'medium', 'large', 'larger'];
	var TEXT_MIN = 1; // Small
	var TEXT_MAX = TEXT_SIZES.length - 1; // Larger
	
	var text_size = 2;

	// Set initial size
	if ( $.cookie(COOKIE_NAME) ) {
		text_size = $.cookie(COOKIE_NAME);
		if ( text_size < TEXT_MIN || text_size > TEXT_MAX ) text_size = 2;
		$('body').addClass(TEXT_SIZES[text_size]);	
	} else {
		text_size = 2;
		$('body').addClass(TEXT_SIZES[text_size]);	
		$.cookie(COOKIE_NAME, text_size, COOKIE_OPTS);
	}
	
	// Increase font size
	$(".increasefont").click(function(){
		if (text_size < TEXT_MAX) {
			$('body').removeClass(TEXT_SIZES[text_size]);
			text_size++;
			$('body').addClass(TEXT_SIZES[text_size]);	
			$.cookie(COOKIE_NAME, text_size, COOKIE_OPTS);
			doResize();
			
			if ($.browser.msie && $.browser.version == 6.0) { 
			window.location.reload(true);
			}
		}
		
		return false;
	});
	
	// Decrease font size
	$(".decreasefont").click(function(){
		if (text_size > TEXT_MIN) {
			$('body').removeClass(TEXT_SIZES[text_size]);
			text_size--;
			$('body').addClass(TEXT_SIZES[text_size]);	
			$.cookie(COOKIE_NAME, text_size, COOKIE_OPTS);
			doResize();
			
			if ($.browser.msie && $.browser.version == 6.0) { 
			window.location.reload(true);
			}
		}
		return false;
	});

});

