function afterComment(){
			j('#contactForm').slideUp('slow',function(){
				j('#video').slideDown('slow');
				
				});
				}	
	jQuery.fn.delay = function(time,func){
	return this.each(function(){
		setTimeout(func,time);
	});
};	

var recent = '';
var j = jQuery.noConflict();
var site = 'http://www.sarahgrahamfitness.com/';	
j(document).ready(function(){
	
	var url = document.location.href;
	if(url.match('location')){
		initialize();
	}
	if(url.match('admin') == null){
		
		j.ajax({
			url: site + 'website/get_nav',
			type: 'POST',
			dataType: 'html',
			success : function(html){
			
				j('#contentWrapper #nav').remove();			
				if(j('#contentWrapper #video').length > 0){
				
					j('#contentWrapper').after(html);
				
				}else{
				
					j('#contentWrapper').before(html);
				
				} 
					j('#nav a').each(function(index, item){
						var rel = j(item).attr('rel');
						var href = j(item).attr('href');
						
						j(item).attr('rel', href);
						j(item).attr('href', '#' + rel);
					});
					
						var url = window.location.href;
	
					if(/#/.test(url)){
						var hash = '#' + url.split('#', 2)[1];
						
						reloadPage(j('#nav a[href=' + hash + ']'));
					}

			}
		
		});
	}
	

	
	
	j('#nav a.main').live('click', getPages);
	
		
	

/* check form validation */

	j('#checkout_form').submit(function(evt){
			var errors = {}
			
			// check credit card number
			var card_num = j('#card_num').val();
			if(card_num.trim() == '' || card_num.length <= 0){
				errors['card_num'] = 'This field is required';
			}else 
			
			if(/[\D]/.test(card_num)){
				errors['card_num'] = 'This field can only contains numbers';
			}
			
			// check cvv2 number 
			var cvv2 = j('#cvv2').val();
			if(cvv2.trim() == '' || cvv2.length <= 0){
				errors['cvv2'] = 'This field is required';
			}else
			if(cvv2.length < 3 || cvv2.length > 4){
				errors['cvv2'] = 'The field can only be between 3 and 4 numbers';
			}else
			if(/[\D]/.test(cvv2)){
				errors['cvv2'] = 'This field can only contain numbers';
			}
			
			// check the credit card type
			
			var card = j('#card').val();
			if(card.length <= 0 || card.trim() == ''){
				errors['card'] = 'This field is required';
			}
			
			// check the month
			var month = j('#month').val();
			
			if(month.length <= 0 || month.trim() == ''){
				errors['month'] = 'This field is required';
			}else 
			if(/[\D]/.test(month)){
				errors['month'] = 'This field can only contain numbers';
			}else
			if(parseInt(month) > 12 || parseInt(month) < 1){
				errors['month'] = 'You have selected an invalid month';
			}
			
			// check the year
			var year = j('#year').val();
			var d = new Date();
			var curYear = d.getFullYear();
			if(year.trim() == '' || year.length <= 0){
				errors['year'] = 'This field is required';
			}else
			if(/[\D]/.test(year)){
				error['year'] = 'This field can only contain numbers';
			}else
			if(year.length !== 4){
				errors['year'] = 'The year must be a four digit number';
			}else
			if(parseInt(year) < curYear){
				errors['year'] = 'The year you have supplied has already passed';
			}
			
			// check name
			var firstName = j('#first_name').val();
			
			if(firstName.trim() == '' || firstName.length <= 0){
				errors['first_name'] = 'This field is required';
			}else
			if(/[^a-zA-Z]/.test(firstName)){
				errors['first_name'] = 'This field can only contains letters';
			}
			
			// check last name
			var lastName = j('#last_name').val();
			if(lastName.trim() == '' | lastName.length <=0){
				errors['last_name'] = 'This field is required';
			}else
			if(/[^a-zA-Z]/.test(lastName)){
				errors['last_name'] = 'This field can only contains letters';
			}
			
			// check email
			var email = j('#email').val();
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(email.trim() == '' || email.length <= 0){
				errors['email'] = 'This field is required';
			}else
			if(!reg.test(email)){
				errors['email'] = 'You have entered and invalid email, please try again';
			}
			
			// check confirm email
			
			var confirmEmail = j('#confirm_email').val();
			if(confirmEmail.trim() == '' || confirmEmail.length <=0){
				errors['confirm_email'] = 'This field is required';
			}else
			if(confirmEmail !== email){
				errors['confirm_email'] = 'Your confirmation email does not match your email';
			}
			
			// check street
			var street = j('#street').val();
			if(street.lenth <=0 || street.trim() == ''){
				errors['street'] = 'The street address is required';
			}
			
			// check city
			var city = j('#city').val();
			if(city.length <= 0 || city.trim() == ''){
				errors['city'] = 'The city is required';
			}
			
			// check state
			var state = j('#state').val();
			if(state.length <= 0 || state.trim() == ''){
				errors['state'] = 'The state is required';
			}else
			if(/[^a-zA-Z]/.test(state)){
				errors['state'] = 'The state may only contain letters';
			}else
			if(state.length !== 2){
				errors['state'] = 'The state may only contain two letters';
			}
			
			// check zip code
			var zip = j('#zip').val();
			if(zip.length <=0 || zip.trim() == ''){
				errors['zip'] = 'The zip code is required';
			}else
			if(/[\D]/.test(zip)){
				errors['zip'] = 'The zip code may only contain numbers';
			}else
			if(zip.length < 5){
				errors['zip'] = 'Your zip code does not have enough numbers';
			}
			var errorArray = [];
			j('span.checkout_error').remove();
			for(field in errors){
				if(errors.hasOwnProperty(field)){
					
					var message ='<span class="checkout_error">* ' + errors[field] + '</span>';
					if(field == 'zip'){
						j('label[for=state]').append(message);
					}else{
						j('label[for=' + field + ']').append(message);
					}
				
					errorArray.push(field);
				
				}
			}
			
			if(errorArray.length > 0){
				evt.preventDefault();
			}

	
	
		
	});



});
      
