$(function(){

	$("#header form input.text, form #zipcode")
		.focus(function() {	if (this.value === this.defaultValue) {	this.value = ''; } })
		.blur(function() { if (this.value === '') { this.value = this.defaultValue;	} });

	if ($('body').hasClass('home')) {
	
	    $('#slideshow .slides').before('<a class="prev" title="Previous">Previous</a><a class="next" title="Next">next</a><ul class="slide-nav"></ul>').cycle({
	        fx:      'scrollHorz',
			timeout: 6000,
			speed: 400,
	        prev:    '#slideshow .prev',
	        next:    '#slideshow .next',
	        pager:   '#slideshow .slide-nav',
	        pagerAnchorBuilder: pagerFactory
	    });
	
		$('#slideshow .prev, #slideshow .next, #slideshow .slide-nav').click(function() {
			$('#slideshow .slides').cycle('pause');
		});
	
	
		$('.social-media-tabs .holderdiv').hide();
		$('.social-media-tabs .holderdiv:first').show();
		$('.social-media-tabs ul li a:first').addClass('selected');
	
		$('.social-media-tabs ul li a').click(function() {
			$('.social-media-tabs ul li a').removeClass('selected');
			$(this).addClass('selected');
			var currentTab = $(this).attr('href');
			$('.social-media-tabs .holderdiv').hide();
			$(currentTab).show();
			return false;
		});
	
	
		$('.zip-code-check .message a').click(function() {
			$(this).parent().hide();
			return false;
		});

		$('.zip-code-check form').submit(function() {
			var userCode = $('.zip-code-check .text').val();
			if (userCode == "Enter Your ZIP to SIGN UP") {
				$('.zip-code-check .error').show(); 
			} else {
				var zipCodes = "78701,78702,78703,78704,78705,78712,78722,78723,78731,78735,78739,78741,78745,78746,78748,78749,78751,78752,78753,78756,78757,78758,78759".split(',');
				var inArea = false;
				var maybeZipCodes = "78727,78730,78733,78750".split(',');
				var maybeInArea = false;
		
				$.each(zipCodes, function(i, val) {
					if (val == userCode) { inArea = true; } 
			    });
	
				if (!(inArea)) {
					$.each(maybeZipCodes, function(i, val) {
						if (val == userCode) { maybeInArea = true; } 
				    });
				}
	
				if (inArea) {
					$.fn.colorbox({href:'http://ecocleanaustin.com/form/', innerWidth:520, innerHeight:560, scrolling:false, iframe:true, open:true}); 
				} else if (maybeInArea) {
					$('.zip-code-check .maybe').show(); 
				} else {
					$('.zip-code-check .failure').show(); 
				}
			}	
			return false;
		});
		
		}
	
	$('.sidebar .signup form').submit(function() {
		var userCode = $('.sidebar .signup .text').val();
		if (userCode != "Enter Your ZIP to SIGN UP") {
			var zipCodes = "78701,78702,78703,78704,78705,78712,78722,78723,78731,78735,78739,78741,78745,78746,78748,78749,78751,78752,78753,78756,78757,78758,78759".split(',');
			var inArea = false;
			var maybeZipCodes = "78727,78730,78733,78750".split(',');
			var maybeInArea = false;
				
			$.each(zipCodes, function(i, val) {
				if (val == userCode) { inArea = true; } 
		    });

			if (!(inArea)) {
				$.each(maybeZipCodes, function(i, val) {
					if (val == userCode) { maybeInArea = true; } 
			    });
			}
			
			if (inArea) {
				$.fn.colorbox({href:'http://ecocleanaustin.com/wordpress/form/', innerWidth:520, innerHeight:560, scrolling:false, iframe:true, open:true}); 
			} else if (maybeInArea) {
				$.fn.colorbox({href:'http://ecocleanaustin.com/forms/form-maybe.html', innerWidth:520, innerHeight:100, scrolling:false, iframe:true, open:true}); 
			} else {
				$.fn.colorbox({href:'http://ecocleanaustin.com/forms/form-sorry.html', innerWidth:520, innerHeight:140, scrolling:false, iframe:true, open:true}); 
			}			
		}	
		return false;
	});	


	if ($('body').hasClass('delivery')) {
	
		$('.sidebar .refer a').click(function(e) {
			e.preventDefault();
			$.fn.colorbox({href:'http://ecocleanaustin.com/forms/form-share.html', innerWidth:520, innerHeight:290, scrolling:false, iframe:true, open:true}); 
		});	

	}	
	
	if ($('body').hasClass('about')) {
	
	    $('#about-us-slideshow .slides').before('<ul class="slide-nav"></ul>').cycle({
	        fx:      'scrollHorz',
			timeout: 6000,
			speed: 400,
	        pager:   '#about-us-slideshow .slide-nav',
	        pagerAnchorBuilder: pagerFactory
	    });
	
		$('#about-us-slideshow .slide-nav').click(function() {
			$('#about-us-slideshow .slides').cycle('pause');
		});

	}	
	
	
	$('.post ol').addClass('special').find('li').wrapInner('<span>');
	
	
    $('.sidebar .share a').click(function (e){
		e.preventDefault();
		var url = $(this).attr('href');
		window.open(url, 'Share', 'width=610,height=500,scrollbars=no');
	});
	
	
	
});

	    function pagerFactory(idx, slide) {
	        return '<li><a href="#" title="Jump to slide '+(idx+1)+'">'+(idx+1)+'</a></li>';
	    };

