var base_path = "http://squiid.com/";


$(function(){	
	/*
	#
	#
	#
	#
	#
	#
	*/
	
	//Services page scrollup
	//$('.services .grid_3').append('<a href="#">Read mo &raquo;</a>').children('p').hide();

	
	
	
	   var keys = []; var vals = [];
	   $('#header input:text').each(function(){
	       $(this).attr('orig', $(this).val());
	       	      $(this).focus(function(){
        	          if ($(this).val() == $(this).attr('orig'))
        	            $(this).val('');
        	      });   
	        });

	        $("#newsletter_signup form").submit(function(){
				/*
				var m = '#newsletter_signup .message';
				var pass = false;
				var first = $('#head_firstname').val();
				var last = $('#head_lastname').val();
				var email = $('#head_email').val();
				var msg = '';
				alert(first);
				if ( first == 'first') {
					alert(first);
					msg = 'Please tell me your first name';
					$('#head_firstname').focus();
					$('#newsletter_signup .message').html(msg).show();
					return false;
				} /*else if (last == '' || last == 'last') {
				 	msg = 'Last name required';
					$('#head_last_name').focus();
					$('#newsletter_signup .message').html(msg).show();
				} /*else { 
					alert('else');
					pass = true;
				}
				*/
				
				  $('#head_noajax').remove();
				  $.post(base_path + 'ajax/newsletter_mini', $(this).serialize(), 
					function(data, b, c){
						$('#newsletter_signup form').fadeOut('slow', function(){
							$('#newsletter_signup .message').html(data).fadeIn().delay(1000).fadeOut(function(){
								$('#newsletter_signup form').fadeIn();
								$('#newsletter_signup form input:text').each(function(){
									$(this).val('');
								});
								
							});
						});
		           });

		           return false;

	        }); //end submit
	
	
	
	
	//$('body').addClass('snow');
	//$('div#logo img').attr('src', base_path + 'images/logo-black.png');
	
	/*$('#logo img').hover(function(){
		$(this).attr('src', base_path + 'images/logo-yellow.png');
	},function(){
		$(this).attr('src', base_path + 'images/logo-white.png');
		
	});*/
	
	//SCROLL FOLLOW just set the div to class='scrollfollow'	
	$('div.scrollfollow').scrollFollow(); 


	//make sure those blank anchors don't jump
	$('a').each(function(){
			if ($(this).attr('href') == '#')
			{ 
				$(this).click(
					function(){
						return false;
					});
			}
	});
	
	//jquery.localscroll for main anchors
	$('#main').localScroll({
		offset: -70,
		hash: false,
		reset: true
	});
	
	//jqury.lazyload for efficienc
	$('#main img').lazyload({
		threshold: 200,
		effect: 'fadeIn'
	});

	//Squid generic image toggle
	//Set image class to toggle, and give off image filename with 'off' and on image filename with 'on'
	$('img.toggle').hover(function(){
		$(this).attr('src',$(this).attr('src').replace('off', 'on'));
	}, function(){
		$(this).attr('src',$(this).attr('src').replace('on', 'off'));
	});
	
	
	//Special Pages: More Content
	
	$('a.slideDown').click(function(){
		var what = $(this).attr('rel');
		//alert(what);
		$(what).slideDown('fast');
		return false;
	});
	
	$('a.fadeIn').click(function(){
		var what = $(this).attr('rel');
		$(what).fadeIn(fast);
		return(false);
	});
	
	$('a.more').click(function(){
		$(this).fadeOut();
		$(this).parent().parent().find('p.more').slideDown('slow');
				//$('p.more').slideDown('slow');
		return false; //dont jump shaggy
	});
	
	
	
	
	
	
	
	
	
	/* SIDEBAR FORM */
	
	$('#success').hide();
	
	
	
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
	    phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number");

	
	
	$("#sidebar_request").validate({
		rules : {
			phone: { 
				phoneUS: true
				}
		},
		submitHandler: function(form) {
				$(form).ajaxSubmit({
					target: 	'#success',
					url: 		base_path + 'ajax/sidebar_request',
					type: 		'post',
					success: function(){
						$('#sidebar_request').fadeOut('slow', function(){
							$('#success').fadeIn('slow').delay(2000).fadeOut('slow');
						});
					}
					
				});
				return false;
		}
	});
	
	
	$("#comment_post").validate({
		rules: {
			name: {required: true },
			website: {required: true }
		},
		submitHandler: function(form) {
				$(form).ajaxSubmit({
					type: 		'post',
					target: '#newcomment',
					success: function(){
						$('#comment_post').slideUp('fast', function(){
							$('#newcomment').slideDown('fast');
							
							$('#comments_count').fadeOut('fast').html('Viewing all comments').fadeIn('fast');
							$('p#you_should_post').fadeOut('fast').html('Thank you for posting!').fadeIn('fast');
							
							squidCufon();
						});
					}
					
				});
				//return false;
		}
	});
	
	
	/*
	
	
	$('.skin-block').click(function(){
		if ($(this).attr('id') == 'skin-one') swapSkin('yellow');
		if ($(this).attr('id') == 'skin-two') swapSkin('garage');			
		if ($(this).attr('id') == 'skin-three') swapSkin('snowy');
	});
	
	*/
	
});


function swapSkin(g) {
	$('body').fadeOut('fast', function(){
		$('body').attr('id', g);
		squidCufon();
	}).delay('100').fadeIn();
	

	 
}

