$(document).ready(function () {
	scale();		
	loadAndFadeImages();			
});


$(window).resize(function(){
  scale();
});

$(document).ready(function(){
  $.preloadCssImages();
});


	function scale(){
		 // upper_height = 650; 
		 document_height = $(window).height();
		 			document_height =  document_height - 71;
		 			remaining_document_height = document_height - 1200;
		 
		 			if (remaining_document_height > 0) {
		 				$('#upper').height(1200 + remaining_document_height);
		 			}
		 			else {
					if ( remaining_document_height < 0){
						if ( document_height > 650 ){
		 				$('#upper').height(document_height);                        
		 			}
						else {
							$('#upper').height(650);                        
			 				
						}
		}}
		}
		
		function	loadAndFadeImages() {
			var found_images = $("img").css('display','none');
			var image_parents = new Array();
			var counter = 0;
				jQuery.makeArray(found_images);
				found_images.each(function(image){
					if (!this.complete){
					image_parents[counter] = $(this).parent();
					$(this).remove();
					}
					else {
					this.loaded = true;
					$(this).fadeIn();
					}

					counter ++;

				})

				counter = 0;
					found_images.each(function(image){		 
							if (!this.loaded){ 
								var	parent = $(image_parents[counter]);
							 var img = new Image();
							  $(img).load(function () {
							      $(this).css('display','none').appendTo(parent).fadeIn();
							   }).error(function () {}).attr('src', this.src);
							}		
							counter ++;			
							});
		}
		
		
	function changeDocumentTitle(title_text){
		var titleConstant = " | :robot communicant"
		var newTitle = title_text + titleConstant;
		document.title = newTitle
	}
	
	
	
	function clearText(input_obj){
		var input = $(input_obj);
		if ( input.hasClass('clear') == false ) {
			if (input[type='text']){ input.val(''); }
			if (input[type='textarea']){ input.text(''); }
			input.addClass('clear');
		}
	}
