$(document).ready(function(){




	fl_top = $("#head").outerHeight(true) + $("#shoulders").outerHeight(true);
	fl_bottom = $("#knees").outerHeight(true) + $("#toes").outerHeight(true);
	fl_reset();
	$("#knees,#toes").show();
	$(window).resize(function(){
		fl_reset();
	});




	var poll_options = {
		target : '#kdm-poll',
		beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
	};

	// bind to the form's submit event 
	$('FORM.kdm-poll').ajaxForm(poll_options);
	$('INPUT.kdm-poll').click(function(){
		$(this.form).ajaxSubmit(poll_options);
	});








	if($.cookie('textresize_diff')!=null){
		textresize_diff = parseInt($.cookie('textresize_diff'));
	}

	$(".text-size IMG").each(function(){
		 //alert($(this).attr("class"));
		//sizevar = 0;
		 switch($(this).attr("class")){
		 
			case "min":
				$(this).attr("fsize",0);
				break;
			
			case "med":
				$(this).attr("fsize",2);
				break;
			
			case "max":
				$(this).attr("fsize",4);
				break;
			
		 }
		$(this).click(function(){
			resizeText(parseInt($(this).attr("fsize")));
			return false;
		});
	});
	initText(textresize_diff);




});


var fl_top, fl_bottom;
function fl_reset(){
	$("#body").css("min-height", $(window).height() - (fl_top + fl_bottom));
}




// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    /*
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
        */
} 







/*
--------------------------------------------------------
	TEXT RESIZE
--------------------------------------------------------
*/
var textresize_tags = "#body-center H1, #body-center H2, #body-center H3, #body-center H4, #body-center H5, #body-center P, #body-center A, #body-center LI";
var textresize_diff = 0;


function resizeText(value){
	//textresize_diff = value; //value<textresize_min?textresize_min:value>textresize_max?textresize_max:value;
	$.cookie('textresize_diff',value, {path:'/'});
	$(textresize_tags).each(function(i){
		var size = parseInt($(this).attr("originalSize"));
		//alert(value);
		size += value;
		$(this).css("fontSize",size);
	});
}
function initText(value){
	$(textresize_tags).each(function(i){
		$(this).attr("originalSize",parseInt($(this).css("fontSize")));
		//alert(this.tagName + ": " + parseInt($(this).css("fontSize")));
	});
	if(value!=0){
		resizeText(value);
	}
}

