$.validator.setDefaults({
	submitHandler: function(form) {
		$("#loading").html('<img src="images/icons/ajax-loader-bar.gif" />');
		$("#message").html('');
		$("input[type=submit]").attr('disabled', true);

		var txtName = $('#txtName').val();
		var txtContact = $('#txtContact').val();
		var txtEmail = $('#txtEmail').val();
		var txtMessage = $('#txtMessage').val();
		var txtCaptcha = $('#txtCaptcha').val();

		$("input[type=text]").attr('disabled', true);
		$("textarea").attr('disabled', true);

		$.ajax({ type : "POST", url : "ajax.php", dataType : 'json',
			data : {
				"txtName":txtName,
				"txtContact":txtContact,
				"txtEmail":txtEmail,
				"txtMessage":txtMessage,
				"txtCaptcha":txtCaptcha,
				"action":"sendEmail"
			},
			success : function(data){
				$("#loading").html('');
				if (data.error==false) {
					$('#message').html('<div class="msg_success">'+data.success+'</div>');
					$("input[type=text]").val("");
					$("textarea").val("");
				} else {
					$('#message').html('<div class="msg_error">'+data.error+'</div>');
					$("#txtCaptcha").val("");
				}
				var timestamp = new Date().getTime();
				var img_src = $("#captcha").attr('src');
	     		$("#captcha").attr('src',img_src+'?'+timestamp);
				$("input[type=submit]").attr('disabled', false);
				$("input[type=text]").attr('disabled', false);
				$("textarea").attr('disabled', false);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert(XMLHttpRequest.statusText);
				alert(errorThrown);
			}
		});
		//form.submit();
	}
});
	$(document).ready(function(){
		//$("img, div, p, ul, li, span").lazyload();

		$("#content").supersized({

			// Functionality
			fit_landscape          :   0,
			slide_interval          :   3000,		// Length between transitions
			transition              :   1, 			// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
			transition_speed		:	700,		// Speed of transition

			// Components
			slide_links				:	'blank',	// Individual links for each slide (Options: false, 'num', 'name', 'blank')
			slides 					:  	[			// Slideshow Images
												{image : 'images/img01.jpg' },
												{image : 'images/img02.jpg' }
										]

		});

		var actionAdd = function() {
			if ($("#hdnAction").val()=="add")
				return true;
			else
				return false;
		}

		$("#form").validate({
			debug: true,
			errorElement: "span",
			errorClass: "invalid",
			rules: {
				txtName: {required: true},
				txtContact: {required: true},
				txtEmail: {required: true, email:true},
				txtMessage: {required: true},
				txtCaptcha: {required: true}
			},
			messages: {
				txtName: {required: "Please enter name."},
				txtContact: {required: "Please enter contact."},
				txtEmail: {required: "Please enter email.", email: "Please enter valid email."},
				txtMessage: {required: "Please enter message"},
				txtCaptcha: {required: "Please enter captcha."}
			}
		});

		$(".box_content").hover(function() {
			$(this).css('filter', 'alpha(opacity=40)');
			$(this).stop().fadeTo("slow", 0.9);
			$(this).css('z-index','5');
		}).mouseleave(function() {
			$(this).css('filter', 'alpha(opacity=90)');
			$(this).stop().fadeTo("slow", 0.4);
			$(this).css('z-index','0');
		  });

		//$("#box_website").fadeIn(1000, function(){
			//$("#box_ecomm").fadeIn(1000, function(){
		  		//$("#box_cms").fadeIn(1000, function(){
		    		//$("#box_webapps").fadeIn(1000, function(){
		    			$("#box_intro").fadeIn(1000, function(){
			    		});
		    		//});
		   		//});
		 	//});
		//});

		$('#name_card').hover(function() {
	      $(this).stop().animate({ width: "874px" }, 500, 'easeInOutExpo');
	      $('#overlay').stop(true, true).fadeIn();
	    }, function() {
	      $(this).stop().animate({ width: '437px' }, 800, 'easeInOutExpo');
	      $('#overlay').stop(true, true).fadeOut(1000);
	    });

	    $('.nav_contact').click(function() {
	    	$('#name_card').fadeOut('fast',function() {
	    		$(this).css('width','437px').delay(500).fadeIn();
	    	});
		    $('#overlay').fadeOut(1000);
	    });

		var xaxis = function() {
			xPosition = ($(window).scrollLeft());
			if (xPosition>1000) {
				$('#supersized').fadeOut('slow');
				$('#bottom_bg').fadeIn('slow');
				$('#top_bg').fadeIn('slow');
			} else {
				$('#supersized').fadeIn('slow');
				$('#bottom_bg').fadeOut('slow');
				$('#top_bg').fadeOut('slow');
			}
		}
		$(window).bind("scroll",xaxis);
		$(xaxis);

		var highlightButton = function() {
			xPosition = ($(window).scrollLeft());
			if (xPosition>1000 && xPosition<3000) {
				$('.nav').each(function() {
					id = $(this).attr('id');
					id = id.replace('nav_','');
					$('#nav_'+id).html('<img src="images/'+id+'_btn.png" />');
				});
				$('#nav_services').html('<img src="images/services_btn_hover.png" />');
			} else if(xPosition>3000 && xPosition<5000) {
				$('.nav').each(function() {
					id = $(this).attr('id');
					id = id.replace('nav_','');
					$('#nav_'+id).html('<img src="images/'+id+'_btn.png" />');
				});
				$('#nav_portfolio').html('<img src="images/portfolio_btn_hover.png" />');
			} else if(xPosition>5000) {
				$('.nav').each(function() {
					id = $(this).attr('id');
					id = id.replace('nav_','');
					$('#nav_'+id).html('<img src="images/'+id+'_btn.png" />');
				});
			} else {
				$('.nav').each(function() {
					id = $(this).attr('id');
					id = id.replace('nav_','');
					$('#nav_'+id).html('<img src="images/'+id+'_btn.png" />');
				});
				$('#nav_home').html('<img src="images/home_btn_hover.png" />');
			}
		}
		$(window).bind("scroll",highlightButton);
		$(highlightButton);

		var offset = -(($(window).width() - $("ul#scroll li").width())/2);
		$.localScroll({offset:{left:offset},reset:true,queue:false,hash:false,axis:'x',duration:1000,easing:'easeInOutExpo'});

		$('.lightbox').lightbox();

		$('#footer').hover(function() {
			$(this).css('z-index', '3');
		}, function() {
			$(this).css('z-index', '1');
		});

		var autoresize = function() {
			var ideal = 830;
			var windowHeight = $(window).height();

			
				var variance = windowHeight/(windowHeight-$('ul#scroll li#service').height());
				$('ul#scroll li#service').css('top', (windowHeight*(0.20/(variance)))+'px');

				var variance = windowHeight/(windowHeight-$('ul#scroll li#portfolio').height());
				$('ul#scroll li#portfolio').css('top', (windowHeight*(0.4/(variance)))+'px');
	
				var variance = windowHeight/(windowHeight-$('ul#scroll li#contact').height());
				$('ul#scroll li#contact').css('top', (windowHeight*(0.4/(variance)))+'px');
				
				var variance = windowHeight/(windowHeight-$('ul#scroll li#contact').height());
				$('ul#scroll li#contact').css('top', (windowHeight*(0.4/(variance)))+'px');
				
				var variance = windowHeight/(windowHeight-$('#box_intro').height());
				$('#box_intro').css('top', (windowHeight*(0.6/(variance)))+'px');
			//var variance = ideal-windowHeight;
			//$('#box_website, #box_ecomm, #box_webapps').css('top', -(variance/2)+'px');
		};
		$(window).resize(autoresize);
		$('img').load(function() {
			$(autoresize);
		});
    });
