// The main JQuery function that is called when the document has
// completed loading
$(document).ready(function() {
	
	// Hide the main password text box so the password text
	// can be displayed in its place
	$("#txtPassword").hide();
	
	// When the username textbox is clicked on, the format
	// of the textbox changes to bring attention to it
	$("#txtUserName").focus(function() {
		
		$tempUserName = $("#txtUserName").val().toLowerCase();
		if ($tempUserName == "user name") {
			$("#txtUserName").css('color', '#000');
			$("#txtUserName").val("");
		}
	});
	
	// when the password text textbox gains focus, it
	// disappears and gives focus to the password textbox
	$("#txtPasswordText").focus(function() {
		$("#txtPasswordText").hide();
		
		$("#txtPassword").css('color', '#000');
		$("#txtPassword").show();
		$("#txtPassword").focus();
	});
	
	//$.fancybox.hideActivity();
	
	// ensures the error message is hidden prior to the
	// form being displayed
	$("#login_error").hide();
	
	// displays the modal login box and ensures the
	// proper textboxes are displayed
	$("#loginBox").fancybox({
		'autoDimensions': false,
		'scrolling'		: 'auto',
		'padding'		: 0,
		'titleShow'		: false,
		'overlayColor'	: '#333',
		'overlayOpacity': 0.6,
		'width'			: '75%',
		'height'		: '75%',
		'type'			: 'iframe'
	});
	
	$("#lnkPasswordBox").click(function() {
	
		alert("hello");
	});
	
	// overrides the form's submit function and replaces it
	// with ajax form login validation. If the username and
	// password match, the user is logged in and redirected
	$("#frmLogin").bind("submit", function() {
	
		$.post(
			"ajaxLogin.php",
			{ userName:$('#txtUserName').val(), password:$('#txtPassword').val() },
			function(data) {
				if(data=="success") {
					document.location='controlPanel.php';
				}
				else {
					$.fancybox.hideActivity();
					$("#login_error").html(
						"Unable to match username or password<br />\n" + 
						"<a id='lnkPasswordBox' href='#' >Forget password?</a>\n"
					);
					$("#login_error").show();
				}
		});
	
		$.fancybox.showActivity();
	
		return false;
	});
	
	/*****************************
	JQuery Watch TV Popup
	*****************************/
	
	// Displays the modal box that allows users to watch
	// live streaming video of Lighthouse Events
	$(".tvPopup").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'overlayColor'	: '#333',
		'overlayOpacity': 0.6,
		//'transitionIn'	: 'none',
		'title'			: this.title,
		'width'			: 400,
		'height'		: 300,
		'type'			: 'swf',
		'swf'			: {
			'wmode'				: 'opaque',
			'allowfullscreen'	: 'true',
			'allowscriptaccess'	: 'always',
			'quality'			: 'false',
			'flashvars'			: 'type=rtmp&file=ltan&streamer=rtmp://150.obj.netromedia.net/ltan&autostart=true&skin=streaming/skins/glow.zip&image=images/connect_tvplaceholder.jpg&controlbar.position=over'
		}
	});
	
	/******************************
	Photo Light Boxes
	******************************/
	
	// Displays the lightbox for Femi & Remi Ogunrinde
	$("#gallery_femiremi").click(
		function() {
			$.fancybox([
				{
					'href'	: 'images/web/Ogunrinde01.jpg',
					'title'	: 'Download this photo to use on websites. (Right click to save)'
				}
				/*{
					'href'	: 'images/print/Ogunrinde.zip',
					'title'	: '10\"x8\" photo to use in brochures, magazines, etc. (Right click to save)'
				}*/
			], {
				'type'              : 'image',
				'changeFade'        : 0,
				'overlayColor'		: '#333',
				'overlayOpacity'	: 0.6,
				'titlePosition'		: 'over'
			}
		);
	});
	
	// Displays the lightbox for Ray & Karen Jelinski
	$("#gallery_raykaren").click(
		function() {
			$.fancybox([
				{
					'href'	: 'images/web/Jelinski01.jpg',
					'title'	: 'Download this photo to use on websites. (Right click to save)'
				}
			], {
				'type'              : 'image',
				'changeFade'        : 0,
				'overlayColor'		: '#333',
				'overlayOpacity'	: 0.6,
				'titlePosition'		: 'over'
			}
		);
	});
	
	// Displays the lightbox for Ray & Karen Jelinski
	$("#gallery_robapril").click(
		function() {
			$.fancybox([
				{
					'href'	: 'images/web/Howard01.jpg',
					'title'	: 'Download this photo to use on websites. (Right click to save)'
				}
			], {
				'type'              : 'image',
				'changeFade'        : 0,
				'overlayColor'		: '#333',
				'overlayOpacity'	: 0.6,
				'titlePosition'		: 'over'
			}
		);
	});
	
	// Displays the lightbox for Ray & Karen Jelinski
	$("#gallery_dorothy").click(
		function() {
			$.fancybox([
				{
					'href'	: 'images/web/Cook01.jpg',
					'title'	: 'Download this photo to use on websites. (Right click to save)'
				}
			], {
				'type'              : 'image',
				'changeFade'        : 0,
				'overlayColor'		: '#333',
				'overlayOpacity'	: 0.6,
				'titlePosition'		: 'over'
			}
		);
	});
	
	$("#facebook").fancybox({
		'width'				: 640,
		'height'			: 480,
        'autoScale'     	: false,
		'overlayColor'		: '#333',
		'overlayOpacity'	: 0.6,
		'padding'			: 0,
		'type'				: 'iframe'
	});
	
	$("#twitter").fancybox({
		'width'				: 800,
		'height'			: 600,
        'autoScale'     	: false,
		'overlayColor'		: '#333',
		'overlayOpacity'	: 0.6,
		'padding'			: 0,
		'type'				: 'iframe'
	});
	
	$("#map").fancybox({
		'width'				: 800,
		'height'			: 600,
        'autoScale'     	: false,
		'overlayColor'		: '#333',
		'overlayOpacity'	: 0.6,
		'padding'			: 0,
		'type'				: 'iframe'
	});
	
	/********************************************
	Control Panel Functions
	*********************************************/
	/*
	var oldPassword = "";
	var newPassword = "";
	var confPassword = "";
	
	$('#lblOldPasswordError').hide();
	$('#lblNewPasswordError').hide();
	$('#lblConfPasswordError').hide();
	
	$("#cmdSubmit").click(function() {
		
		$("#lblOldPasswordError").hide();
		$("#lblNewPasswordError").hide();
		$("#lblConfPasswordError").hide();
		
		oldPassword = $("input#txtOldPassword").val();
		newPassword = $("input#txtNewPassword").val();
		confPassword = $("input#txtConfPassword").val();
		
		// validate form fields
		
		var bHasErrors = false;
		
		if (oldPassword == "") {
			$("#lblOldPasswordError").show();
			bHasErrors = true;
		}
		
		if (newPassword == "") {
			$("#lblNewPasswordError").show();
			bHasErrors = true;
		}
		
		if (newPassword != confPassword || newPassword == "") {
			$("#lblConfPasswordError").show();
			bHasErrors = true;
		}
		
		if (!bHasErrors) {
			
			SubmitForm();
		}
	});
	
	function SubmitForm() {
	
		//var arrData = { oldPass: oldPassword, newPass: newPassword, confPass: confPassword, userName: <?php echo "'" . $_SESSION['username'] . "'"; ?> };
				
		//alert("Hello");
		
		$.post(
			"changePassword.php",
			arrData,
			function(data) {
				
				if (data == "Success") {
					$("#passwordForm").fadeOut("normal", function() {
						$('#passwordForm').html("<div class='message'>Your password has been successfully changed.</div>").fadeIn("normal");
					});
				}
				else {
					$("#passwordForm").fadeOut("normal", function() {
						$('#passwordForm').append("<div class='message'>An error occurred and your password couldn't be changed. " + 
												"Please check your old and new passwords and try again.<br /><a href='javascript:HideMessage();'><img src='images/background_warning_close.gif' alt='close' /></a></div>").fadeIn("normal");
					});
				}
			}
		);
	}
		
	function HideMessage() {
		$(".message").fadeOut("normal");
	}
	*/
	
	//get all link with class panel  
    $('a.panel').click(function () {  
  
        //reset and highlight the clicked link  
        $('a.panel').removeClass('selected');  
        $(this).addClass('selected');  
          
        //grab the current item, to be used in resize function  
        current = $(this);  
          
        //scroll it to the destination  
        $('#wrapper').scrollTo($(this).attr('href'), 800);        
          
                //cancel the link default behavior  
        return false;  
    });  
  
  
    //resize all the items according to the new browser size  
    $(window).resize(function () {  
          
        //call the resizePanel function  
        resizePanel();
		
    });
    
    // SoSo Social Feed 
	$("#activityfeed").soSoSocial();
	
	$(function() {
		$('#home_banner .image').dumbCrossFade({
			'slideType' : 'fade', 
			'showTime' : 10000
		});
	});
	
	/*******************************************************************
	*
	* Email Form Functions
	*
	********************************************************************/
	var sCommentsVal = "Please provide your comments…";
	
	// load the modal window
	$('a.modal').click(function(){

		// scroll to top
		$('html, body').animate({scrollTop:0}, 'fast', function() {
		
			// before showing the modal window, reset the form incase of previous use.
			$('.success, .error').hide();
			$('form#contactForm').show();
	
			// Reset all the default values in the form fields
			$('#name').val('Your name');
			$('#email').val('Your email address');
			$('#comment').val(sCommentsVal);
	
			//show the mask and contact divs
			$('#mask').show().fadeTo('', 0.7);
			$('div#contact').fadeIn();
		
		
		});

		

		// stop the modal link from doing its default action
		return false;
	});

	// close the modal window is close div or mask div are clicked.
	$('div#close, div#mask').click(function() {
		$('div#contact, div#mask').stop().fadeOut('slow');

	});

	$('#contactForm input').focus(function() {
		$(this).val('');
	});
	
	$('#contactForm textarea').focus(function() {
		$(this).val('');
	});

	// when the Submit button is clicked...
	$('input#submit').click(function() {
		
		//Inputed Strings
		var username = $('#name').val(),
			email = $('#email').val(),
			comment = $('#comment').val();

		//Error Count
		var error_count = 0;

		//Regex Strings
		var username_regex = /^[A-Za-z ]*[A-Za-z][A-Za-z ]*$/; // must contain at least one letter, no numbers or special characters allowed
		var email_regex = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/

		$('.error').remove();
		
		//Test Username
		if (String(username).search(username_regex) == -1) {
			$('#name').after("<p class='error'>Provide a name.</p>");
			error_count += 1;
		}
		
		//Test Email
		if (String(email).search(email_regex) == -1) {
			$('#email').after("<p class='error'>Provide a valid email.</p>");
			error_count += 1;
		}
		
		//Blank Comment?
		if(comment == '' || comment == sCommentsVal) {
			$('#comment').after("<p class='error' style='display:block;'>" + sCommentsVal + ".</p>");
			error_count += 1;
		}
		
		//If no errors, then proceed
		if(error_count == 0) {
			
			$.ajax({
				type: "post",
				url: "send.php",
				data: "name=" + username + "&email=" + email + "&comment=" + comment,
				error: function() {
					$('.error').hide();
					$('#sendError').slideDown('slow');
				},
				success: function () {
					$('.error').hide();
					$('.success').fadeIn('slow');
					$('form#contactForm').slideUp(750, "easeOutCubic");
				}
			});
		}

		else {
            $('.error').show('fast');
            $(".error").css("display", "inline");
        }
            
            

		return false;
	});
	
	
	
	
	//startPage();
});


