//**********************************************************************************************************************
/**
* DOCUMENT: main.js
* DEVELOPED BY: Dustin Dikes
* EMAIL: dustindikes@gmail.com
* PHONE: 509-279-4968
* DATE: 05/28/2011
* DESCRIPTION: This document contains all the javascript for the Pet Savers website
*/
//***********************************************************************************************************************

var cur_slide 		= 0;
var num_slides		= 0;
var slide_length	= 10000;
var first_switch	= 0;

/************************************************************************
/ Document Ready
/************************************************************************/
$(document).ready(function(){

	// Count number of slides
	num_slides = $('.slide').length - 1;
	
	// Set slider timeout
	setTimeout('switch_slide()',slide_length);
	
	// Set interior aside height
	var aside_height	= $('#content aside').height();
	var section_height	= $('#content section').outerHeight();
	
	if(section_height > aside_height)
	{
		$('#content aside').height(section_height);
	}
	
	// Date picker
	
	var min_date = 	0;
	var date =		new Date();
	var day = 		date.getDay();
		
	if(day == 1) {
		min_date = 2;
	}
	
	if(day == 2 || day == 3 || day == 4) {
		min_date = 4;
	}
	
	if(day == 5 || day == 6 || day == 0) {
		min_date = 3;
	}
	
	$('.datepicker').datepicker({ 
		minDate:		min_date,
		maxDate: 		'+2m',
		beforeShowDay: 	unavailable
	});
	
	// Newsletter Box
	$('#newsletter_email').click(function(){
		if($(this).val() == 'Email') {
			$(this).val('');
		}
	});
	
	// Additional Services
	$('#additional_checkbox').click(function(){
	
		if($(this).is(':checked'))
		{
			$('#additional_services').slideDown(300);
		}
		else 
		{
			$('#additional_services').slideUp(300);
		}
	
	});

});

/************************************************************************
/ Limit dates available on datepicker
/************************************************************************/
        	
function unavailable(date) {

	var unavailableDates = 	["9-24-2011"];
	var day = 				date.getDay();
	var dmy = 				date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
	var curTime = 			new Date();
	var curMonth =			curTime.getMonth() + 1;
	var curYear = 			curTime.getFullYear();
	var curDay = 			curTime.getDate();
	var curDate = 			curDay + '-' + curMonth + '-' + curYear;
	
	// Set holidays
	natDays = [
	  [1, 	1, 	'us'], 	// New Years
	  [7, 	4, 	'us'], 	// Fourth of July
	  [12, 	24, 'us'], 	// Christmas Eve
	  [12, 	25, 'us'] 	// Christmas Day
	];
	
	// Check if it is a holiday
	var natFail = false;
    for (i = 0; i < natDays.length; i++) {
      if (date.getMonth() == natDays[i][0] - 1
          && date.getDate() == natDays[i][1]) {
        natFail = true;
      }
    }
	
	
	// Disable Thursdays, Fridays, and Sundays	
	// Disable Specified Dates
	if (day != 4 && day != 5 && day != 0 && $.inArray(dmy, unavailableDates) == -1 && !natFail) {
		console.log('available' + day);
		return [true, ""];
	} else {
		console.log('unavailable');
		return [false,"","Unavailable"];
	}
}

/************************************************************************
/ Switch Slides
/************************************************************************/
function switch_slide() {
	
	cur_slide++;
	
	if(cur_slide > num_slides) {
		cur_slide = 0;
	}
	
	// Only do this after the first slide has gone
	// Move the first slide to the bottom, reset the top to zero
	if(first_switch > 0) {
		$('.slide').eq(0).insertAfter($('.slide:last'));
		$('#slides').css('top','0');
	}
	else {
		first_switch++;
	}
	
	// Slide up and update navigation dot
	$('#slides').animate({'top':'-300px'},500);
	$('#slider_nav ul li').removeClass('current').eq(cur_slide).addClass('current');
	
	setTimeout('switch_slide()',slide_length);
}
