$(document).ready(function() {
var link = '';
var viewportwidth;
				var viewportheight;

				if (typeof window.innerWidth != 'undefined')
				{
					viewportwidth = window.innerWidth,
					viewportheight = window.innerHeight
				}

				else if (typeof document.documentElement != 'undefined'
				&& typeof document.documentElement.clientWidth !=
				'undefined' && document.documentElement.clientWidth != 0)
				{
				viewportwidth = document.documentElement.clientWidth,
				viewportheight = document.documentElement.clientHeight
				}

	$('#arrowRight').parent().click(function(e){
		e.preventDefault();
		link = $(this).attr('href');
		$('#footer').animate({opacity:0});
		$('#landingLogo').animate({opacity:0},1500)
		$('#landingElements').animate({
			left:viewportwidth/2-592,
			opacity:0
		},1500,function(){			
			window.location = link;
		})	
	})
	
	$('#arrowLeft').parent().click(function(e){
		e.preventDefault();
		link = $(this).attr('href');
		$('#footer').animate({opacity:0});
		$('#landingLogo').animate({opacity:0},1500)
		$('#landingElements').animate({
			left:viewportwidth/2,
			opacity:0
		},1500,function(){			
			window.location = link;
		})	
	})
var action = '';
    //if submit button is clicked
    $('.submit').click(function () {        
         
        //Get the data from all the fields
        var name = $(this).parent().siblings(' input[name=fullName]');
        var email = $(this).parent().siblings(' input[name=emailAddress]');
		var query = $(this).parent().siblings('textarea');
        var form = $(this).attr('id');
		
        //Simple validation to make sure user entered something
        //If error found, add hightlight class to the text field
        if (name.val()=='') {
            name.removeClass('highlightGreen').addClass('highlightRed');
            return false;
        } else {
		name.removeClass('highlightRed').addClass('highlightGreen');
        };
        if (email.val()=='') {
            email.addClass('highlightRed');
            return false;
        }
		
		if (form=='getAssistanceBtn'){
			action = 'scripts/processAssistance.php';
		}else if (form=='subscribeBtn'){
			action = 'scripts/process.php';
        }
        //organize the data properly
        var data = 'name=' + name.val() + '&email=' + email.val() + '&query=' + query.val() + '&form='
        + form;
        //disabled all the text fields, hide submit button and show loading gif.
        $(this).parent().siblings(' input').attr('disabled','true');
        $(this).css('display','none'); 
		$(this).siblings('.loadingGraphic').show();
                 
        //start the ajax
        $.ajax({
            //this is the php file that processes the data.
            url: action, 
             
            //GET method is used
            type: "GET",
 
            //pass the data         
            data: data,     
             
            //Do not cache the page
            cache: false,
             
            //success
            success: function (html) {              
                //if process.php returned 1/true (send mail success)
                if (html==1) {        	
email.addClass('highlightGreen');		
                    //hide the form
                    $('#' + form).parent().parent('form').fadeOut('slow',function(){                
                     
                    //show the success message
                    $('#' + form).parent().parent().siblings('.responseBox').fadeIn('slow','swing');
                     }); 
                //if process.php returned 0/false (send mail failed) 
				} else {
				console.log('fail');
					//hide the form
					$('#' + form).parent().siblings(' input').removeAttr('disabled');
					email.addClass('highlightRed');
					$('#'+form).css('display','block'); 
					$('#'+form).siblings('.loadingGraphic').css('display','none'); 

                    //show the failure message
                    $('#' + form).parent().siblings('.failBox').fadeIn('slow','swing');
				}						
            }       
        });
         
        //cancel the submit button default behaviours
        return false;
    }); 


  var urlQuery = location.search;
    urlQuery = urlQuery.replace('?', '');
    var split = urlQuery.split('=');

    if (split[0] == 'b' && split[1] == 'div') {
        $('div').css('outline', '1px solid #222');
    }
if (split[0] == 'b' && split[1] == 'list') {
        $('ul').css('outline', '1px solid #222');
    }
if (split[0] == 'align' && split[1] == 'just') {
        $('#leftHandSide p').css('text-align', 'justify');
    }
	
	


});

