$(document).ready(function(){
   
   /*
   *	Used to scroll to a specific position.
   *	Edit the variables below to adjust speed and positioning
   */
	var scrollDuration = 500; // 1000 = 1 second
	var scrollGap = 0; // in Pixels, the gap left above the scroll to point
	
	$('a[href^=#]').click(function() 
	{
		if (
			location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && 
			location.hostname == this.hostname
			) 
		{
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) 
			{
				var targetOffset = $target.offset().top - scrollGap;
				$('html,body').animate
					(
					{scrollTop: targetOffset}, 
					scrollDuration
					);
				
				// Remove all "active" classes
				$("a").removeClass("active");
				
				// Set "active" class on clicked item
				$(this).addClass("active");
								
				return false;
			}
		}
	});
	
	
	/** login link */
	
	$('a#login-link, a#login-close').click(function() {
		$('#login').slideToggle();
		return false;
	});
	
	
	
	/** jQuery Lightbox Init / settings */
	
	// initiate Lightbox
	$('.gallery a[href$=".jpg"]').lightbox({
		strings: {
				help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery',
				prevLinkTitle: 'previous image',
				nextLinkTitle: 'next image',
				prevLinkText:  '&laquo; Previous',
				nextLinkText:  'Next &raquo;',
				closeTitle: 'close image gallery',
				image: 'Image ',
				of: ' of ',
				download: 'Download'
			},
		fileBottomNavCloseImage: '/js/lightbox/images/close.gif'
	});
	
	
	// Thumbnail hover
	$('.gallery .thumb').hover(function(){
		$(this).stop().animate({ opacity: "0.8"}, 100);
	}, function() {
		$(this).stop().animate({ opacity: "1"}, 200);
	});
	//
	
	
	
	/** jCaoursel Lite Init / settings */
	
	// Slider navigation expand and contract
	var extraPadding = '15px';
	$('.slider a.prev').hover(function() {
		$(this).animate({ paddingLeft : "+="+extraPadding }, 100);        
	}, function() {
		$(this).animate({ paddingLeft : "-="+extraPadding }, 100);
	});
	$('.slider a.next').hover(function() {
		$(this).animate({ paddingRight : "+="+extraPadding }, 100);       
	}, function() {
		$(this).animate({ paddingRight : "-="+extraPadding }, 100);  
	});
	
	
	


	/** Contact Form */
	
	// Contact form, click to remove text feature
	$('#cf_name,#cf_email,#cf_message').each(function() {
		var original_txt = this.value;
		
		$(this).focus(function() 
		{
			if(this.value == original_txt) { this.value = ''; }
		});
		$(this).blur(function() 
		{
			if(this.value == '') { this.value = original_txt; }
		});
	});
	
	// contact form validation
	var hasChecked = false;
	$("#cf_submit").click(function () { 
		hasChecked = true;
		return checkForm();
	});
	$("#cf_name,#cf_email,#cf_message").live('change click', function(){
		if(hasChecked == true)
		{
			return checkForm();
		}
	});
	function checkForm()
	{
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if($("#cf_name").val() == '') {
			hasError = true;
		}
		if($("#cf_email").val() == '') {
			hasError = true;
		}else if(!emailReg.test( $("#cf_email").val() )) {
			hasError = true;
		}
		if($("#cf_message").val() == '') {
			hasError = true;
		}
		if(hasError == true)
		{
			$("#contact-form-errror").fadeIn();
			return false;
		}else{
			return true;
		}
	}
	// end contact form validation
	
	

	//	********************************
	//	Add additional functions here...
	//	********************************
	
	
	
	// Simple style switcher for live demo - you can remove this
	$(".switch-to-dark").click(function() {
	   $("#themeCSS").attr("href", "css/colors-dark.css");
	   return false;
	 });
	$(".switch-to-default").click(function() {
	   $("#themeCSS").attr("href", "css/colors-default.css");
	   return false;
	 });
	//
	
	
}); // end document.ready

