function ucfirst (str) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

var $_GET = {};

document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) {
        return decodeURIComponent(s.split("+").join(" "));
    }

    $_GET[decode(arguments[1])] = decode(arguments[2]);
});

if(typeof(Cufon)!= 'undefined')
{
	Cufon.replace('h3' );
	Cufon.replace('h4' );
	Cufon.replace('h5' );
	Cufon.replace('h6' );
	Cufon.replace('#main-content blockquote' );
	Cufon.replace('#do-teaser h6' ); 
	Cufon.replace('#do-teaser p' );
	Cufon.replace('.item-name ' );
}
function slideShow(box) {
    var active = $('#'+box+' div.active');

    if ( active.length == 0 ) { 
        active = $('#'+box+' div:last');
    }

    var next =  active.next().length ? active.next() : $('#'+box+' div:first');
    active.addClass('last-active');

    next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
    
}
function startSlideShow (class_name, seconds) {
    $('.'+class_name).each(function () {
        setInterval( "slideShow('"+$(this).attr('id')+"')", seconds * 3000 );
    });
}
//Cufon.replace('#nav a', {
	//hover: true});	
//begin beautiful jquery
		$(document).ready(function() {	
    // Send the class name and the seconds. 
    // Right now everything with this class has to have a unique id.
    startSlideShow('slide_show', 2);
			$(".replace-input").click(function()
			{
				$(this).toggleClass('selected');
				var newval = $(this).attr('tag');
				if($(this).hasClass('selected'))
				{
					$(this).parent().children('.replace-all').removeClass('selected').children('input').val('');
					$(this).children('input').val(newval);
				}else{
					$(this).children('input').val('');
				}
				SubmitSearch();
			});
			
			$(".replace-all").click(function()
			{
				$(this).toggleClass('selected');
				var newval = 'All';
				if($(this).hasClass('selected'))
				{
					$(this).parent().children('.selected').removeClass('selected').children('input').val('');
					$(this).toggleClass('selected');
					$(this).children('input').val(newval);
				}else{
					$(this).children('input').val('');
				}
				SubmitSearch();
			});
		
			function SubmitSearch()
			{
				//gather all my inputs
				$("form").submit();
			};

			$("#debug").click(SubmitSearch);
		
		
		//image fader for header 
		
			$('#teaser').innerfade({
				animationtype: 'fade',
				speed: 750,
				timeout: 6000,
				containerheight: '225px'
			});
			$('#contact-imgs').innerfade({
				animationtype: 'fade',
				speed: 750,
				timeout: 6000,
				containerheight: '225px'
			});
			
			
		//PIKACHOOOOOOOOOSE
		$("#inventory-images").PikaChoose({show_prev_next:false});
		
		//View Perma Link
		$("#perma a").hover(function() {
			$(this).prev("em").animate({opacity: "show", left: "-185"}, "slow");
		}, function() {
			$(this).prev("em").animate({opacity: "hide"}, "fast");
		});
		
		if(typeof($_GET["mess"])!="undefined")
		{
			alert($_GET["mess"]);
			//$('body').append('<a id="fancyme" href="#fancyme">'+$_GET["m"]+'</a>');
			//$('#fancyme').fancybox();
			//setTimeout("$('#fancyme').trigger('click')",1000);
		}
		
		//form fields prefills and clears
		$('#contact-form').find(':input[type!=hidden]').each(function()
		{
			var defaultText = $(this).attr('name').substr(8).replace(']', '');
			defaultText = ucfirst(defaultText);
			$(this).attr('value',defaultText);
			$(this).bind('focus',function()
			{
				$(this).attr('value','');
			});
			$(this).bind('blur',function()
			{
				if($(this).val() == "")
				{
					$(this).attr('value',defaultText);
				}
			});
		});
				
	});//Close Function


