var numSectionsToExpand = 1;
var resized = false;
//Cufon.replace('#top-nav');
(function($) {
	var wrapperHeight = 0;
	$(document).ready(function(){
		if (jQuery.cookie) {
			var isResized = $.cookie('resized');
			if (isResized == 'yes') {
				resized = true;
				resize();
			}
		}
		$(window).resize(function() {
			adjustFooter();
        });
		adjustFooter();
		setupContentSections();
		
		
//		$('a.terms-of-use').each(function() {
//			this.href += '?tid=3';
//		}).fancybox({
//			width: 590,
//			height: 460,
//			autoDimensions: false,
//			type: 'iframe',
//			padding: 60
//		});
		
		$(':text, textarea').example(function() {
			return $(this).attr('title');
		});
		$('.search-btn').click(function() {$(this).parents('form').submit();});
		$('#action-print').click(function() {window.print(); return false;});
		$('#action-resize').click(function() {
			if (resized) {
				$('.resized-10').removeClass('resized-11').css('font-size', '10px');
				$('.resized-11').removeClass('resized-11').css('font-size', '11px');
				$('.resized-12').removeClass('resized-11').css('font-size', '12px');
				if (jQuery.cookie) {
					$.cookie('resized', 'no');
				}
				resized = false;
			} else {
				resize();
			}
			return false;
		});
	});
	
	function resize() {
		resized = true;
		if (jQuery.cookie) {
			$.cookie('resized', 'yes');
		}
		$('*').each(function() {
			var e = $(this);
			var s = e.css('fontSize');
			if (s == '10px') {
				e.css('fontSize', '12px').addClass('resized-10');
			} else if (s == '11px') {
				e.css('fontSize', '13px').addClass('resized-11');
			} else if (s == '12px') {
				e.css('fontSize', '14px').addClass('resized-12');
			}
		});
	};
	
	function adjustFooter() {
		if($.browser.msie && (($.browser.version.substr(0,1) == "6") || ($.browser.version.substr(0,1) == "7"))){
			//return;
		}
		var height = parseInt($(window).height());
		var footerHeight = parseInt($('#footer').height());
		$('#wrapper').css('minHeight', height - footerHeight);		
	};
	
	function setupContentSections() {
		$('.section-heading').each(function(i) {
			var heading = $(this);
			var text = heading.html();
			heading.html('<div class="section-heading-sign"></div><div class="section-heading-text">' + text + '</div><div class="clear"></div>');
			var sign = $('div.section-heading-sign', heading);
			
			var content = heading.next();
			var status;
			if (i < numSectionsToExpand) {
				status = 'opened';
				sign.html('[&ndash;]');
			} else {
				status = 'closed';
				sign.html('[+]');
				content.hide();
			}
			heading.click(function() {
				if(status == 'closed'){
					$('#wrapper').height('auto');
				}
				content.slideToggle('fast', function() {
					if (status == 'opened') {
						sign.html('[+]');
						status = 'closed';
					} else {
						sign.html('[&ndash;]');
						status = 'opened';
					}
				});
			})
		});
	};
})(jQuery);