/******************
*
*  	Filename: quacks.js
*
*  	Created By: Tommy Logik
*
*	Description: This file is used to correct functionality and styling issues
*	that are not possible with standard html and css.
*
*	Note: this files requires jQuery to be initialized or it will throw errors.
*
*******************/
$(document).ready(function(){
						   
	// On document load check to see if the sidebar was previously collapsed
	$('#dynamic-sidebar li').each(function(){
		var scrap = $(this).attr('id');
		if(scrap != '' || scrap !=''){
			if($.cookie(scrap) == '1'){
				$(this).children('h2').next().css({'display':'none'});
				$(this).children('h2').addClass('collapsed');	
			}
		}
	});

	// Toggle the sidebars states and then write a cookie for it
	$('#dynamic-sidebar h2').click(function(){
		if($(this).hasClass('collapsed')){
			$(this).next().slideToggle();
			$(this).removeClass('collapsed');
			var scrap = $(this).closest('li').attr('id');
			$.cookie(scrap, null);
		} else {
			var scrap = $(this).closest('li').attr('id');
			$.cookie(scrap, '1');
			$(this).next().slideToggle();
			$(this).addClass('collapsed');
		}
	});
	
	// Add Text to sidebar : when focused remove text
	if($('#cc_firstname').val() ==''){
		$('#cc_firstname').val('Name');
	}
	$('#cc_firstname').focus(function(){
		if($(this).val() == 'Name'){
			$(this).val('');
		}
	});
	$('#cc_firstname').focusout(function(){
		if($(this).val() == ''){
			$(this).val('Name');
		}
	});
	
	if($('#cc_email').val() ==''){
		$('#cc_email').val('Email');
	}
	$('#cc_email').focus(function(){
		if($(this).val() == 'Email'){
			$(this).val('');
		}
	});
	$('#cc_email').focusout(function(){
		if($(this).val() == ''){
			$(this).val('Email');
		}
	});
	$('#constant-contact-signup').submit(function(){
		if(($('#cc_email').val() == 'Email') || ($('#cc_firstname').val() == 'Name')){
			alert('Please fill out the form completely. Thank you!');
			return false;
			}
		});
});
