//Script for the Newsletter fields
function remName(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } }
function chkName(a, b){ if(a.value==''){ a.value=b; }else{ a.value=a.value; } }

$(window).load(function() {
    $('#slider').nivoSlider({
    	directionNav: false,
    	controlNav: false,
    	effect: 'random',
    	pauseTime: 9000,
    	pauseOnHover: true
    });
    
    
    
    $('#sliderport').nivoSlider({
    	directionNav: true,
    	controlNav: false,
    	effect: 'fade',
    	pauseTime: 6000,
    	pauseOnHover: true
    });
    
    
});


$(document).ready(function() {
	/*$('#consult .consult span').live('click', function(){
		if($('#consult .consult span.line1').html() == 'Click Here For A'){
			$('#request').slideDown();
			$('#request > form').show('slow');
			$('#consult .consult span.line1').html('Click To Close');
			$('#consult .consult span.line2').html('');
		}
		else{
			$('#request').fadeOut();
			$('#consult .consult span.line1').html('Click Here For A');
			$('#consult .consult span.line2').html('Free Consultation!');
		}
		
	});*/
	
	$('.clickrequest').live('click', function(eve) {
		eve.preventDefault();
		$(window).scrollTop(0);
		/*$('#request').slideDown();
		$('#request > form').show('slow');
		$('#consult .consult span.line1').html('Click To Close');
		$('#consult .consult span.line2').html('');*/
	});
	
	$('.processlink').live('click', function(eve) {
		eve.preventDefault();
		id = $(this).attr('title');
		
		$('.processlink').each(function(){
			if($(this).attr('title') == id){
				$(this).addClass('active');
			}
			else{
				$(this).removeClass('active');
			}
		});
		
		$('.theprocess').each(function(){
			if(id == $(this).attr('id')){
				$(this).fadeIn('slow');
			}
			else{
				$(this).fadeOut();
			}
		});
	});
	
	var pathname = window.location.pathname;
	var chars = pathname.lastIndexOf('/') + 1;
	var link = pathname.slice(chars);
	
	if(link != ''){
		$('#nav a').each(function(){
			if($(this).attr('href') == link){
				$(this).parent('li').addClass('active');
			}
			else{
				$(this).parent('li').removeClass('active');
			}
		});
	}
	else{
		$('#nav a').each(function(){
			if($(this).attr('id') == 'home'){
				$(this).parent('li').addClass('active');
			}
			else{
				$(this).parent('li').removeClass('active');
			}
		});
	}
	
	/*$('#nav ul.topnav > li').hover(function() {
	
		if($(this).hasClass('par')){
			//Following events are applied to the subnav itself (moving subnav up and down)
			$('> ul', this).slideDown(800).show(); //Drop down the subnav on click
			$('> a', this).addClass('parent');
			$('> a', this).addClass('active');
			
			$('#nav ul.topnav > li').hover(function() {
			}, function(){
				$('> ul', this).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				$('> a', this).removeClass('parent');
				$('> a', this).removeClass('active');
			});
			
		}
	},function () {
		
		}
	);
	
	$('#nav li').hoverIntent(function() {
		if($(this).hasClass('par')){
			$('> a', this).addClass('parent');
			$('> a', this).addClass('active');
		  	$(this)
			    .find('ul')
			    .stop(true, true)
			    .slideDown('800');
		}
	}, function() {
	  	$(this)
		    .find('ul')
		    .stop(true,true)
		    .fadeOut('fast');
		$('> a', this).removeClass('parent');
		$('> a', this).removeClass('active');
	});*/
	
	$('.testimonials').cycle({
		timeout:         9000,
		speed:  1000,
		fx: 	'fade'
	});
	
//	$.validator.addMethod("notdefault", function(value, element) {
//		var arr = [ 'Name', "Email", "Phone", "How can we help?" ];
//	    var test = jQuery.inArray(value, arr);
//	    
//	    if(test == '-1'){
//	    	return true;
//	    }
//	    else{
//	    	return false;
//	    }
//    }, "Please enter a value.");
//	
	//Request form homepage
//	$("#requestconsult").validate({
//		rules: {
//			'data[Lead][first_name]': { 
//				required: true, 
//				minlength: 3,
//				notdefault: true
//			},
//			'data[Lead][email]': { 
//				required: true, 
//				email: true,
//				notdefault: true
//			},
//			'data[Lead][phone_work]': { 
//				required: true, 
//				notdefault: true
//			}
//		},
//		messages: {
//			'data[Lead][first_name]': "Please enter your name",
//			'data[Lead][email]': {
//				required: "Please provide a email",
//				email: "Please enter an valid email"
//			},
//			'data[Lead][phone_work]': "Please enter your phone number"
//		}
//		
//	});
	
	
	
	$('.requestconsult').live('click', function(eve) {	
		
		var url = $('#requestconsult').attr('action');
		var valid = true;
		//alert(url);
		//return false;
		
		if($('#LeadFirstName').val() == 'Name' || $('#LeadFirstName').val() == '') {
          	alert('Please enter your name');
          	valid = false;
	    }
	    
	    if($('#LeadPhoneWork').val() == 'Phone' || $('#LeadPhoneWork').val() == '' || $('#LeadPhoneWork').val() == '123456') {
	      	alert('In order to serve you better, please enter your phone number. We are committed to your privacy.');
	      	valid = false;
	    }
	    
	    if(!validateEmail($('#LeadEmail').val())) {
	      	alert('Please enter a valid email');
	      	valid = false;
	    }
		
		if(valid){
			$.post(url, $(this).parents('form:first').serialize());
			$("#request > form").slideToggle();
			$("#request .thanksmessage").fadeIn().html('<span style="color: #ffffff"><br/>Thank you for your submission. One of our representatives will be with your shortly.</span>');
			$('#LeadFirstName').val('Name');
			$('#LeadPhoneWork').val('Phone');
			$('#LeadEmail').val('Email');
			$('#LeadDescription').val('How can we help?');
			window.setTimeout('$("#request > form").slideToggle();', 5500);
			window.setTimeout('$("#request .thanksmessage").fadeOut();', 5000);
		}
		
		//window.setTimeout("$('#consult .consult span.line1').html('Click Here For A');", 5500);
		//window.setTimeout("$('#consult .consult span.line2').html('Free Consultation!');", 5500);
		//window.setTimeout("$('#request .thanksmessage').hide();", 5500);
		return false;
		
	});
	
	$('#contactsubmit').live('click', function(eve) {	
		
		if($('#WebDesignServicesName').val() == 'Name' || $('#LeadFirstName').val() == '') {
	      	alert('Please enter your name');
	      	eve.preventDefault();
	    }
	    
	    if($('#WebDesignServicesPhoneWork').val() == 'Phone' || $('#WebDesignServicesPhoneWork').val() == '' || $('#WebDesignServicesPhoneWork').val() == '123456') {
	      	alert('In order to serve you better, please enter your phone number. We are committed to your privacy.');
	      	eve.preventDefault();
	    }
	    
	    if(!validateEmail($('#WebDesignServicesEmail').val())) {
	      	alert('Please enter a valid email');
	      	eve.preventDefault();
	    }
		
	});
	
	function validateEmail(txtEmail){
	   var a = txtEmail;
	   var filter = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{1,4}$/;
	    if(filter.test(a)){
	        return true;
	    }
	    else{
	        return false;
	    }
	}
	
	function closerequest(){
		$('#request').fadeOut();
		$('#consult .consult span.line1').html('Click Here For A');
		$('#consult .consult span.line2').html('Free Consultation!');
	}
	
});

