$(document).ready(function()
{
	if ( !Modernizr.textshadow )
	{
		/*$('#content p a').textshadow('0 1px 1px rgba(0, 0, 0, 0.5)');*/
		$('footer p a').textshadow('0 2px 2px rgba(0, 0, 0, 1.0)');
		$('nav#sub li a').textshadow('0 2px 2px rgba(0, 0, 0, 0.8)');
		/*$('nav#sub li a:hover').textshadow('0 1px 1px rgba(0, 0, 0, 0.8)');*/
	}
	
	if ( $("#description").length )
	{
		$("#content li div").mouseover(function(event)
		{
			event.stopImmediatePropagation();
			$(this).css("background-color","#e1d6c2");
			var nId = $(this).parent().attr("id").substring(1);
			$("#description p").css("background-image", "url('/img/bg-product-catalogs-b" + nId + ".png')");
			$("#d" + nId).show();
		});
		
		$("#content li div").mouseout(function(event)
		{
			event.stopImmediatePropagation();
			$(this).css("background-color","transparent");
			var nId = $(this).parent().attr("id").substring(1);
			$("#description p").css("background-image", "url('/img/bg-product-catalogs-b0.png')");
			$("#d" + nId).hide();
		});
	}

	if ( $('#orderform').length )
   	{
   	   	var options = {
       		//target:        '#output1',   // target element(s) to be updated with server response
       		beforeSubmit:  validateForm,  // pre-submit callback
       		success:       showResponse,  // post-submit callback
			resetForm: true

       		// other available options: 
       		//url:       url         // override for form's 'action' attribute
       		//type:      type        // 'get' or 'post', override for form's 'method' attribute
       		//dataType:  null        // 'xml', 'script', or 'json' (expected server response type)
       		//clearForm: true        // clear all form fields after successful submit
       		//resetForm: true        // reset the form after successful submit

       		// $.ajax options can be used here too, for example:
       		//timeout:   3000
   		}

   		// bind form using 'ajaxForm'
   		$('#orderform').ajaxForm(options);
	}
	
	if ( $('#gallery').length )
   	{
   		// hide the captions
   		$("#caption div").hide();
   		$("#caption0").show();

   		var nCurrentPhoto = 0;
   		var nIndex = 100;

   		$("#thumbs div a").click(function(event)
		{
			var nPhoto = $(this).parent().attr("id").substring(5);

			if ( nPhoto == nCurrentPhoto ) return;

			$("#caption" + nCurrentPhoto).fadeOut();
			$("#caption" + nPhoto).fadeIn();

			$("#large" + nPhoto).hide();
			$("#large" + nPhoto).css("z-index", nIndex);
			$("#large" + nPhoto).fadeIn();
			nIndex++;
			nCurrentPhoto = nPhoto;
		});   	
   	}
   	
   	if ( $('.staff_landing').length )
   	{
   		if ( window.location.hash )
   		{
   			var sCurrentId = window.location.hash;
   		}
   		else
   		{
   			var sCurrentId = "#alabama";  
   		}
   		
   		$("#content ul li a").each(function()
   		{
    		if ( $(this).attr("href") == sCurrentId )
    		{
    			$(this).parent().addClass("on");
    		}
  		});
  		
  		$(sCurrentId).show();

   		$("#content ul li a").click(function(event)
   		{
   			$("#content ul li").removeClass("on");
   			var sId = $(this).attr("href");
   			$(this).parent().addClass("on");
   			$(sCurrentId).hide();
   			$(sId).show();
   			sCurrentId = sId;   			   		
  		});
	}
});


// ====== functions ======

function viewCatalog(sCatalog)
{
	return window.open(sCatalog,'catalog','width=900,height=600,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0');
}

// pre-submit callback
function validateForm(formData, jqForm, options)
{
    var isComplete = true;
    
 	if ( ( $("#catalog1hc").val() == 0 ) && ( $("#catalog1cd").val() == 0 ) && ( $("#catalog2hc").val() == 0 ) && ( $("#catalog2cd").val() == 0 ) && ( $("#catalog3hc").val() == 0 ) && ( $("#catalog3cd").val() == 0 ) && ( $("#catalog4hc").val() == 0 ) && ( $("#catalog4cd").val() == 0 ) && ( $("#catalog5hc").val() == 0 ) && ( $("#catalog5cd").val() == 0 ) && ( $("#catalog6hc").val() == 0 ) && ( $("#catalog6cd").val() == 0 ) && ( $("#catalog7hc").val() == 0 ) && ( $("#catalog7cd").val() == 0 ) )
 	{
 		alert("Please indicate the quantity for each catalog you'd like to order.");
 		isComplete = false;
 	}
 	else
 	{
 		sAlert = "Please fill in the following required fields:\n";

 		if ( $("#name").val() == "" )
 		{
 			sAlert += "- Name\n";
 			isComplete = false;
 		}
 		
 		if ( $("#title").val() == "" )
 		{
 			sAlert += "- Job Title\n";
 			isComplete = false;
 		}

		if ( $("#company").val() == "" )
 		{
 			sAlert += "- Company Name\n";
 			isComplete = false;
 		}

 		if ( $("#address1").val() == "" )
 		{
 			sAlert += "- Address\n";
 			isComplete = false;
 		}
 		
 		if ( $("#city").val() == "" )
 		{
 			sAlert += "- City\n";
 			isComplete = false;
 		}

		if ( $("#state").val() == "" )
 		{
 			sAlert += "- State\n";
 			isComplete = false;
 		}
 		
 		if ( $("#zip").val() == "" )
 		{
 			sAlert += "- Zip/Postal Code\n";
 			isComplete = false;
 		}
 		
 		if ( $("#country").val() == "" )
 		{
 			sAlert += "- Country\n";
 			isComplete = false;
 		}

		if ( $("#email").val() == "" )
 		{
 			sAlert += "- E-mail Address";
 			isComplete = false;
 		}
 		
 		if ( !isComplete ) alert(sAlert);
 	}
 	
	return isComplete;
}
 
// post-submit callback
function showResponse(responseText, statusText, xhr, $form)
{
    /*
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.');
    */
    if ( statusText == "success" ) $('#thankyou').fadeIn();
}
