$(document).ready(function() {
	$('#c_email').focus(function() {
			if ($.trim(this.value) == 'email'){   
					this.value = '';   
			}   
	});
	$('#c_email').blur(function() {   
			if ($.trim(this.value) == ''){   
					this.value = 'email';   
			}
	});
	
	$('#c_message').focus(function() {
			if ($.trim(this.value) == 'message'){   
					this.value = '';   
			}   
	});
	$('#c_message').blur(function() {   
			if ($.trim(this.value) == ''){   
					this.value = 'message';   
			}
	});
	
	jQuery.validator.addMethod("defaultInvalid", function(value, element) { 
	 switch (element.name) { 
		case "c_email":
		 if (element.value == "email") 
				return false; 
		 else
			return true;
		break;
		case "c_message":
		 if (element.value == "message") 
				return false; 
		 else
			return true;
		break;

	 } 
	});
	
	$('#contact-ty').hide();
													 
	$("#c-form").validate({
		rules: {
				c_email: { required: true, email: true, defaultInvalid: true },
				c_message: { required: true, defaultInvalid: true }
				},
				
		messages: {
				c_email: "",
				c_message: ""
				},
				
				//email=csteman@shaw.ca&message=testing&j=true

		submitHandler: function(form) {
				var fdata = 'email=' + $('#c_email').val() +
				'&message=' + $('#c_message').val() +
				'&j=true';

				$.ajax({
						url: '../php/send.php',
						data: fdata,
												type: 'post',
												success: function (html) { 
								$('#c_email').val('');
								$('#c_message').val('');
								$('#contact-ty').html(html);
								$('#contact-form').fadeOut('normal', function(){ 
											$('#contact-ty').fadeIn('normal');
											}); } 
											});

				}
		});

								 
	$('#banner').after('<div id="banner-nav">');
	
	$('#banner').cycle({
			fx:       'scrollHorz',
			timeout: 5000,
			//easing:  'backinout',
			pager:  '#banner-nav'
	});
	
	
	
	$('#portfolio li').each(function(index) {
		//var group = 'group_' + $(this).parent().index() + '_' + $(this).index();
		var group = 'group_' + $(this).parent().index();
		$(this).find('a').colorbox({rel:group});
	});
	
	$("#main-nav li a,.btn-quote").click(function() {
		$("#main-nav li a").removeClass("active");
		$(this).addClass("active");
		
		$("body").stop().scrollTo($(this.hash), 1000, {offset: ($(this).parent().index() * 10) + 2 + -120});
		return false;
	});
	
	if(window.location.hash != "") {
		$("#main-nav li a").removeClass("active");
		$('#main-nav li').each(function(index) {
			if($(this).find('a').attr("href")	== '/' + window.location.hash) {
				$(this).find('a').addClass("active");
				$("body").stop().scrollTo(window.location.hash, 1000, {offset: ($(this).index() * 10) + 2 + -120});
			}
		});
	}

});

function selectNav(url) {
	$("#main-nav li a").removeClass("active");
	$('#main-nav li').each(function(index) {
			if($(this).find('a').attr('href') == url)
				$(this).find('a').addClass("active");
	});
}
