
$(document).ready(function() {
	
	$(document).pngFix();
	
	var contentPath = '';
	var contentHeight = 200;
	
	$('#navAbout, #navContact').click(function () {
		
		// set id of clicked button
		var sec = $(this).attr('id');
		whichSection(sec);
		
		return false;
	});
	
	
	// close button
	$('#closeHeader').click(function () {
		var hContent = $('#headerContent');
		var emBtn = $(this);
		
		
		$('#panelTitle').fadeOut('400', function () {
			$(this).text("");
		});
		
		
		$('#headerContent').fadeOut('400', function () {
			//hContent.html('');
			
			$('#aboutContent').hide();
			$('#contactContent').hide();
			
			emBtn.addClass('hideCloseButton');
		});
		
		
		$("#headerContainer").animate({ height: "0px" }, { duration: 500 });
		
		return false;
	});
	
	
	// switch statement when animated in
	function whichSection(section) {
		
		switch(section)
		{
			case 'navAbout':
			contentPath = 'dynamic/about.php';
			contentToFade = $('#aboutContent');
			contentTitle = '<img src="'+siteRoot+'/images/tAbout.png" alt="About" width="42" height="15"/>';
			contentHeight = 290;
			break;
			
			case 'navContact':
			contentPath = 'dynamic/contact.php';
			contentToFade = $('#contactContent');
			contentTitle = '<img src="'+siteRoot+'/images/tContact.png" alt="Contact" width="58" height="15"/>';
			contentHeight = 370;
			break;
		}
		
		var hContent = $('#headerContent');		
		
		$("#headerContent").fadeOut(500, function () {
			resizeHeader();
		});
		
	}
	
	function resizeHeader()
	{
		cButton = $('#closeHeader');
		
		$("#headerContainer").animate({height:contentHeight}, 400, function () {
			
			$("#panelTitle").html(contentTitle);
			$('#panelTitle').fadeIn(200);
			//loadContent(contentPath);
			loadContent();
			
			cButton.removeClass('hideCloseButton');
			$('#closeHeader').fadeIn(200);	
		});
	}	
		
	
	function loadContent() // did have param as content
	{
		$('#aboutContent').hide();
		$('#contactContent').hide();
		contentToFade.show();
		$('#headerContent').fadeIn('400');
		
		
		if(contentPath == "dynamic/contact.php") {
			var tBox = $('#fmMessage');
			tBox.focus();
		}
		
		
		/*$('#headerContent').load(siteRoot+'/'+content, function() {
			//Cufon.replace('h2', { fontFamily: 'Mercury Text G1' });
			//$(this).fadeIn('400');
			
			// if contact, setup contact stuff.
			
			if(contentPath == "dynamic/contact.php") {
				var tBox = $('#fmMessage');
				tBox.focus();				
				
				// upon clicking submit button
		      	$('#submitForm').click(function () {
		      				      		
		      		// set errors to false
		      		var errors = false;
			      	$('#formFeedback').removeClass('errorFormat');
		      		
		      		// gather form values
		      		pMessage = $('#fmMessage').val();
		      		
		      		// check for message
		      		if(pMessage.length  == '') {
		      			errors = true;
		      			$('#formFeedback').addClass('errorFormat');
		      		}
		      				      		
		      		
		      		if(!errors) {
		      			
		      			// disable form, hide errors & show loading icon
		      			disableForm();
		      			
		      			$('#formFeedback').html('Sending message...').removeClass('warningIcon').addClass('loadingIcon');
		      			
			      		// attempt to send
			      		$.post(siteRoot+'/scripts/sendMail.php', { message: pMessage }, function(data) {
			      			if(data == 'success') {
			      				// hide form and show success message
								//$('#successMsg').show();
								$('#formFeedback').html('Message sent.').removeClass('loadingIcon').addClass('successIcon');
								$('#fmMessage').html('Dear Jon,\n\n');
								$('#fmMessage').focus();
								enableForm();
			      			} else {
			      				// enable form, show errors & hide loading icon
			      				$('#formFeedback').html('Sorry, could not send your email').addClass('errorIcon');
			      				
			      				enableForm();
			      			}
			      		});
			      		
		      		} else {
		      		
		      			$('#formFeedback').html('Please ensure you have filled out all fields').addClass('warningIcon');
			      		enableForm();
		      		}
		      		
		      		return false;
		      	});
				
				
				function disableForm()
				{
		      		$('#fmMessage').attr("disabled", "disabled").css({opacity : 0.7}, 400);
				}
				
				function enableForm()
				{
		      		$('#fmMessage').attr("disabled", "").css({opacity : 1}, 400);
				}
				
				
					
					
			}
		});
		
		*/
	}
	
	// handle checking and unchecking of filters
	
	$("#filters > a").click(function() {
		
		var filterRef = $(this).attr('id');
		var clickedItem = $(this);
		var status;
		
		if(clickedItem.hasClass('checked')) {
			$(this).removeClass('checked');
			$(this).addClass('unCheck');
			status = 'off';
		} else {
			$(this).removeClass('unCheck');
			$(this).addClass('checked');
			status = 'on';
		}
		
		handleClickedFilter(filterRef, status);
		
		return false;
	
	});
	
	function handleClickedFilter(filter, status) {
		
		var classFilter;
		
		switch(filter) {
			case 'fResources':
			classFilter = '.Resource';
			break;
			
			case 'fInspiration':
			classFilter = '.Inspiration';
			break;
			
			case 'fArticles':
			classFilter = '.Article';
			break;
			
			case 'fPhotos':
			classFilter = '.Photo';
			break;
			
		}
		
		if(status == 'off') {
			//$(''+classFilter+'').hide();
			$(''+classFilter+'').fadeOut();
		} else {
			$(''+classFilter+'').fadeIn();
		}
		
		
	}
	
	
	/* handle show/hide rss */
	var rssMenu = $("#rssContent");
	$("#rssBtn").click(function() {
		
		$(this).addClass('rssFocus');
		rssMenu.show();
		
		return false;
	
	});
	
	
	$(document).click(function() {
		if(!$(this).is(rssMenu)) {
			rssMenu.hide();
			$("#rssBtn").removeClass('rssFocus');
		}
	});
	
	
	$('.block').click(function() {
		//$(this).addClass('blockOver');
		
		window.location = $(this).find('a.btmLink').attr('href');
		
	});
	
	
	
	// upon clicking submit button
  	$('#submitForm').click(function () {
  				      		
  		// set errors to false
  		var errors = false;
      	$('#formFeedback').removeClass('errorFormat');
  		
  		// gather form values
  		pMessage = $('#fmMessage').val();
  		
  		// check for message
  		if(pMessage.length  == '') {
  			errors = true;
  			$('#formFeedback').addClass('errorFormat');
  		}
  				      		
  		
  		if(!errors) {
  			
  			// disable form, hide errors & show loading icon
  			disableForm();
  			
  			$('#formFeedback').html('Sending message...').removeClass('warningIcon').addClass('loadingIcon');
  			
      		// attempt to send
      		$.post(siteRoot+'/scripts/sendMail.php', { message: pMessage }, function(data) {
      			if(data == 'success') {
      				// hide form and show success message
					//$('#successMsg').show();
					$('#formFeedback').html('Message sent.').removeClass('loadingIcon'); //.addClass('successIcon');
					$('#fmMessage').html('Dear Jon,\n\n');
					$('#fmMessage').focus();
					enableForm();
      			} else {
      				// enable form, show errors & hide loading icon
      				$('#formFeedback').html('Sorry, could not send your email'); //.addClass('errorIcon');
      				
      				enableForm();
      			}
      		});
      		
  		} else {
  		
  			$('#formFeedback').html('Please ensure you have filled out all fields'); //.addClass('warningIcon');
      		enableForm();
  		}
  		
  		return false;
  	});
	
	
	function disableForm()
	{
  		$('#fmMessage').attr("disabled", "disabled").css({opacity : 0.7}, 400);
	}
	
	function enableForm()
	{
  		$('#fmMessage').attr("disabled", "").css({opacity : 1}, 400);
	}
	
	
});










