// JavaScript Document
$(function(){
		// If screen is to small
		
				/*if(!window.innerWidth)
		{
			//strict mode
			if(!(document.documentElement.clientWidth == 0))
			{
				w = document.documentElement.clientWidth;
				if (w == 1024) 
					{
						$(".page").css("margin-left","-560px");
					}	
				if(w == 1152)
				{
						$(".page").css("margin-left","-500px");
				}
			}
			//quirks mode
			else
			{
				w = document.body.clientWidth;
				if (w == 1024) 
					{
						$(".page").css("margin-left","-560px");
					}	
				if(w == 1152)
				{
						$(".page").css("margin-left","-500px");
				}
			}
		}
		//w3c
		else
		{
				w = window.innerWidth;
				if (w == 1024) 
					{
						$(".page").css("margin-left","-560px");
					}	
				if(w == 1152)
				{
						$(".page").css("margin-left","-500px");
				}
		}
*/

	
		
		if (screen.width == 1024) 
		{
			$(".page").css("margin-left","-560");
		}			
		if(screen.width == 1152)
		{
				$(".page").css("margin-left","-500");
		}
		
		jQuery.easing.def = 'easeInOutCirc';
		$('#home').click(function(){
			aboutP();
		});	
		
		$('#about').click(function(){
			aboutP();
		});		
		
		$('#project').click(function(){
			projectP();
		});		
		
		$('#services').click(function(){
			servicetP()
		});		
		
		
		$('#contact').click(function(){
			contactP()
		});	
		
		
		//Show Pages
		$('#show').click(function(){
			$('.page').show();
			$('#show').removeClass("footer");
			$('#show').addClass("selectedV");
			
			$('#hide').removeClass("selectedV");
			$('#hide').addClass("footer");

		});	
		
		//Hide Pages
		$('#hide').click(function(){
			$('.page').hide();
			
			$('#hide').removeClass("footer");
			$('#hide').addClass("selectedV");
			
			$('#show').removeClass("selectedV");
			$('#show').addClass("footer");
		});	
		
		//Send Form
		$('#submit').click(function(){
		
			
			var Name = $('#Name').val();
			var Company = $('#Company').val();
			var Email = $('#Email').val();
			var Phone = $('#Phone').val();
			var Message = $('#Message').val();
			
			var error=false;
			var response="";

			
			if(Name == "" || Name == "*Name")
			{
				 response += "Please provide your name!\n";
				 error = true;
			}
			if(!isEmail(Email)) 
			{
				 response += "Please provide a valid email!\n";
				 error = true;
			}
			if(Phone == "" || Phone == "*Phone Number")
			{
				 response += "Please provide a phone number!\n";
				 error = true;
			}
			if(Message == "" || Message == "*How can we help you?")
			{
				 response += "Please provide a message!\n";
				 error = true;
			}
			
			if(error)
			{
				alert("There was an error submiting the form\n\n" + response);
				return false;
			}
			else{
				$('#formHolder').append('<span id="loading"><img src="images/ajax-loader.gif" alt="Currently Loading" />  Sending Message...</span>');	
			}
			
			
			
			//console.log(Name + Email + Phone + Message) ;
			
			$.ajax({
				url: 'SendEmail.php',
				type: 'POST',
				data: 'Name=' + Name + '&Company=' + Company + '&Email=' + Email + '&Phone=' + Phone + '&Message=' + Message,
					
				success: function(result) {
						$('#response').remove();
						
						$('#loading').fadeOut(500, function() {
							$('#formHolder').append('<p id="response">' + result + '</p>');								
							$(this).remove();
							setTimeout ( "$('#response').remove()", 2000 );

						});	
					}
				});		
									
		return false;
		});	
		
		$.extend($.fn.jScrollPane.defaults, {showArrows:true, scrollbarWidth: 20, arrowSize: 20, dragMinHeight: 52 , dragMaxHeight:52 });
		$('#scrollabel').jScrollPane();

	
	});
		
	
	
function removeElement(parentDiv, childDiv){
     if (childDiv == parentDiv) {
         // alert("The parent div cannot be removed.");
     }
     else if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
     else {
        //  alert("Child div has already been removed or does not exist.");
          return false;
     }
}



 






function getFlashMovieObject(movieName){
if (window.document[movieName]){
		return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1){
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf(”Microsoft Internet”)!=-1)
{
return document.getElementById(movieName);
}
}

function SendDataToFlashMovie(newPage)
{
	var flashMovie = getFlashMovieObject("Fnav");
	flashMovie.sendTextToFlash(newPage);
}



function KillIntro()
{
	//StopINTRO();
		$('#intro').hide();
	$('#intro').remove();
	$('#header').animate({ top: "0px"}, 500);
	$('#footer').animate({ bottom: "0px"}, 500);
				
}


function initIntro()
{

	//$("#intro").hide();

	$('#container').animate({ left: "-1800px"}, 1500,
							function(){
							$('#header').animate({ top: "0px"}, 500);
							$('#footer').animate({ bottom: "0px"}, 500);
							});
	
}





function aboutP()
{
	$('#container').animate({ left: "-1800px"}, 2000);
	SendDataToFlashMovie("About");
}

function projectP()
{
	$('#container').animate({ left: "-4800px"}, 2000);
	SendDataToFlashMovie("Projects");
}

function servicetP()
{
	$('#container').animate({ left: "-7800px"}, 2000);
	SendDataToFlashMovie("Services");
}

function contactP()
{
	$('#container').animate({ left: "-10800px"}, 2000);
	SendDataToFlashMovie("Contact");
}

///Text Fields
function clearText(field){

	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;

}



//Check Email
function isEmail(str) { //Email address
	var emailRegExp="^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex=new RegExp(emailRegExp);
	return regex.test(str);
}