function initialize(){

var map;
    var directionsPanel;
    var directions;
	

      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(37.302685,-121.931624), 15);
      map.setUIToDefault();
      mapSetup();
}
      
function mapSetup(){


	 	j('#getDirections').submit( function(){
	  	
  	var errors = new Array();
	 
	   	 
	  	if(j('#street').val() == ''){
	  		errors.push('Please fill in your street address');
	  	}
	  	if(j('#city').val() == ''){
	  		errors.push('Please fill in your city');
	  	}
	  	if(j('#zip').val() == ''){
	  		errors.push('Please fill in your zip code');
	  	}
	  	if(j('#zip').val() !== '' && j('#zip').val().length !== 5){
	  		errors.push('Please use a 5 digit zip code');
	  	}
	  	if(isNaN(j('#zip').val())){
	  		errors.push('The zip code must only be a 5 digit number');
	  	}
	
	  	if(errors.length > 0){
	  	
	  		var errorBlock = j('<div>').attr('id', 'error');
	  		j.each(errors, function(){
	  			errorBlock.append('<span>' + this + '</span>');
	  			
	  		
	  		});
	  		
	  		j('div.innerContent h1').after(errorBlock);
	  		
	  		return false;
	  	}

		var map;
	    var directionsPanel;
	    var directions;
		var from = j('#street').val() + ', ' + j('#city').val() + ', ' + j('#state').val() + ', ' + j('#zip').val();
	      map = new GMap2(document.getElementById("map_canvas"));
	      map.setCenter(new GLatLng(37.302685,-121.931624), 15);
	      directionsPanel = document.getElementById("route");
	      directions = new GDirections(map, directionsPanel);
	    
	      directions.load("from: " + from + " to: 1256 s bascom ave, san jose, ca, 95008");
		
		j('#route').delay(500,function(){
			j('#route').slideDown('normal');
			});
	
       return false  
    });




}

	function reloadPage(clicked){
		var href = j(clicked).attr('rel');
		var nav = j('#nav');
		var link = j(clicked).attr('class');
				
		j('#contentWrapper').slideUp('normal'); //, function(){
		j('#contentWrapper').delay(50, function(){
			j.ajax({
				url: href,
				type: "POST",
				dataType : 'html',
				success : function(html){
					var contentWrapper = j('#contentWrapper');

						
						
						if(link.match('video')){
							contentWrapper.html(html).hide();
							nav.before(contentWrapper);
							
							contentWrapper.delay(50, function(){
								contentWrapper.slideDown('normal');
							
							});
							
						}else{
							contentWrapper.html(html).hide();
							nav.after(contentWrapper);
							
							if(link.match('location')){
								initialize();
							}
							
							contentWrapper.delay(50, function(){
							
								contentWrapper.slideDown('normal');
							});
						}					
						
					}
				
			});
			});
			
		}


	function getPages(evt){
		var href = j(this).attr('rel');
		var nav = j('#nav');
		var link = j(this).attr('class');
				
		j('#contentWrapper').slideUp('normal'); //, function(){
		j('#contentWrapper').delay(50, function(){
			j.ajax({
				url: href,
				type: "POST",
				dataType : 'html',
				success : function(html){
					var contentWrapper = j('#contentWrapper');

						
						
						if(link.match('video')){
							contentWrapper.html(html).hide();
							nav.before(contentWrapper);
							
							contentWrapper.delay(50, function(){
								contentWrapper.slideDown('normal');
							
							});
							
						}else{
							contentWrapper.html(html).hide();
							nav.after(contentWrapper);
							
							if(link.match('location')){
								initialize();
							}
							
							contentWrapper.delay(50, function(){
							
								contentWrapper.slideDown('normal');
							});
						}					
						
					}
				
			});
			});
			
		}












	
	
	
	
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}




