 $(document).ready(function(){
  	
	$("a#quickbar_info_join").click(function() {
		$("#lightbox_overlay").slideDown('slow');
		//$("#lightbox").fadeIn();
	});
	
	var orig = new Array();
  	orig['pos'] = $("#header_nub").position();
  	orig['pos'] = orig['pos'].left;
  	orig['col'] = $("#header_nub").css('background-color');
  	orig['wid'] = $("#header_nub").width();
  	
  	hoverClear = setTimeout(function() { }, 100);

	function navHover(nav_item,nav_class) {
 	$(nav_item).hover(
	      function () {
	        hoverOver(nav_item);
	      }, 
	      function () {
	        hoverOut(nav_item);
	      }
	    );
	}
	
	function hoverOver(nav_item) {
      	clearTimeout(hoverClear);
		$("div#header_nub").animate({ width: $(nav_item).width(), left: $(nav_item).position().left + 50, backgroundColor: $(nav_item).css('color') }, 500);
	}
	
	function hoverOut(nav_item) {
		hoverClear = setTimeout(function() {
			$("div#header_nub").animate({ width: orig['wid'], left: orig['pos'], backgroundColor: orig['col'] }, 500);		
		}, 2000);
	}
		
	navHover('a#header_nav_ichurch','ichurch');
	navHover('a#header_nav_connect','connect');
	navHover('a#header_nav_video','video');
	navHover('a#header_nav_store','store');
	
	var currentLogin = null;
	
	$("#header_signin_button_fb").click(function() {
		if (currentLogin != 'fb') {
			$("#header_signin_sf").fadeOut('fast');
			$("#header_signin_fb").fadeIn('fast');
			$("#header_signin_button_fb").addClass("active");
			$("#header_signin_button_sf").removeClass("active");
			currentLogin = 'fb';
		}
	});
	
	$("#header_signin_button_sf").click(function() {
		if (currentLogin != 'sf') {
			$("#header_signin_fb").fadeOut('fast');
			$("#header_signin_sf").fadeIn('fast');
			$("#header_signin_button_sf").addClass("active");
			$("#header_signin_button_fb").removeClass("active");
			currentLogin = 'sf';
		}
	});
	
	$("#header_quickbar_info_signin").click(function(ev) {
		ev.preventDefault();
		$("#header_signin").fadeIn('slow');
		$("#header_nub").fadeOut('slow');
	});
	
	$("#header_signin_button_x").click(function() {
		$("#header_signin").fadeOut('slow');
		$("#header_nub").fadeIn('slow');
	});
	
	$("#header_signin_sf_options_join").click(function() {
		$("#header_signin").fadeOut('slow');
	});
	
	$(".join").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			:	'iframe',
		'width'			:	320,
		'height'		:	430,
		'margin'		:	0,
		'padding'		:	0,
		'autoScale'		:	false,
		'centerOnScroll':	true,
		'overlayColor'	:	'#ffffff',
		'overlayOpacity':	0.5
	});
	
	if ($('#header_signin_sf_email').val() != '') { $('#header_signin_sf_email').css({'background' : 'white'}); }	
	if ($('#header_signin_sf_password').val() != '') { $('#header_signin_sf_password').css({'background' : 'white'}); }	

	/*setInterval(function() {
		mycounter = mycounter + 1;
		test = $('#header_signin_sf_email').val();
		if ($('#header_signin_sf_email').val() != '') { test2 = 'true'; $("#header_signin_sf_email").css({'background' : 'white'}); } else { test2 = 'false'; }
		$("#debug").html(mycounter + test + test2);
		//if ($('#header_signin_sf_email').val() != '') { $(this).css({'background' : 'red'}); }
	}, 1000);*/
	
	
	$('#header_signin_sf_email, #header_signin_sf_password').emptyonclick_signin();
	

	$("#header_signin_sf_submit").click(function(ev) {
		ev.preventDefault();
		post = $("#header_signin_sf_form").serialize();
		$(this).attr('disabled', 'disabled');
		$("#header_signin_sf_email").attr('disabled', 'disabled');
		$("#header_signin_sf_password").attr('disabled', 'disabled');
		$("#header_signin_sf_spinner").show();
		$(this).fadeOut(100);
		$.post($("#header_signin_sf_form").attr('action'), post, function(data) {
			
			if (data.status == true) {
				setTimeout(function() {
					$("#header_signin_sf").fadeOut("slow");
					$(".replace_first_name").html(data.info.first_name);
					$(".replace_last_name").html(data.info.last_name);
					$("#header_signin_success").show();
					$("#header_signin_response").fadeIn("slow");
					$("#header_quickbar_info_joinsignin").addClass("disable");
					$("#header_quickbar_info_user").removeClass("disable");
					loggedIn();
					setTimeout(function() {
						$("#header_signin").fadeOut(2000);
					}, 3500);
				}, 500);
			} else if (data.status == false) {
				setTimeout(function() {
					$("#header_signin_sf").fadeOut("slow");
					$("#header_signin_fail").show();
					$("#header_signin_response").fadeIn("slow");
				}, 500);
			}
			
		}, 'json');
		//$("#header_signin").fadeIn('slow');
	});
	
	
	$("#header_signin_fail_tryagain").click(function(ev) {
		ev.preventDefault();
		$("#header_signin_sf_spinner").hide();
		$("#header_signin_sf_submit").show();
		$("#header_signin_sf_submit").removeAttr('disabled');
		$("#header_signin_sf_email").removeAttr('disabled');
		$("#header_signin_sf_password").removeAttr('disabled');
		//$("#header_signin_sf_email").val('');
		$("#header_signin_sf_password").val('');
		//$("#header_signin_sf_email").css({'background' : 'url(/../assets/images/header_signin_sf_email_bg.png) white no-repeat 5px'});
		$("#header_signin_sf_password").css({'background' : 'url(/../assets/images/header_signin_sf_password_bg.png) white no-repeat 5px'});
		$("#header_signin_fail").fadeOut("slow");
		$("#header_signin_response").fadeOut("slow");
		$("#header_signin_sf").fadeIn("slow");
	});
		
	function jquery_verify_fb() {
		//$("#header_nav").fadeOut();
	}
	
	$('.valign').each(function(){
		$(this).vAlign();
	});	


});
 
function loggedIn() {
	$(".login").fadeIn("fast");
	$(".logout").fadeOut("fast");
	$('.valign').each(function(){
		$(this).vAlign();
	});
	logged_in = true;
}
	
function loggedOut() {
	$(".logout").fadeIn("fast");
	$(".login").fadeOut("fast");
	$('.valign').each(function(){
		$(this).vAlign();
	});
	logged_in = false;
}

var logged_in = false;