// JavaScript Document
jQuery.noConflict();
var loaded_count = 0;
var num_pics     = 0;

jQuery(document).ready(function() {
			
	jQuery(".clear_input").val("");

	// Get the page that we're on
	var page = jQuery("#page_label").html();
	num_pics = 0;
	
	switch (page) {
		case "contact":
			jQuery("#contact_link").addClass('active');	
			loaded_count = 0;
			break;	
		case "about":
			jQuery("#about_link").addClass('active');
			loaded_count = 0;
			break;
		case "pricing":
			jQuery("#pricing_link").addClass('active');
			loaded_count = 0;
			break;							
		case "wedding":
			jQuery("#wedding_link").addClass('active');
			loaded_count = 0;
			num_pics = 9;
			var folder_path = "elements/images/wedding/";
			break;	
		case "children":
			jQuery("#child_link").addClass('active');
			loaded_count = 0;
			num_pics = 35;
			var folder_path = "elements/images/children/";
			break;	
		case "seniors":
			jQuery("#senior_link").addClass('active');
			loaded_count = 0;			
			num_pics = 21;
			var folder_path = "elements/images/seniors/";			
			break;	
		case "couture":
			jQuery("#couture_link").addClass('active');
			loaded_count = 0;			
			num_pics = 19;
			var folder_path = "elements/images/couture/";			
			break;	
		case "family":
			jQuery("#family_link").addClass('active');
			loaded_count = 0;			
			num_pics = 17;
			var folder_path = "elements/images/family/";			
			break;	
	}
	
	// Set the initial width
	var div_width = 46;
	m = 1;
	
	// Loop through the images to build a random array of the images
	var random_array     = new Array();
	var image_idx_array  = new Array();
	var	rand_num         = 1;
    var numLow           = 1;
    var numHigh          = num_pics;
	var adjustedHigh     = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
	
	for (var i = 1; i <= num_pics; i++) {
		
		while (jQuery.inArray( rand_num, image_idx_array ) != -1) {
			// Get a random number
			rand_num = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
		}
		
		image_idx_array[i] = rand_num;
	}
	
	// Loop through all of the images that need to be uploaded
	for (var i = 1;i<=num_pics;i++) {
		var img = new Image();
		jQuery(img).attr('id',image_idx_array[i]);
		jQuery(img).load(function () {
			// Create the new div and set the div attributes
			var newdiv = document.createElement('div');
			newdiv.setAttribute('class', "image_holder");
			newdiv.setAttribute('id', "image_holder_" + jQuery(this).attr('id'));

			jQuery('#photo_section').append(newdiv);
			
			// Add the picture to the right div
			jQuery('#image_holder_' + jQuery(this).attr('id')).append(this);
			
			// Get this width to add to the total
			div_width += (11+30+ jQuery(this).attr('width'));
			//console.log("Width= " + div_width + " This width=" + jQuery(this).attr('width') + " #" + m++);
			
			// Increment the total count loaded
			loaded_count++;
			//console.log("Loaded count: " + loaded_count);
			if (loaded_count == num_pics) {
				jQuery('#loader').fadeOut('slow');
				jQuery('#loader').addClass('hidden');
				jQuery('#photo_section').width(div_width);
				jQuery('#photo_section').fadeIn(1000);
			}
		}).attr('src', folder_path + image_idx_array[i] + '.jpg');
	}	
});

function validateForm(){
	var name = document.getElementById("contact_name").value;
	var email = document.getElementById("contact_email").value;
	var phone = document.getElementById("contact_phone").value;
	var message = document.getElementById("contact_message").value;	
	
	var correct = true;
	
	if (name == ""){
		//document.getElementById("req_name").style.display = "inline";
		correct = false;
	}
	//else 
		//document.getElementById("req_name").style.display = "none";
		
	if (email == ""){
		//document.getElementById("req_email").style.display = "inline";		
		correct = false;
	}
	//else
		//document.getElementById("req_email").style.display = "none";		
		
	if (message == ""){
		//document.getElementById("req_comment").style.display = "inline";
		correct = false;				
	}
	//else 
		//document.getElementById("req_comment").style.display = "none";
		
	if (!correct){
		return false;
	}	
	
	//Submit the input form
	document.getElementById('the_form').submit();
	
	//Let the user know we'll get back with them
	alert("Thanks for the note.  I'll get back with you as soon as I can");
}
