	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($('div.errors p.' + id).length > 0) {
				$('div.errors p.' + id).text(message);
				}
			else {
				$('div.errors').append('<p class="' + id + '">' + message + '</p>');
				}
			}
		else { /*no message, just clear the error if there is one*/
			$('div.errors p.' + id).remove();
			}
		if($('div.errors p').length > 0)
			$('div.errors').show();
		else
			$('div.errors').hide();
		}
	
	function cf_validate(e) {
		if($('#cf_meat').text().length > 0 && $('#cf_email').val().length > 0 && check_email()) {
			$('#cf_form').submit;
			}
		else {
			if($('#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($('#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 = $('#cf_email').val();
		var simple_email_reg = new RegExp("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$");
		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 fullscreen_me() {
		alert('max would be ' + screen.width + ' x ' + screen.height);
		window.open("http://bubblegumempire.com/galan/", 'Galan', 'width=' + screen.width + ',height=' + screen.height + ',top=-30,left=-10,fullscreen=yes');
		}
	
	function bookmark_me(){
		var title = 'Galan Design';
		var url = 'http://www.galandesign.com';
		var href = "http://www.GalanDesign.com";
		if (window.sidebar) { // firefox
			window.sidebar.addPanel(title, url, href);
			}
		else if(window.opera && window.print) { // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
			}
		else if(document.all) {// ie
			window.external.AddFavorite(url, title);
			}
		}
		
	function reset_bg_selected() {
		$("#bg_select > dd").removeClass('selected');
		}	

	function new_proj_id(which) {
		current = $("#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 $("#projects div.last").attr("id");
		}
	
	function set_current(id) {
		$("#projects .current").removeClass('current');
		$('#' + id).addClass('current');
		}
						
	function next_project(e) {
		if($('#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($('#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) {
			$("#projects").animate({
					left: 70-$('#' + new_id).position().left
					}, speed);
				set_current(new_id);
			}
		else {
			$("#projects").animate({
					left: 70-$('#' + new_id).position().left
					}, 600);
				set_current(new_id);
			}
		}
	
	function init() {
		jQuery.easing.def = "easeOutQuint";
		$("#options").toggle();
		$("#leather_bg").click(function() {
			$("body").removeClass();
			$("body").addClass('leather');
			reset_bg_selected();
			$(this).addClass('selected');
			});
		$("#chalk_bg").click(function() {
			$("body").removeClass();
			$("body").addClass('chalk');
			reset_bg_selected();
			$(this).addClass('selected');
			});
		$("#wood_bg").click(function() {
			$("body").removeClass();
			$("body").addClass('wood');
			reset_bg_selected();
			$(this).addClass('selected');
			});
		$("#fiber_bg").click(function() {
			$("body").removeClass();
			$("body").addClass('fiber');
			reset_bg_selected();
			$(this).addClass('selected');
			});	
		$("#next_project_btn").click(next_project);
		$("#previous_project_btn").click(previous_project);
		/*$("#fullscreen_li a").click(fullscreen_me);*/
		$("#bookmark_li a").click(bookmark_me);
		/*$('#cf_email').blur(check_email);
		$('#cf_meat').focus(function() {
			if($('#cf_meat').text() == 'Type your comment here')
				$('#cf_meat').text('');
			});
		$('#contact_form').submit(cf_validate);*/
		var navTimer = null;
		$('#featured_work').hover(
			function() {
				if(navTimer) {
					clearTimeout(navTimer);
					navTimer = null;
					}
				else {
					$('#project_list').slideDown(500, 'easeOutQuad');
					}
				}, 
			function() {
				navTimer = setTimeout(function() {
					$('#project_list').slideUp(500, 'easeInQuad');
					navTimer = null;
					}, 300);
				}
			);
		$('#project_list a').click(function() {
			to_project($(this).attr('title'), 600)
			return preventDefaultAction();
			});
		$('div.project_info, div.pi_background, div.pi_hitzone').fadeTo(5, 0);
		$('div.project_info, div.pi_background').show();
		$('div.project_info').hover(
			function() {$(this).fadeTo('normal', 1); $(this).siblings('div.pi_background').fadeTo('normal', .93);},
			function() {$(this).fadeTo('normal', 0); $(this).siblings('div.pi_background').fadeTo('normal', 0);}
			);
		$('a.showcase_secondary, a.showcase_third').click(function() {
			$(this).siblings('a.showcase_link').children('img.showcase_main').attr('src', $(this).attr('href'));
			return preventDefaultAction();
			});		
		}
		
	//initiate when the document is ready
	$(document).ready(function(){
		init();	 
	});