//Text resize Function. URL:http://www.shopdev.co.uk/blog/text-resizing-with-jquery/
// Modified for 3 fixed sizes
var sitefunctions = {	
	textresize : function(){
		var $cookie_name = "textsize";
		var originalFontSize = 10; //$("#mainContent").css("font-size"); IE doesn't like this
		if($.cookie($cookie_name)){
			var $getSize = $.cookie($cookie_name);
			$("#mainContent").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error			
			if($getSize > 10) {
				$("#increaseFont").addClass('darker');
			} else if($getSize < 10) {
				$("#decreaseFont").addClass('darker');
			} else {
				$("#resetFont").addClass('darker');
			}			
		} else{
			$.cookie($cookie_name, originalFontSize, { path: '/' });
			$("#resetFont").addClass('darker');
		}
		$("#resetFont").bind("click",function(){
				$("#mainContent").css("font-size", originalFontSize);
				$.cookie($cookie_name, originalFontSize, { path: '/' });				
				$("#adjustText > a").removeClass('darker');				
				$("#resetFont").addClass('darker');
		});
		$("#increaseFont").bind("click",function(){
				//var currentFontSize = $("#mainContent").css("font-size");
				var currentFontSizeNum = parseFloat(originalFontSize, 10);
				var newFontSize = currentFontSizeNum*1.2;
				if (newFontSize < 13) {
					$("#mainContent").css("font-size", newFontSize);
					$.cookie($cookie_name, newFontSize, { path: '/' });
				}
				$("#adjustText > a").removeClass('darker');				
				$("#increaseFont").addClass('darker');
				return false;
		});
		$("#decreaseFont").bind("click",function(){
				//var currentFontSize = $("#mainContent").css("font-size");
				var currentFontSizeNum = parseFloat(originalFontSize, 10);
				var newFontSize = currentFontSizeNum*0.8;
				if (newFontSize > 7) {
					$("#mainContent").css("font-size", newFontSize);
					$.cookie($cookie_name, newFontSize, { path: '/' });
				}
				$("#adjustText > a").removeClass('darker');
				$("#decreaseFont").addClass('darker');
				return false;
		});
	}
}

// Homepage Switcher
function switcher() {
	$("#switch-list > li").each(
		function( intIndex ){
			var prevId;
			$( this ).bind ("click",function(){
				$("#switch-list > li").removeClass('active');
				var ad = this.id;
				$("#"+ad).addClass('active');				
				if(ad == "third") {
					$("#second").addClass('middle');
				} else {
					$("#second").removeClass('middle');
				}
				$("#main > div").hide();
				var ad_content = ad + "_content";
				$("#"+ad_content).fadeIn(950);
				return false;
			}
		);
	});
}

//Smooth Scrolling
function smoothScroll() {
	$('#main a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			  var $target = $(this.hash);
			  $target = $target.length && $target
			  || $('[name=' + this.hash.slice(1) +']');
			  if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 1200);
			   return false;
			}
		}
	});
}

//Clear Form Fields
//Add the ID of each item you want to clear at the bottom of this block of code
function clearFields() {
	$.fn.clearThis = function() {		
		return this.focus(function() {
			var id1 = this.id;			
			if( this.value == this.defaultValue ) {
				$("#"+id1).addClass('darker');
				this.value = "";				
			}
		}).blur(function() {
			var id1 = this.id;		
			if( !this.value.length ) {
				$("#"+id1).removeClass('darker');
				this.value = this.defaultValue;				
			}
		});
	};
}


 
$(document).ready(function(){
	sitefunctions.textresize();
	if ( $("#switcher").length > 0 ) { switcher(); }
	smoothScroll();	
	clearFields();
	$("#search").clearThis();
	$("#email").clearThis();
	
});
