Cufon.replace('#content h1', { fontFamily: 'Helvetica' });

$(document).ready(function(){
	
	$('#FormValue_EmailAddress').focus(function () {
		$(this).toggleClass('itemFocus').toggleClass('itemFade');
	});
	$('#FormValue_EmailAddress').blur(function () {
		$(this).toggleClass('itemFocus').toggleClass('itemFade');
	});
	
	function galleryCallback() {
		$('#thumbs').autoscroll(AUTOSCROLL_X);
	}
	
	// lightbox initialization
	$("a.flv450").fancybox({ 'hideOnContentClick': false, 'width': 450, 'height': 369, 'overlayShow': true, 'overlayOpacity': .75, 'type':'iframe' });
	$("a.swf800").fancybox({ 'hideOnContentClick': false, 'width': 800, 'height': 595, 'overlayShow': true, 'overlayOpacity': .75, 'type':'iframe', 'titleShow':false, 'swf':{wmode: 'opaque'} });
	$("a.lightbox").fancybox({ 'hideOnContentClick': false, 'width': 600, 'height': 450, 'overlayShow': true, 'overlayOpacity': .75 });
	$("a.movlightbox").fancybox({ 'hideOnContentClick': false, 'width': 600, 'height': 450, 'overlayShow': true, 'overlayOpacity': .75, 'type':'iframe' });
	$("a.gallery").fancybox({ 'hideOnContentClick': false, 'width': 700, 'height': 500, 'overlayShow': true, 'overlayOpacity': .75, 'type':'iframe', 'onComplete': galleryCallback }); 
	
	
	// Rollovers for showcase examples
	var showcaseDesc = new Array();
	$("div.showcaseExample")
		.each(function(i){	this.id = "showcase" + i;	showcaseDesc[this.id] = 0;	})
		.hover(
			function ()
			{	var fade = $(this).children("div.showcaseDesc");
				fade.stop().animate({ height: "241px", opacity: 1 }, 400 );	},
			function ()
			{	var fade = $(this).children("div.showcaseDesc");
				fade.stop().animate({ height: "0px", opacity: 0 }, 400 );	}	);
	
	// Rollovers for showcase categories
	var showcaseDesc = new Array();
	$("div.showcaseCategory")
		.each(function(i){	this.id = "showcase" + i;	showcaseDesc[this.id] = 0;	})
		.hover(
			function ()
			{	var fade = $(this).children(".showcaseDesc"); // Actual text, fade to 100%
				fade.stop().animate({ height: "183px", opacity: 1 }, 400 );
				var fadeBG = $(this).children(".showcaseCategoryBG"); // Background, fade to 75%
				fadeBG.stop().animate({ height: "200px", opacity: .75 }, 400 );
			},
			function ()
			{	var fade = $(this).children(".showcaseDesc");
				fade.stop().animate({ height: "0px", opacity: 0 }, 400 );
				var fadeBG = $(this).children(".showcaseCategoryBG");
				fadeBG.stop().animate({ height: "0px", opacity: 0 }, 400 );
			}
		);
			
			
	// Change the majority of first words of H1 and H3 to a different color.
	// If it's three words, the first two will be changed.
	// If it's two words the first will be changed.
	$('#content h1').each(function (i) {
		if ( $(this).html().substring(0,1) != '<' )
		{	var broken_string = $(this).html().split(" ");
			var broken_start = ( Math.round(broken_string.length/2) ) - 1;
			var new_string = '';
			for ( j = 0 ; j < broken_string.length ; j++ )
			{	if (j == 0 )
				{	new_string = new_string + "<span style='color:#FFFFFF'>";	}
				new_string = new_string + broken_string[j];
				if (j == broken_start )
				{	new_string = new_string + "</span>";	}
				new_string = new_string + " ";
			}
			var string_replace = $(this).html(new_string);
		}
	});
	$('h1, h3').each(function (i) {
		if ( $(this).html().substring(0,1) != '<' )
		{	var broken_string = $(this).html().split(" ");
			var broken_start = ( Math.round(broken_string.length/2) ) - 1;
			var new_string = '';
			for ( j = 0 ; j < broken_string.length ; j++ )
			{	if (j == 0 )
				{	new_string = new_string + "<span style='color:#414d53'>";	}
				new_string = new_string + broken_string[j];
				if (j == broken_start )
				{	new_string = new_string + "</span>";	}
				new_string = new_string + " ";
			}
			var string_replace = $(this).html(new_string);
		}
	});
});