function splash_animate() {

	$('#header').css('width', 0);
	$('#footer').css('width', 0).css('float', 'right');
	$('#maincontent').css('opacity', 0).css('width', 0);
	$('#menu').css('top', '50px').css('opacity', 0);
	$('#menufooter').css('right', '200px').css('opacity', 0);
	$('#contentleftbar').hide();
	$('#logo').css('top', '10px').css('opacity', 0);
	$('#welcome').css('opacity', 0);


	var home_load = function(callback) {

		$('#contentleftbar').show('blind', {direction: 'left', duration: 800});

		$('#maincontent').animate({
			width: '677px',
			opacity: 1,
		}, 800, function() {

			$('#logo').animate({
				top: '30px',
				opacity: 1,
			}, 300, function() {

				$('#welcome').animate({
					opacity: 0.7,
				}, 2000);

			});

		});

	}



    $('#header').animate({
    	width: '100%'
    }, 500);    

    $('#footer').animate({
		width: '100%'
	}, 500, function() {

		$('#menu').animate({
			top: '100px',
			opacity: 1,
		}, 500, 'easeOutBounce');    

		$('#menufooter').animate({
			right: '30px',
			opacity: 1,
		}, 500, 'easeOutBounce', function() {

			// handle for gallery image and google map
			if ($('#main_image').size() > 0) {
				$('#main_image').load(function() {
					home_load();
				}).each(function() {
					if (this.complete) $(this).load();
				});
			}

		});    
	});    

}
	

function ie_splash_animate() {

	$('#header').css('width', 0);
	$('#footer').css('width', 0).css('float', 'right');
	$('#maincontent').css('width', 0);
	$('#maincontent').hide();
	$('#menu').css('top', '50px');
	$('#menu').hide();
	$('#menufooter').css('right', '200px');
	$('#menufooter').hide();
	$('#contentleftbar').hide();
	$('#logo').css('top', '10px');
	$('#logo').hide();
	//$('#welcome').show();



    $('#header').animate({
    	width: '100%'
    }, 500);    

    $('#footer').animate({
		width: '100%'
	}, 500, function() {

		$('#menu').show();
		$('#menu').animate({
			top: '100px',
			//opacity: 1,
		}, 500, 'easeOutBounce');    

		$('#menufooter').show();
		$('#menufooter').animate({
			right: '30px',
			//opacity: 1,
		}, 500, 'easeOutBounce', function() {

			$('#contentleftbar').show('blind', {direction: 'left', duration: 800});
			
			$('#maincontent').show();
			$('#maincontent').animate({
				width: '677px',
				//opacity: 1,
			}, 800, function() {

				$('#logo').show();
				$('#logo').animate({
					top: '30px',
					//opacity: 1,
				}, 300, function() {

					$('#welcome').show();
					$('#welcome').animate({
						//opacity: 0.7,
					}, 2000);

				});

			});    

		});    
	});    

}



function content_animate() {

	$('#maincontent').css('opacity', 0).css('width', 0);
	$('#contentleftbar').hide();

	var content_load = function(callback) {
		$('#contentleftbar').show('blind', {direction: 'left', duration: 800});
		
		$('#maincontent').animate({
			width: '677px',
			opacity: 1,
		}, 800, callback);
	}

	// handle for gallery image and google map
	if ($('#hero_image').size() > 0) {
		$('#hero_image').load(function() {
			content_load();
		});
	}

	else if ($('#main_image').size() > 0) {
		$('#main_image').load(function() {
			content_load();
		});
	}

	else if ($('#location').size() > 0) {
		content_load(function() {
			initialize();
		});
	}
	else
		content_load();
}



$(function() {

/*	Cufon.replace('#company_name h1', { fontFamily: 'Perpetua' });	
	Cufon.replace('#homepage_copy', { fontFamily: 'Perpetua' });	
	Cufon.replace('#inner_title', { fontFamily: 'Perpetua' });	
 	Cufon.replace('#inner_copy', { fontFamily: 'Perpetua' });	 
	
	
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	$('.cycle').cycle(); // Select all links with lightbox class*/

	/* 	center the menu with some funky stuff   */
	$('#nav').width($('ul.topnav').width() + 1);

  
	/* testing below */
	$("ul.topnav > li a:first-child").hover(function() {
	$(this).parent().find("ul.subnav").slideDown(100).show();
	$(this).parent().hover(function() {
	}, function() {
	$(this).parent().find("ul.subnav").slideUp('slow');
	});
	}).hover(function() {
		$(this).addClass("subhover");
	}, function() {
		$(this).removeClass("subhover");
	});
	
	
	
	// fix mailto spam bot filter
	$('a').each(function() {
		var url = $(this).attr('href');
		url = url.replace('###', '@');
		var text = $(this).html();
		text = text.replace('###', '@');		
		$(this).attr('href', url);
		$(this).html(text);
	});
    


	// http://stackoverflow.com/questions/1204457/how-to-solve-hack-fading-semi-transparent-png-bug-in-ie8
	/*
	var i;
	for (i in document.images) {
		if (document.images[i].src) {
			var imgSrc = document.images[i].src;
			if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
				document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
			}
		}
	}
	*/


	$.fn.ie8png = function() {

		return this.each(function() {
			var src = $(this).attr('src');
			$(this).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + src + "')");
		});
	}


	$.fn.ie8pngBG = function() {

		return this.each(function() {

			// original code getting bg info
			var name = $(this).css('background-image');
			var patt = /\"|\'|\)|\(|url/g;
			var path = name.replace(patt,'');

			// remove orignal background and apply msie filter
			$(this).css('background', 'none');

			// make inner link clickable
			var wrap = $('<div />').css('width', '100%').css('height', '100%').appendTo(this);
			$(this).children(':not(:last-child)').appendTo(wrap);
			$(wrap).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='crop',src='"+ path +"')");

			$(this).find('a').css('position', 'relative').css('z-index', '2');
		});
	}


	// main
	//$('#logo img, #welcome img, #menu img').ie8png();
	//$('#menu, #menufooter').ie8pngBG();



    
	// animate
	if ((location.pathname == '/') || (location.pathname == '/1/home')) {

		if ( $.browser.msie )
			ie_splash_animate();
		else
			splash_animate();
	}
	else
		content_animate();




	// middle - hero image
	// doesn't work on safari
	/*
	$('#hero_image').each(function() {
		var container = $(this).parent().height();
		var image = $(this).height();
		$(this).css('margin-top', (container - image) / 2 + 'px');
	});
	*/


	$('#gallery').easySlider({
		auto: false,
		continuous: false,
		speed: 600,
		prevText: '<',
		nextText: '>',
		controlsBefore:	'<div id="gallery_nav">',
		controlsAfter:	'</div>',
		controlsFade: false,
	});


    
});


