	function preventDefaultAction(e)	{
		if (e)	{
   			if (typeof e.preventDefault != 'undefined')	{ 
				e.preventDefault(); 
				}               
    		else	{ 
				e.returnValue = false; 
				}                   
  			}
  		// safey for handling DOM Level 0
  		return false;
		}

	function cf_show_error(id, message) {
		if(message.length > 0) {
			if(jQuery('div.errors p.' + id).length > 0) {
				jQuery('div.errors p.' + id).text(message);
				}
			else {
				jQuery('div.errors').append('<p class="' + id + '">' + message + '</p>');
				}
			}
		else { /*no message, just clear the error if there is one*/
			jQuery('div.errors p.' + id).remove();
			}
		if(jQuery('div.errors p').length > 0)
			jQuery('div.errors').show();
		else
			jQuery('div.errors').hide();
		}
	
	function cf_validate(e) {
		if(jQuery('#cf_meat').text().length > 0 && jQuery('#cf_email').val().length > 0 && check_email()) {
			jQuery('#cf_form').submit;
			}
		else {
			if(jQuery('#cf_meat').val().length < 1) {
				cf_show_error('cf_meat', 'Please enter the text of your email here before sending.');
				}
			else
				cf_show_error('cf_meat', '');
			if(jQuery('#cf_email').val().length < 1 || !check_email()) {
				cf_show_error('cf_email', 'Please provide a valid email address so we can respond.');
				}
			else
				cf_show_error('cf_email', '');
			return preventDefaultAction(e);
			}
		}
		
	function check_email() {
		var email = jQuery('#cf_email').val();
		var simple_email_reg = new RegExp("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}jQuery");
		if(!simple_email_reg.test(email)) {
			cf_show_error('cf_email', ' Please provide a valid email address so we can respond.');
			return false;
			}
		else {
			cf_show_error('cf_email', '');
			return true;
			}
		}
			

	
			
	function reset_bg_selected() {
		jQuery("#bg_select > dd").removeClass('selected');
		}	

	function new_proj_id(which) {
		current = jQuery("#projects div.current").attr("id");
		var num = current.substring(current.lastIndexOf('_') + 1, current.length);
		if(which == 'next')
			num++;
		else
			num--;
		var new_id = 'project_' + num;
		return new_id;
		}
	
	function get_last_project_id() {
		return jQuery("#projects div.last").attr("id");
		}
	
	function set_current(id) {
		jQuery("#projects .current").removeClass('current');
		jQuery('#' + id).addClass('current');
		}
						
	function next_project(e) {
		if(jQuery('#projects div.current').hasClass('last')) {
			to_project('project_1', 1200);
			}
		else {
			var new_id = new_proj_id('next');
			to_project(new_id, 600);		
			}
		return preventDefaultAction(e);
		}	
	
	function previous_project(e) {
		if(jQuery('#projects div.current').hasClass('first')) {
			var last_id = get_last_project_id()
			to_project(last_id, 1200);	
			}
		else {
			var new_id = new_proj_id('previous');	
			to_project(new_id, 600);
			}
		return preventDefaultAction(e);
		}
		
	function to_project(new_id, speed) {
		if(speed) {
			jQuery("#projects").animate({
					left: 70-jQuery('#' + new_id).position().left
					}, speed);
				set_current(new_id);
			}
		else {
			jQuery("#projects").animate({
					left: 70-jQuery('#' + new_id).position().left
					}, 600);
				set_current(new_id);
			}
		}
	
	function init() {
		jQuery.easing.def = "easeOutQuint";
		jQuery("#options").toggle();
		


		jQuery("#next_project_btn").click(next_project);
		jQuery("#previous_project_btn").click(previous_project);
		

		/*jQuery('#cf_email').blur(check_email);
		jQuery('#cf_meat').focus(function() {
			if(jQuery('#cf_meat').text() == 'Type your comment here')
				jQuery('#cf_meat').text('');
			});
		jQuery('#contact_form').submit(cf_validate);*/
		var navTimer = null;
		jQuery('#featured_work').hover(
			function() {
				if(navTimer) {
					clearTimeout(navTimer);
					navTimer = null;
					}
				else {
					jQuery('#project_list').slideDown(500, 'easeOutQuad');
					}
				}, 
			function() {
				navTimer = setTimeout(function() {
					jQuery('#project_list').slideUp(500, 'easeInQuad');
					navTimer = null;
					}, 300);
				}
			);
		jQuery('#project_list a').click(function() {
			to_project(jQuery(this).attr('title'), 600)
			return preventDefaultAction();
			});
		jQuery('div.project_info, div.pi_background, div.pi_hitzone').fadeTo(5, 0);
		jQuery('div.project_info, div.pi_background').show();
		jQuery('div.project_info').hover(
			function() {jQuery(this).fadeTo('normal', 1); jQuery(this).siblings('div.pi_background').fadeTo('normal', .93);},
			function() {jQuery(this).fadeTo('normal', 0); jQuery(this).siblings('div.pi_background').fadeTo('normal', 0);}
			);
		jQuery('a.showcase_secondary, a.showcase_third').click(function() {
			jQuery(this).siblings('a.showcase_link').children('img.showcase_main').attr('src', jQuery(this).attr('href'));
			return preventDefaultAction();
			});		
		}
		
	//initiate when the document is ready
	jQuery(document).ready(function(){
		init();	 
	});
	
	jQuery.noConflict();