// Quick Contact Form Label Handler
var labelHandler = function (formControl, searchStr) {
	if ($(formControl).attr("value") == searchStr) {
		$(formControl).attr("value", "");
	}
	$(formControl).blur(function () {
		if ($(formControl).attr("value") == "") {
			$(formControl).attr("value", searchStr);
		}
	});
}

$(document).ready(function(){	
	
	$('#interior_buckets .bucket').each(function () {
		var self = $(this);
		self.css('cursor', 'pointer').click(function () {
			var destination = self.find('a.view_more').attr('href');
			window.location = 'http://' + window.location.host + '/' + destination;
		});
		self.hover (
			function () {
				self.toggleClass('hovered');
				self.prepend('<div class="bucketOverlay" />').find('.bucket_text').show();
				$('.bucketOverlay').css('opacity', '0.75');
				$('.hovered h3').css('opacity', '0.25');
				self.find('a.view_more').css({
					'background-position' : 'right -6px',
					'color' : '#dadb00',
					'z-index' : '999'
				});
			},
			function () {
				self.toggleClass('hovered');
				$('#interior_buckets .bucket .bucket_content h3').css('opacity', '1');
				$('.bucketOverlay').remove();
				self.find('.bucket_text').hide();
				self.find('a.view_more').css({
					'background-position' : 'right 2px',
					'color' : '#fff',
					'z-index' : '1'
				});
			}
		);
	});
	
	$('#home_buckets .bucket').each(function () {
		var self = $(this);
		self.css('cursor', 'pointer').click(function () {
			var destination = self.find('a.view_more').attr('href');
			window.location = 'http://' + window.location.host + '/' + destination;
		});
		self.hover (
			function () {
				self.toggleClass('hovered');
				self.prepend('<div class="bucketOverlay" />').find('.bucket_text').show();
				$('.bucketOverlay').css('opacity', '0.75');
				$('.hovered h3').css('opacity', '0.25');
				$('.hovered ul').css('opacity', '0.25');
				self.find('a.view_more').css({
					'background-position' : 'right -6px',
					'color' : '#dadb00',
					'z-index' : '999'
				});
			},
			function () {
				self.toggleClass('hovered');
				$('#home_buckets .bucket h3').css('opacity', '1');
				$('#home_buckets .bucket ul').css('opacity', '1');
				$('.bucketOverlay').remove();
				self.find('.bucket_text').hide();
				self.find('a.view_more').css({
					'background-position' : 'right 2px',
					'color' : '#fff',
					'z-index' : '1'
				});
			}
		);
	});
	/*
	//sticky right sidebar
	if ($('#right_column_floater').length > 0) {
		//get the left and top of the element
		var elemOffset = $('#right_column_floater').offset();
		//get the current value of the CSS 'position' attribute, for re-binding it later
		var cssPos = $('#right_column_floater').css('position');
		var contentHeight = $('#center_column').height();
		//bind to window.scroll
		$(window).scroll(function() {
			var scrollTop = $(window).scrollTop();
			
			//if the element is below the top of the viewport, return it to normal
			if(scrollTop < elemOffset.top) {
				//return original style
				$('#right_column_floater').css('position' , cssPos);
			}

			//if the top of the viewport is lower than or equal to the top of the element, set the element's position to fixed.
			if(scrollTop >= elemOffset.top && scroll) {
				$('#right_column_floater').css('position' , 'fixed');
				$('#right_column_floater').css('left' , elemOffset.left + 3);
				$('#right_column_floater').css('top' , 0);
			}

			//if the document is scrolled down, but far enough to overlap the footer, we change the style to not let that happen
			if  (scrollTop > (contentHeight - 200)) {
				$('#right_column_floater').css('top',  contentHeight - 420);
				$('#right_column_floater').css('left',  0);		
				$('#right_column_floater').css('position', 'relative');
			}
		});
		//$('#right_column').stickyfloat({ duration: 800 });
		
	}
	*/
	$("#quick_contact #contact-name").focus(function () {
		labelHandler(this, "Full Name*");
	});
	$("#quick_contact #contact-email").focus(function () {
		labelHandler(this, "Email Address*");
	});
	$("#quick_contact #contact-phone").focus(function () {
		labelHandler(this, "Phone Number");
	});
	$("#quick_contact #contact-comment").focus(function () {
		labelHandler(this, "Question or Comment*");
	});
	
	$('.pdf-btn').not('.alt').colorbox({inline:true, href:"#pdfList", close:"Close   <span>X</span>", width: "900px"});

});
