/**********************************************************/
// CLEARS TEXT FIELD ON FOCUS; REPLACES ON BLUR
function clearText(input){
	if(input.defaultValue==input.value){input.value=''};
}

function restoreText(input){
	if(input.value==''){input.value=input.defaultValue;}
}
/**********************************************************/


/* JQUERY */
$(document).ready(function() {
	
	
	/**********************************************************/
	// IPHONE DETECTION
	var deviceIphone = "iphone";
	var deviceIpod = "ipod";
	
	//Initialize our user agent string to lower case.
	var uagent = navigator.userAgent.toLowerCase();
	
	//**************************
	// Detects if the current device is an iPhone.
	function DetectIphone()
	{
	   if (uagent.search(deviceIphone) > -1)
		  return true;
	   else
		  return false;
	}
	
	//**************************
	// Detects if the current device is an iPod Touch.
	function DetectIpod()
	{
	   if (uagent.search(deviceIpod) > -1)
		  return true;
	   else
		  return false;
	}
	
	//**************************
	// Detects if the current device is an iPhone or iPod Touch.
	function DetectIphoneOrIpod()
	{
		if (DetectIphone())
		   return true;
		else if (DetectIpod())
		   return true;
		else
		   return false;
	}
	/**********************************************************/
	
	
	
	/**********************************************************/
	// INIT
	$('. section img').hide();
	$('.section .center').hide();
	$('.hours .center').show();
	
	var scrollElement;
	if($.browser.webkit) scrollElement = 'body';
	if($.browser.msie) scrollElement = 'html';
	if($.browser.mozilla) scrollElement = 'html';
	/**********************************************************/
	
	
	
	/**********************************************************/
	// IMG PRELOAD
	/**********************************************************/
	//window.onload = function() {
		//$('. section img').fadeIn(350);
		
		if (DetectIphoneOrIpod()) {
			$('#footer ul a:not(.clps_all)').css({
				'background-position' : '0 -46px',
				'text-indent' : 0,
				'height' : 'auto'
			});
		}
	//}
	
	
	/**********************************************************/
	// SECTION EXPANSION/CONTRACTION
	//$('.section:not(.hours)').each(function() {
	$('.section').each(function() {
		// OBJECTS
		var trigger = $('.trigger', this);
		var exp_clps = $('.exp_clps', this);
		var div = $('.center', this);
		var clps_all = $('.clps_all');
		
		// BOOLS
		var expanded = false;
		
		var section_name = $(this).attr('class').split(' ',3).pop();
		var section = '#footer a.'+section_name;
		
		// ASSIGNMENTS
		$(trigger).css({'cursor':'pointer'});
		$(div).css({'display':'none'});
		
		$(clps_all).click(function() {
			if (expanded) {
				changeState();
				if (DetectIphoneOrIpod() == false) {
					$('body').scrollTop();
				}
			}
			return false;
		});
		
		// FUNCTIONALITY
		$(trigger).click(function() {
			
			changeState();
			if (expanded) {
				if (DetectIphoneOrIpod() == false) {
					$('body').scrollTo({
						'top' : $('div.'+section_name).offset().top,
						'left': 0
					}, 600);
				}
			}
			return false;
		});
		
		// FOOTER NAV 
		$(section).click(function() {
			if (!expanded) {
				changeState();
			}
			
			if (DetectIphoneOrIpod() == false) {
				$('body').scrollTo({
					'top' : $('div.'+section_name).offset().top,
					'left': 0
				}, 600);
			}
			
			return false;
		});
		
		function changeState(inDiv) {
			if (expanded) { // close div
				$(div).slideUp(250);
				$(exp_clps).css('background-position','0 0');
			} else { // open div
				//$('.section .center').slideUp(250);
				$(div).slideDown(450);
				$(exp_clps).css('background-position','0 -22px');
			}
			
			// change value of 'expanded' boolean
			(expanded == false) ? expanded = true : expanded = false;
		}
		
		// expand 'hours & location' div
		/*if ( $(this).hasClass('.hours') ) {
			changeState();
		}*/
		
	});
	
	//$('.hours').slideDown(450);
	//$('.hours .exp_clps').css('background-position','0 -22px');
	/**********************************************************/
}); // END READY
