
$(document).ready(function(){

	$('a[href$=pdf]').click(function() { 
		link = $(this).attr('href');
		_gaq.push(['_trackPageview', 'pdf/' + link]);
		//console.log('Logged: ' + link);
	});
	visible_home_id = "";

	$(window).resize(function() { 
		windowResizeBoxPosition(visible_home_id);
	});

	( $.cookie('tcookie') )? tchange( $.cookie('tcookie') ) : tchange( 'text0' );
	$('.tchange').click(function(){ tchange( $(this).attr('id') ); return false; });

	function windowResizeBoxPosition(visible_home_id) { 
		
		if(visible_home_id != ""){
			// reposition the visible box on the home page
			
			this_box = $('#' + visible_home_id).attr('id');
			position = $('#' + visible_home_id).position();
			height = $('#' + visible_home_id).height();
			
			//alert(this_box);
			bottom_corner = height + Math.round(position.top);
			left_corner = position.left;
			
			this_box = this_box.replace('box', 'spotlight');
			
			//alert(this_box);
			new_bottom_corner = ($(window).height() - bottom_corner) ;
			
			$('#' + this_box + '').css({ 
				'bottom': '' + new_bottom_corner + 'px',
				'left': '' + left_corner
				
			});
		
		}
	}

	$('.feedback_modal_form').jqm({
		"closeClass": "closeXjqm"
	});

	$(".feedback_link").click(function(){
		
		$('.feedback_modal_form').jqmShow();
		if($(this).attr('id') == 'feedback') { 
			$('#feedback_contact_text').html('Feedback');
			_gaq.push(['_trackPageview', '/js_click/feedback_form_show']);
			//console.log('Logged: /js_click/feedback_form_show');
		} else { 
			$('#feedback_contact_text').html('Contact Us');
			_gaq.push(['_trackPageview', '/js_click/contact_us_form_show']);
			//console.log('Logged: /js_click/contact_us_form_show');
		}
	});

	$('.close_home').click(function(){
			$(this).parent().fadeOut('fast');
	});
	
	$('#feedback_form').submit(function() { 
	var alert_text = "";
	var errors = 0;
		$("#feedback_form input").each(function() { 
		/*
		<label>First Name</Label> * : <input type="text" name="FirstName"  style="width: 220px"/><br/>
			<label>Last Name</Label> * : <input type="text"  name="LastName" style="width: 220px"/><br/>

			<label>Email Address</Label> * : <input type="text" name="EmailAddress" style="width: 200px" /><br/>
			<label>Phone Number</Label> : <input type="text" name="PhoneNumber"  style="width: 200px"/><br/>
			<label>Organization Name</Label> : <input type="text" name="OrgName"  style="width: 320px" /><br/>
			<label>Address</Label> : <input type="text" name="Address"  style="width: 380px"/><br/>

			<label>City</Label> : <input type="text" name="City" style="width: 160px" /> 
			<label>State</Label> : <input type="text" name="State"  style="width: 30px"/> 
			<label>Zip Code</Label> : <input type="text" name="ZipCode" style="width: 60px" /> <br/>
			<label>Enter our MHI's Zip Code</label> : <input type="text" name="humanConfirm" style="width: 60px" /> 
		*/
		
			if($(this).attr('name') == "FirstName" && $(this).attr('value') == "" ) { 
				alert_text = alert_text + "Please Enter a First Name\n";
				$(this).css('border-color', '#ff0000');
				errors ++;
			}
			if($(this).attr('name') == "LastName" && $(this).attr('value') == "" ) { 
				alert_text = alert_text + "Please Enter a Last Name\n";
				$(this).css('border-color', '#ff0000');
				errors ++;
			}
			if($(this).attr('name') == "EmailAddress" && $(this).attr('value') == "" ) { 
				alert_text = alert_text + "Please Enter a Email Address\n";
				$(this).css('border-color', '#ff0000');
				errors ++;
			}
			if($(this).attr('name') == "humanConfirm" && $(this).attr('value') == "" ) { 
				alert_text = alert_text + "You must confirm you are a human\n";
				$(this).css('border-color', '#ff0000');
				errors ++;
			}
			
			
			
		});
	if(errors) { 
		alert(alert_text);
		return false;
	} else { 
		return true;
	}	 
	});
	
	
	$('.three_item_home_box').click(function(){
	
	
		
		this_box = $(this).attr('id');
		position = $(this).position();
		height = $(this).height();
		_gaq.push(['_trackPageview', '/js_click/home_page_item_show/' + this_box]);
		//console.log('Logged: /js_click/home_page_item_show/' + this_box);
		
		bottom_corner = height + Math.round(position.top);
		left_corner = position.left;
		
		this_box = this_box.replace('box', 'spotlight');
		
		$('.spotlight').each(function(){
			$(this).fadeOut('fast');
		});
		new_bottom_corner = ($(window).height() - bottom_corner - 2) ;
		
		

		
		$('#' + this_box + '').css({ 
			'bottom': '' + new_bottom_corner + 'px',
			'left': '' + left_corner
		});
		$('#' + this_box +	'').fadeIn('fast');
		visible_home_id = $(this).attr('id');
		
		
	});
	
	
	
	$('.nav_container a').each(function() { 
		if($(this).attr('class') != "selected") { 
			$(this).hover(function() { 	
				toggler = "arrow_" + $(this).attr("id");
				$(this).css('opacity', '0.8');
			}, function() {
				toggler = "arrow_" + $(this).attr("id");
				$(this).css('opacity', '1.0');
			});
		}
	});



	$('.search_box').focus(function() { 
		
		$(this).css('color', '#333');
		
		if( $(this).val() == 'Search' ){
			$(this).val('');
		}

	}).blur(function() { 
				
		if( $(this).val() == '' ){
			$(this).val('Search');
			$(this).css('color', '#D8CFC7');
		}

	});

	
	$('.about_subnav .about_subnav_item').each(function() { 
		
		if( !$(this).hasClass('selected_subpage') ){
			
			$(this).hover(function() { 
				// over
				$(this).addClass('grey');
				$(this).find("a").prepend("+ ");
				
			}, function() { 
				// out
				replace_text = $(this).find("a").html();
				replace_text = replace_text.replace("+ ", "");
				$(this).find("a").html(replace_text);
				$(this).removeClass('grey');
			});
			
		}
	});
	
});


function tchange(t){
	switch(t){ 
		case 'text0' 	: $('body').css('font-size', '62.5%');break;
		case 'text1' 	: $('body').css('font-size', '65%');break;  
		case 'text2' 	: $('body').css('font-size', '67.5%');break;  
	}
	$('.tchange').removeClass('tchange_selected'); 
	$('#'+t+'').addClass('tchange_selected'); 
	$.cookie('tcookie', ''+t+'');
}
