$(document).ready(function() {

	$(".signin").click(function(e) {          
		e.preventDefault();
		$("#signin_menu").toggle();
		$(".signin").toggleClass("menu-open");
	});
	
	$("#signin_menu").mouseup(function() {
		return false
	});
	
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.signin").length==0) {
			$(".signin").removeClass("menu-open");
			$("#signin_menu").hide();
		}
	});	
	
	$("#signin_form").submit(function() {
		var u = $('#username').val(); u = $.trim(u);
		var p = $('#password').val(); p = $.trim(p);
		if ((u !== "") && (p !== "")) {
			$(".submit_btn").hide();
			$(".invalid_login").hide();
			//check the username exists or not from ajax
			$.post("process.php?x=clientlogin",{ username:u,password:p,rand:Math.random() } ,function(data) {
				//alert('u:'+u+' p:'+p + ' data returned: '+data);
				var entry = data.split("#");
				if(entry[0] == 'yes') { //if correct login detail
					document.location=entry[1];
					/*$("#msgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
						$(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,function() { //redirect to secure page
							document.location='secure.php';
						});
					});*/
				}
				else {
					//alert("NO GO"+u+":"+p);
					$(".submit_btn").show();
					$(".invalid_login").show();
				}
			});
		}
		else {
			//alert("NO USER");
			$(".invalid_login").show();
		}
		
		return false;//not to post the  form physically
	});
	
	$("#client_form").submit(function() {
		var gnc_name = $('#gnc_name').val(); gnc_name = $.trim(gnc_name);
		var gnc_email = $('#gnc_email').val(); gnc_email = $.trim(gnc_email);
		var gnc_phone = $('#gnc_phone').val(); gnc_phone = $.trim(gnc_phone);
		var gnc_website = $('#gnc_website').val(); gnc_website = $.trim(gnc_website);
		var gnc_message = $('#gnc_message').val(); gnc_message = $.trim(gnc_message);
		
		if ((gnc_name !== "") && (gnc_email !== "") && (gnc_message !== "")) {
			//$(".client-form-submit-btn").hide('slow', function() {
				$(".client-form-submit-btn").hide();									   
				$(".client-form-invalid").hide();
			//});
			//check the username exists or not from ajax
			$.post("process.php?x=clientcontactform",{ n:gnc_name,e:gnc_email,p:gnc_phone,w:gnc_website,m:gnc_message,rand:Math.random() } ,function(data2) {
				var form = data2;
				if(form == 'success') {
					$('#gnc_name').val(null);
					$('#gnc_email').val(null);
					$('#gnc_phone').val(null);
					$('#gnc_website').val(null);
					$('#gnc_message').val(null);
					$(".client-form-content").hide('slow', function() {
						$(".client-form-thank-you").html('<p>THANK YOU.  YOUR INQUIRY HAS BEEN SUBMITTED.  WE WILL CONTACT YOU SHORTLY.</p>');
						$(".client-form-thank-you").show();
					});
					
					if (facebook_contact_form == true) {
						$("#message").hide('slow');
						facebook_contact_form = false;
					}
					//document.location=entry[1];
					/*$("#msgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
						$(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,function() { //redirect to secure page
							document.location='secure.php';
						});
					});*/
				}
				else {
					//alert("NO GO"+u+":"+p);
					$(".client-form-submit-btn").show();
					//$(".client-form-invalid").hide('slow', function() {
						$(".client-form-invalid").show();
					//});
				}
			});
		}
		else {
			//alert("NO USER");
			//$(".client-form-invalid").hide('slow', function() {
				$(".client-form-invalid").show();
				$(".client-form-submit-btn").show();
			//});
		}
		
		return false;//not to post the  form physically
	});
	
	var $paneTarget = $('#about-us');

	$('#more-about-us').click(function(){
		$paneTarget.stop().scrollTo( '+=210px', 800 );
	});
	
	$('#less-about-us').click(function(){
		$paneTarget.stop().scrollTo( '-=210px', 800 );
	});

	
	get_sifr();	
	
	
});

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function get_contact_form() {
	getFlashMovie("player1").getContactForm("GNC");
}
function stop_video() {
	getFlashMovie("player1").stopNewclearTV("GNC");
}
function play_video() {
	getFlashMovie("player1").playNewclearTV("GNC");
}
function get_contact_form2() {
	$(current_page).slideUp('slow', function() {
		$("#contact-form").slideDown('slow');
		current_page = "#contact-form";
	});
}

function get_landing_page() {
	$(current_page).slideUp('slow', function() {
		$("#content").slideDown('slow');
		current_page = "#content";
	});
}

function get_about_info() {
	$(current_page).slideUp('slow', function() {
		$("#about").slideDown('slow');
		current_page = "#about";
	});
}

