function startScroll(tabID) {
	
	jQuery("#"+tabID).find('div').stop().scrollTo('580px', 20000, {axis: 'x', onAfter: function(){
   			
   		jQuery(this).stop().scrollTo('0px', 20000, {axis: 'x'});
   		
   	}});
	
}

function resetTours() {
	
	jQuery("#tours li div").stop().scrollTo("0px", 0, {axis: 'x'});
	
}

jQuery(document).ready(function(){
	
	if(jQuery('a[rel*=facebox]').length) {
		$('a[rel*=facebox]').facebox();
	}

	//jQuery("#contact").hide();

	//cycle only if #header exists
	if(jQuery('#header').length) {
		jQuery('#header').cycle({ 
    		fx:     'fade',
    		speed:	2500,
    		timeout: 8000, 
    		delay:  0,
    		easing: 'swing',
    		pager: '#slideNav'
   		});
   	}
   	
   	//cycle on of #slideShow exists
   	if(jQuery('#slideShow').length) {
		jQuery('#slideShow').cycle({ 
    		fx:     'fade',
    		speed:	3000,
    		timeout: 8000, 
    		delay:  0,
    		easing: 'swing'
   		});
   	}
   	
   	//setup virtual tour tabs
   	if(jQuery('#tabs').length) {
   		
   		//make the first virtual tour visible
   		jQuery("#tours li:first").css({'display': 'block'});
   		
   		jQuery("#tours li:first div").scrollTo('100%', 20000, {axis: 'x', onAfter: function(){
   			
   			jQuery('#tours li:first div').scrollTo('0px', 20000, {axis: 'x'});
   		
   		}})
   		
   		//scroll button next
   		jQuery("#tours li img#next").click(function(){
   			
   			//first stop scroll animation
   			jQuery(this).parent().find('div').stop();
   			
   			//now scroll forward to the end
   			jQuery(this).parent().find('div').scrollTo('+=200px', 1000, {axis: 'x'});
   			
   		});
   		
   		//scroll button previous
   		jQuery("#tours li img#prev").click(function(){
   			
   			//first stop scroll animation
   			jQuery(this).parent().find('div').stop();
   			
   			//now scroll forward to the end
   			jQuery(this).parent().find('div').scrollTo('-=200px', 1000, {axis: 'x'});
   			
   		});
   
   		
   		//remove the border on the last tab
   		jQuery("#tabs li:last").css({'background': 'none'});
   		
   		jQuery("#tabs li a").click(function(){
   		
   			//fade out all tours
   			jQuery("#tours li").fadeOut(1000, function(){
   			
   				//reset tours
   				resetTours();
   				
   			});
   			
   			//remove active class from tabs
   			jQuery("#tabs li a").removeClass("active");
   			
   			//apply active class to clicked tab
   			jQuery(this).addClass("active");
   			
   			tabID = jQuery(this).attr('title');
   			
   			jQuery("#"+tabID).fadeIn(1000, function(){
   			
   				startScroll(tabID);
   				
   			});
   			
   		})
   		
   	}
   	
   	
   	
   	//setup quote button (on virtual offices page)
   	if(jQuery('#getquote').length) {
   		jQuery("#getquote").toggle(function(){
			
			getQuoteOn();
	
		}, function(){
		
			getQuoteOff();
	
		});
		
		//facebox
		$('a[rel*=facebox]').facebox();
	}
	
	//setup the "view plans button"
	if(jQuery("#plans").length) {
		jQuery("#getaquote a:first").toggle(function(){
		
			seePlansOn();
	
		}, function(){
	
			seePlansOff()
	
		})
	}
   	
   	
   	//setup navigation effects
   	jQuery("#nav td:not(.current)")
   			.css({backgroundPosition: "0px 0px"})
   			.mouseenter(function(){
   				   				
   				jQuery(this).stop().animate({backgroundPosition: "(0px -110px)"}, 1000);
   				
   				jQuery(this).children("a").stop().animate({color: "#6b4f04"}, 500);
   				
   			})
   			.mouseleave(function(){
   				
   				jQuery(this).stop().animate({backgroundPosition: "(0px 0px)"}, 1000);
   				
   				jQuery(this).children("a").stop().animate({color: "#ffffff"}, 500);
   				
   			})
   			
   	
   	//remove the CSS border from the last in the navigation
	jQuery("#nav td:last").css("border-right", "0px");
	
	
	//setup login input boxes
	jQuery('#username').focus(function(){
	
		if(this.value == '' || this.value == 'username') {this.value = ''}
		
		jQuery(this).css({'border-color':"#fbad05", 'background': '#fbf5e8'});
		
	}).blur(function(){
			
		jQuery(this).css({'border-color':"#cfd0d0", 'background': 'url(images/input_bg.gif) -1px -1px'});
		
	})
	
	jQuery('#password').focus(function(){
		
		if(this.value == '' || this.value == 'password') {this.value = ''}
		
		jQuery(this).css({'border-color':"#fbad05", 'background': '#fbf5e8'});
		
	}).blur(function(){
	
		jQuery(this).css({'border-color':"#cfd0d0", 'background': 'url(images/input_bg.gif) -1px -1px'});
		
	})
	
	
	//setup quote contact form
	if(jQuery("#contactForm").length) {
		
		jQuery("#contactForm input, #contactForm textarea").focus(function(){
		
			jQuery(this).animate({borderBottomColor: '#fbad05', borderLeftColor: '#fbad05', borderRightColor: '#fbad05', borderTopColor: '#fbad05', backgroundColor: '#fcf1d9'})
			
			//jQuery(this).css({'border-color':"#fbad05", 'background': '#fcf1d9'});
			
		}).blur(function(){
		
			jQuery(this).animate({borderBottomColor: '#cfd0d0', borderLeftColor: '#cfd0d0', borderRightColor: '#cfd0d0', borderTopColor: '#cfd0d0', backgroundColor: '#ffffff'})
			
			//jQuery(this).css({'border-color':"#cfd0d0", 'background': '#ffffff'});
			
		});
		
		jQuery("#submit").mousedown(function(){
		
			jQuery(this).css("background", "url(images/submit.gif) bottom left no-repeat");
		
		}).mouseup(function(){
			
			jQuery(this).css("background", "url(images/submit.gif) top left no-repeat");
				
		})
		
	}
	
	
	//setup form on the contact page
	if(jQuery("#contactPage").length) {
	
		jQuery("#contactPage input:not(#submit)").focus(function(){
		
			jQuery(this).css({'border-color':"#fbad05", 'background': '#fbf5e8'});
			
		}).blur(function(){
		
			jQuery(this).css({'border-color':"#cfd0d0", 'background': 'url(images/input_bg.gif) -1px -1px'});
			
		});
		
		
		jQuery("#contactPage textarea").focus(function(){
		
			jQuery(this).css({'border-color':"#fbad05", 'background': '#fbf5e8'});
			
		}).blur(function(){
		
			jQuery(this).css({'border-color':"#cfd0d0", 'background': 'url(images/textarea_bg.gif) 0px 4px repeat-x'});
			
		});
		
		//make the first field active
		jQuery("#form input:first").focus();
	
	}
	
	
	//setup Casual Page hover thumbs
	
	if(jQuery("#contentCasual").length) {

		jQuery("ul#thumbs li").toggle(function() {
	
			jQuery("ul#thumbs li").css("z-index", 0);
			
			jQuery('#butt').remove();
	
			jQuery(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
			jQuery(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
				.animate({
					marginTop: '-110px', /* The next 4 lines will vertically align this image */ 
					marginLeft: '-310px',
					top: '50%',
					left: '50%',
					width: '484px', /* Set new width */
					height: '363px', /* Set new height */
					padding: '20px'
				}, 200, "backinout", function(){
				
					offset = jQuery(this).offset();
				
					butt = jQuery("<div id='butt'></div>").css({'position': 'absolute', 'top': '-20px', 'left': '120px', 'z-index': 15})
					
					jQuery(this).parent().append(butt)
					
				});

			}, function() {
			
				jQuery(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
					.animate({
						marginTop: '0', /* Set alignment back to default */
						marginLeft: '0',
						top: '0',
						left: '0',
						width: '110px', /* Set width back to default */
						height: '90px', /* Set height back to default */
						padding: '5px'
				}, 400, "backinout", function(){
			
					jQuery('#butt').remove();
				
				});
			});		
		}
		
	
	
	//setup the footer left ads
	jQuery(".left > div").toggle(function(){
	
		jQuery(this).next().show("drop", {}, 500)
	
	}, function(){
	
		jQuery(this).next().hide("drop", {}, 500);
	
	});
	
	//setup the home page bar ads
	/*jQuery("#promoBar > div").toggle(function(){
	
		jQuery(this).find("p").show("drop", {direction: 'up'}, 500)
	
	}, function(){
	
		jQuery(this).find("p").hide("drop", {}, 500);
	
	});*/
	
	
	//datepicker on the availability page
	if(jQuery("#widgetField").length) {
	
		var now3 = new Date();
		
		var now4 = new Date()
				
		$('#widgetCalendar').DatePicker({
			flat: true,
			format: 'd B, Y',
			date: [new Date(), new Date()],
			calendars: 2,
			mode: 'range',
			starts: 1,
			onChange: function(formated) {
				$('#widgetField span').get(0).innerHTML = formated.join(' - ');
			}
		});
		var state = false;
		$('#widgetField>a').bind('click', function(){
			$('#widgetCalendar').stop().animate({height: state ? 0 : $('#widgetCalendar div.datepicker').get(0).offsetHeight}, 500);
			state = !state;
			return false;
		});
		$('#widgetCalendar div.datepicker').css('position', 'absolute');
		
		$("#widgetField").toggle(function(){
			
			$('#widgetCalendar').stop().animate({height: state ? 0 : $('#widgetCalendar div.datepicker').get(0).offsetHeight}, 500);
			state = !state;
			
		}, function(){
		
			$('#widgetCalendar').stop().animate({height: state ? 0 : $('#widgetCalendar div.datepicker').get(0).offsetHeight}, 500);
			state = !state;
		
		})
	
	}
});



function getQuoteOn() {
	
	//if the plans section is on display, we'll hide it first
	if(jQuery("div#plans").css('display') == 'block') {
			
		jQuery("a#seeplans").css('background', 'url(images/moreinfo.gif) top left no-repeat');
		jQuery("div#plans").css('display', 'none');
				
	}
			
	//fade out the steps section
	jQuery("#steps").animate({opacity: 0.4}, 1000);
			
	//fade out the "view plans" button
	jQuery("a#seeplans").animate({opacity: 0.4}, 1000);
	
	//disable seeplans button
	jQuery("#getaquote a:first").unbind("click");
			
	//button effect
	jQuery("#getaquote a:last").css("background", "url(images/getaquote.gif) bottom left no-repeat");
	
	jQuery('#contact').stop().slideDown(1500, function(){$("#firstname").focus();});
	
}

function getQuoteOff() {
	
	//fade in the steps section
	jQuery("#steps").animate({opacity: 1}, 1000);
	
	//fade in the seeplans button
	jQuery("a#seeplans").animate({opacity: 1}, 1000);
	
	//enable the seeplans button
	jQuery("#getaquote a:first").toggle(function(){seePlansOn()}, function(){seePlansOff()})
		
	//button effect
	jQuery("#getaquote a:last").css("background", "url(images/getaquote.gif) top left no-repeat");
	
	jQuery('#contact').stop().slideUp(1500);
	
}

function seePlansOn() {
	
	if(jQuery("div#contact").css('display') == 'block') {
			
		jQuery("div#contact").css('display', 'none');
		jQuery("a#quote").css('background', 'url(images/getaquote.gif) top left no-repeat');
				
	}
			
	//fade out the steps section
	jQuery("#steps").animate({opacity: 0.4}, 500);
	
	//fade out the getaquote button
	jQuery("a#quote").animate({opacity: 0.4}, 500);
	
	//disable the getaquote button
	jQuery("a#quote").unbind("click");
	
	//button effect
	jQuery("#getaquote a:first").css("background", "url(images/moreinfo.gif) bottom left no-repeat");
	
	jQuery('#plans').stop().slideDown(1000);
	
}

function seePlansOff() {
	
	//fade in the steps section
	jQuery("#steps").animate({opacity: 1}, 500);
	
	//fade in the getaquote button
	jQuery("a#quote").animate({opacity: 1}, 500);
	
	//enable the getaquote button
	jQuery("a#quote").toggle(function(){getQuoteOn()}, function(){getQuoteOff()});
	
	//button effect
	jQuery("#getaquote a:first").css("background", "url(images/moreinfo.gif) top left no-repeat");
	
	jQuery('#plans').stop().slideUp(1000);
	
}

function get_cookie (cookie_name) {

	var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

	if (results) {
  		return (unescape(results[2]));
  	} else {
    	return null;
    }
}


