
function checkDates(){
	
	var date_filter = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;
	var email_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	// DATE FORMAT MM/DD/YYYY
	$("input.isDate").focus(
		function()
		{
			if( $(this).attr("value") == "mm/dd/yyyy"){
				$(this).attr("value", "");
			}
		}
	);
	$("input.isDate").blur(
		function()
		{
			if( $(this).attr("value") == null){
				$(this).attr("value", "mm/dd/yyyy");
			}
		}
	);
	
	// EMAIL ADDRESS
	$("input.isEmail").focus(
		function()
		{
			if( $(this).attr("value") == "enter your valid email address"){
				$(this).attr("value", "");
			}
		}
	);
	$("input.isEmail").blur(
		function()
		{
			if( $(this).attr("value") == null){
				$(this).attr("value", "enter your valid email address");
			}
		}
	);
	/*
	$("input.isDate").blur(
		function()
		{
			//alert( "YOU HAVE JUST LEFT THE INPUT " + $(this).attr("id") );
			var currentInput_ID = $(this).attr("id");
		//	alert(currentInput_ID);
			var str = $(this).attr("value");
		//	alert(str);
		//	alert( $(this) );
			if (!filter.test(str)){
				//alert('Please enter a vaild date, MM/DD/YYYY');
				return false;
				$("#" + currentInput_ID).focus();
			//	alert( $("#" + currentInput_ID) );
				//alert($(this));
			}
		}
	);
	*/
	
}

function toggleGalleryScroll()
{
	$("ul#gallery_scroll li a").click(
		function()
		{
				image_prefix = "slide_";
				image_suffix = ".jpg";
				$("ul#gallery_scroll li a").attr("class", "");
				$(this).attr("class", "current");
				clicked_on = $(this).text();
			$("img#gallery_scroll_image").fadeOut(250, function()
			{
				$("img#gallery_scroll_image").fadeIn(750);
				//$("img#gallery_scroll_image");
			}).attr("src", "/images/gallery/"+image_prefix + clicked_on + image_suffix);
			return false;
		})
}

function toggleTidbits()
{
	$("ul#tidbit_spinner a.next").click(
		function()
		{
			current_id = $(this).parent().parent().parent().attr("id");
			new_id = parseInt(current_id.replace("tidbit-", "")) + 1;
			
			if ( new_id > 11 ){
				new_id = 1;
			}
			
			new_id = "tidbit-" + new_id;
			
			if( $("li#" + current_id).attr("class") == "current" ){
				$("li#" + current_id).fadeOut("EaseOutExpo", function()
				{
					$("li#" + current_id).attr("class", "");
					$("li#" + new_id).attr("class", "current").fadeIn("EaseInExpo");
				});
			}
			
			return false; //disable the anchor from refreshing the page
		});
}

