$(document).ready(function () {

	/* --------------------------------------- */
	/* -----  Load home.php On Page Load ----- */
	/* --------------------------------------- */

	$('div.page-home').slideDown(450);
	
	
	/* --------------------------------------- */
	/* -----     'Client Login' Popup    ----- */
	/* --------------------------------------- */
	
	$('a.client-login').click(function() {
		
		$('.popup-background').css({ opacity: 0.6 }).fadeIn(600);
		
		$('.client-login-popup').fadeIn(600);
	
	});
	
	$('div.client-login-popup div.close, div.popup-background').click(function() {
		
		$('.popup-background').fadeOut(300);
		
		$('.client-login-popup').fadeOut(300);
	
	});
	
	
	var loginEmail    = $('input.login-email');
		
	var loginPassword = $('input.login-password');
	
	var loginButton   = $('li.login-button');
		
	var loginForm     = $('form.client-login');
	
	$(loginButton).click(function () {
		
		if ( loginEmail == '' || loginPassword == '' ) {
		
			$('div.login-alerts div.code-red').slideDown(200).delay(2500).slideUp(200);
		
		} else {
		
			alert('lol');
		
		}
	
	});
	
	
	/* --------------------------------------- */
	/* -----    Font Incrementation      ----- */
	/* --------------------------------------- */
	
	var defaultFontSize = 12;
    
    $('a.bigger').click(function () {
        
        if ( defaultFontSize < 18 ) {
        
            $('p').css({ 'font-size' : defaultFontSize++ + 'px' });
            
        } else {
            
            return false;
            
        }
        
    });
    
    $('a.smaller').click(function () {
        
        if ( defaultFontSize > 8 ) {
        
            $('p').css({ 'font-size' : defaultFontSize-- + 'px' });
            
        } else {
            
            return false;
            
        }
        
    });
    
    $('a.normal').click(function () {
        
        $('p').css({ 'font-size' : '12px' });
		
		var defaultFontSize = 12;
        
    });
	
	
	/* --------------------------------------- */
	/* -----      Navigation Tabs        ----- */
	/* --------------------------------------- */
	
	pageTitle = document.title;
	
	$("li.home").click(function() {
			
		$("li.web-design, li.our-portfolio, li.web-hosting, li.contact").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.page-our-portfolio, div.page-web-design, div.page-web-hosting, div.page-contact").slideUp(450);
		
		$("div.page-home").delay(600).slideDown(450);
		
		
		document.title = pageTitle;
		
	});
	
	
	$("li.web-design").click(function() {
			
		$("li.home, li.our-portfolio, li.web-hosting, li.contact").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.page-home, div.page-our-portfolio, div.page-web-hosting, div.page-contact").slideUp(450);
		
		$("div.page-web-design").delay(600).slideDown(450);
		
		
		document.title = pageTitle + ' \u203a Website Design';
		
	});
	
	
	$("li.web-hosting").click(function() {
			
		$("li.home, li.web-design, li.our-portfolio, li.contact").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.page-home, div.page-web-design, div.page-our-portfolio, div.page-contact").slideUp(450);
		
		$("div.page-web-hosting").delay(600).slideDown(450);
		
		
		document.title = pageTitle + ' \u203a Website Hosting';
		
	});
	
	
	$("li.our-portfolio").click(function() {
			
		$("li.home, li.web-design, li.web-hosting, li.contact").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.page-home, div.page-web-design, div.page-web-hosting, div.page-contact").slideUp(450);
		
		$("div.page-our-portfolio").delay(600).slideDown(450);
		
		
		document.title = pageTitle + ' \u203a Our Portfolio';
		
	});
	
	
	$("li.contact").click(function() {	
		
		$("li.home, li.web-design, li.our-portfolio, li.web-hosting").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.page-home, div.page-web-design, div.page-our-portfolio, div.page-web-hosting").slideUp(450);
		
		$("div.page-contact").delay(600).slideDown(450);
		
		
		document.title = pageTitle + ' \u203a Get In Touch';
		
	});
	
	
	/* --------------------------------------- */
	/* -----    Website Hosting Form     ----- */
	/* --------------------------------------- */
	
	var companySize 		= $('select.company-size');
	
	var staffCount 			= $('select.staff-count');
	
	var existingWebsite 	= $('select.existing-website');
	
	var hostingStatus 		= $('select.hosting-status');
	
	var websiteType 		= $('select.website-type');
	
	var websiteSystem 		= $('select.system-type');
	
	var payRecurrance 		= $('select.pay-reccurance');
	
	
	$(companySize).change(function () {
		
		if ( $(this).val() == 'small' || $(this).val() == 'medium' || $(this).val() == 'large' ) {
		
			$('tr.people').slideDown(200);
		
		} else if ( $(this).val() == 'personal' ) {
		
			$('tr.people').slideUp(200);
		
		}
	
	});
	
	
	$(existingWebsite).change(function () {
	
		if ( $(this).val() == 'yes' ) {
		
			$('tr.website-hosting').slideDown(200);
		
		} else if ( $(this).val() == 'no' ) {
		
			$('tr.website-hosting, tr.website-type, tr.website-system').slideUp(200);
		
		}
	
	});
	
	$(hostingStatus).change(function () {
	
		if ( $(this).val() == 'yes' ) {
		
			$('tr.website-type').slideDown(200);
		
		}
	
	});
	
	$(websiteType).change(function () {
	
		$('tr.website-system').slideDown(200);
		
	});
	
	
	$(payRecurrance).change(function () {		
		
		$('div.estimate').slideDown(200);
		
		$('div.cost h3').html('lol');
		
		
		if ( $(this).val() == 'monthly' ) {
		
			$('div.cost span').html('per month');
		
		} else {
		
			$('div.cost span').html('per year');
		
		}
	
	});
	
	
	/* --------------------------------------- */
	/* -----   Contact Form Validation   ----- */
	/* --------------------------------------- */
	
	$('li.send-message').click(function() {
		
		var name = $('#name-input').val();
		
		var email = $('#email-input').val();
		
		var subject = $('#subject-input').val();
		
		var phone = $('#phone-input').val();
		
		var message = $('#message-input').val();
		
		if ( name == '' || email == '' || subject == '' || message == '' ) {
			
			$('div.alerts div.code-red').slideDown(200).delay(2500).slideUp(200);
			
		} else {
			
			  //var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
			  
			  var formData = 'name=' + name + '&email=' + email + '&phone=' + phone + '&subject=' + subject + '&message=' + message;
			  
			  $.ajax({
				  
				type: "POST",
				
				url: "_build/_php/process.php",
				
				data: formData,
				
				success: function() {
					
					$('form.get-in-touch').animate({ 'height' : '0' }, 800);
			
					$('div.alerts div.code-green').slideDown(200);
				
				}
			  
			  });
			  
			  return false;
			  
		}
		
	});
	
	$('#phone-input').keypress(function ( event ) {
		
		return ( ( event.which >= 8 ) && ( event.which <= 57 ) ); 
		
	});
	
	$('#email-input').blur(function () {
		
		var at = $('#email-input').indexOf('@');
		
		var dot = $('#email-input').indexOf('.');
		
		if ( ( at == -1 ) && ( dot == -1 ) ) {
			
			alert('This is not a valid e-mail address!');
			
			$(this).focus();
			
		}
		
	});
	
	
	/* --------------------------------------- */
	/* -----        Footer Links         ----- */
	/* --------------------------------------- */
	
	$('a.home').click(function () {
	
		$("li.web-design").removeClass('active');
		
		$("li.our-portfolio").removeClass('active');
		
		$("li.web-hosting").removeClass('active');
		
		$("li.contact").removeClass('active');
		
		
		$(this).addClass('active');
		
		
		$("div.padding").load('_build/_content/home.php');
	
	});
	
	$("a.contact").click(function() {
		
		$("li.home").removeClass('active');
			
		$("li.web-design").removeClass('active');
		
		$("li.our-portfolio").removeClass('active');
		
		$("li.web-hosting").removeClass('active');
		
		$('li.contact').addClass('active');
		
		
		$("div.page-home").slideUp(450);
		
		$("div.page-web-design").slideUp(450);
		
		$("div.page-our-portfolio").slideUp(450);
		
		$("div.page-web-hosting").slideUp(450);
		
		$("div.page-contact").delay(600).slideDown(450);
		
	});

});
