var $j = jQuery.noConflict();

$j(document).ready(function(){	
	$j('a[rel=lightbox]').lightBox();
	
	// slideshow
		$j('#slideshow').cycle({
			fx: 'fade',
			speed: 5000,
			pause: 1
		});
	
	// form validations
	$j("#contactPageContactForm").validate({
        rules: {
          	name: { required: true, minlength: 2},
          	email: { required: true, email: true},
        	confirmEmail: { required: true, email: true, equalTo: "#email" },
        	comment: "required",
    		attention : "required",
    		captcha: {
    			required: true,
    			digits: true
    		}
        },
        messages: {
        	name: "Please enter your name.", 
        	email: "Please enter a valid email.",
        	confirmEmail: {
        		required: "Please confirm your email address",
				equalTo: "Your emails do not match."
        	},
        	attention: "Please choose a recipient.",
          	comment: "Please enter a comment.",
          	captcha: "The answer is incorrect."
        }
      });


	
	
	// navbar focus function
	$j("#nav ul.navigation a").click(function(){
		var currentPage = $j(this).attr("href");
		$j("#nav ul.navigation li:first").removeClass('current');
		$j(this).parent().addClass('current');
	});	
	
	
	
	$j("input").focus(function() {
		$j(this).parent().addClass("curFocus")
		});
		
		$j("input").blur(function() {
		$j(this).parent().removeClass("curFocus")
		});

		$j("select").focus(function() {
		$j(this).parent().addClass("curFocus")
		});
		
		$j("select").blur(function() {
		$j(this).parent().removeClass("curFocus")
		});


	// function to display maps from sidebar link into main content area
		$j("#locationsList li a:not(.toggle)").click(function() {
			// get clicked link class attribute
			var mapToGet = $j(this).attr("class");
			
			// fade out anything in the pageContent div
			$j("#pageContent").children().fadeOut('slow');
			
			// append a new div called map into the pageContent div for easy styling
			$j("#pageContent").append('<div id="map"></div>')
				.children("#map").hide()			
				.load('locations.php iframe.'+ mapToGet, function()
            	    {
            	    	$j("#map").fadeIn("slow");
            	    });
   			return false;
			});
			
			
			
		// contact us sidebar function
			$j("div.contactOption h6 a.locationsContent").click(function(){
				// fade out anything in the pageContent div
				$j("#pageContent").children().fadeOut('slow');
				
				$j("#pageContent").load('locations.php #locationContent', function(){
            	    	$j("#locationContent").fadeIn('slow');
            	    	$j("div.maps").hide();
            	    	$j("div.location li a").click(function() {
							// ger id attribute of clicked link and store in variable
							var mapID = $j(this).attr("class");
				
							// slide the map down 
							$j("#" + mapID).slideToggle("slow");
							return false;				
						});
            	    });
   			return false;
			});
			
			
			
			$j("div.contactOption h6 a.contactContent").click(function(){
				// fade out anything in the pageContent div
				$j("#pageContent").children().fadeOut('slow');
			
				$j("#pageContent").load('contactus.php #contactContent', function(){
            	    	$j("#contactContent").fadeIn("slow");
            	    	// form validations
						$j("#contactPageContactForm").validate({
					        rules: {
					          	name: { required: true, minlength: 2},
					          	email: { required: true, email: true},
					        	confirmEmail: { required: true, email: true, equalTo: "#email" },
					        	comment: "required",
					    		attention : "required",
					    		captcha: {
					    			required: true,
					    			digits: true
					    		}
					        },
					        messages: {
					        	name: "Please enter your name.",
					        	email: "Please enter a valid email.",
					        	confirmEmail: {
					        		required: "Please confirm your email address",
									equalTo: "Your emails do not match."
					        	},
					        	attention: "Please choose a recipient.",
					          	comment: "Please enter a comment.",
					          	captcha: "The answer is incorrect."
					        }
					      });
            	    });
   			return false;
			});
		
			
			
			
		// locations list toggle function
			$j('.storeList').hide();
			$j("#locationsList ul li h4 a").click(function(event) {
				
				// ger id attribute of clicked link and store in variable
				var listID = $j(this).attr("id");
				
				// toggle unordered list with the class matcing previous ID and change background image to down arrow
				$j('.' + listID).slideToggle(1000);
				$j(this).toggleClass("sidebarHeaderBackgroundOpen");
				
				
				return false;
			});

});	