function selectPackages()
{
	$('form#proposal_form input#_package1').click(
		function(){
			if( $(this).attr("checked") == true)
			{
				$('input#_services_1_1').attr({checked: "checked"});
				$('input#_services_1_2').attr({checked: "checked"});
				$('input#_services_1_3').attr({checked: "checked"});
				$('input#_services_1_4').attr({checked: "checked"});
				$('input#_services_1_5').attr({checked: "checked"});
				$('input#_services_1_6').attr({checked: "checked"});
				$('input#_services_1_7').attr({checked: "checked"});
				$('input#_services_1_8').attr({checked: "checked"});
				$('input#_services_1_9').attr({checked: "checked"});
				$('input#_services_1_10').attr({checked: "checked"});
				$('input#_services_1_11').attr({checked: "checked"});
				$('input#_services_1_12').attr({checked: "checked"});
			}
			else if( $(this).attr("checked") == false)
			{
				$('input#_services_1_1').attr({checked: ""});
				$('input#_services_1_2').attr({checked: ""});
				$('input#_services_1_3').attr({checked: ""});
				$('input#_services_1_4').attr({checked: ""});
				$('input#_services_1_5').attr({checked: ""});
				$('input#_services_1_6').attr({checked: ""});
				$('input#_services_1_7').attr({checked: ""});
				$('input#_services_1_8').attr({checked: ""});
				$('input#_services_1_9').attr({checked: ""});
				$('input#_services_1_10').attr({checked: ""});
				$('input#_services_1_11').attr({checked: ""});
				$('input#_services_1_12').attr({checked: ""});
			}
		}
	);
	$('form#proposal_form input#_package2').click(
		function(){
			if( $(this).attr("checked") == true)
			{
				$('input#_services_1_1').attr({checked: "checked"});
				$('input#_services_1_3').attr({checked: "checked"});
			}
			else if( $(this).attr("checked") == false)
			{
				$('input#_services_1_1').attr({checked: ""});
				$('input#_services_1_3').attr({checked: ""});
			}
		}
	);
	$('form#proposal_form input#_package3').click(
		function(){
			if( $(this).attr("checked") == true)
			{
				$('input#_services_1_6').attr({checked: "checked"});
				$('input#_services_1_8').attr({checked: "checked"});
				$('input#_services_1_9').attr({checked: "checked"});
				$('input#_services_1_11').attr({checked: "checked"});
				$('input#_services_3_2').attr({checked: "checked"});
			}
			else if( $(this).attr("checked") == false)
			{
				$('input#_services_1_6').attr({checked: ""});
				$('input#_services_1_8').attr({checked: ""});
				$('input#_services_1_9').attr({checked: ""});
				$('input#_services_1_11').attr({checked: ""});
				$('input#_services_3_2').attr({checked: ""});
			}
		}
	);
}

function references()
{
			
	$('a.references').click( 
		function()
		{
				pagesize = getPageSize();
				x = pagesize[0];
				y = pagesize[1];
			
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Get page sizes
				var pagesize = getPageSize();
				$('.lightbox').css({
					width:		pagesize[0],
					height:		pagesize[1]
				});
			});
			
			
			$.ajax({
				type: "POST",
				url: "/js/references.php",
				dataType: "html",
				data: {x: x, y: y},
				success: function(html){
					$('body').append(html);
					$('p.close a').click(
						function()
						{
							$('.lightbox').remove();
							$('.lb-wrap').remove();
							return false;
						}
					);
				}
			});
			return false;
		}
	);
	
}
function testimonials()
{
			
	$('a.testimonials').click( 
		function()
		{
				pagesize = getPageSize();
				x = pagesize[0];
				y = pagesize[1];
			
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Get page sizes
				var pagesize = getPageSize();
				$('.lightbox').css({
					width:		pagesize[0],
					height:		pagesize[1]
				});
			});
			
			
			$.ajax({
				type: "POST",
				url: "/js/testimonials.php",
				dataType: "html",
				data: {x: x, y: y},
				success: function(html){
					$('body').append(html);
					$('p.close a').click(
						function()
						{
							$('.lightbox').remove();
							$('.lb-wrap').remove();
							return false;
						}
					);
				}
			});
			return false;
		}
	);
	
}



		function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
function mainGallery_initCallback(carousel) {
	
	jQuery('ul#gallery_scroll li a').bind('click', function(){
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text().replace(/0/,'')));
		return false;
	});
};

$(document).ready(function(){
//	toggleSearch();
//	toggleGalleryScroll();
	toggleTidbits();
	//checkDates();
	//resultsFilter();
	
			
	references();
	testimonials();
	
    $("#gallery_scroll_image_wrap").cycle();

	$('p.close_pulldown').click( function()
	{
		$(this).parent().slideUp(1000);
		return false;
	});
	
	$('#drop_nav').tabs({ fx: { height: 'toggle' }, selected: null, unselect: true });
	$('#secondary_nav').tabs({ fx: { height: 'toggle' } });
	
	$('#pan-gallery a.img').lightBox();
	$('#pan-gallery a.img img').css({opacity: '.5'});
	$('#pan-gallery a.img img').mouseover( function(){
		$(this).css({opacity: '1'});
	});
	$('#pan-gallery a.img img').mouseout( function(){
		$(this).css({opacity: '.5'});
	});
	
	selectPackages();
});