$(document).ready(function() {
	$('input[type=text],input[type=password]').focus(function(){
		var currentVal = $(this).val();										// Read initial field value
		$(this).val('');														// Clear initial value

		$(this).blur(function(){
			var getNewVal = $(this).val();										// Read new input value
			if ( getNewVal == '' || getNewVal == ' ' ) {
				$(this).val(currentVal);										// Switch to initial value
			}
		});
	});
	
	/* cufon */
	if ( $('p#intro').length || $('h1.pageTitle') ) {
		Cufon.replace('p#intro, h1.pageTitle');
	}

	$('.gt li').hover(
		function(){
			$(this).children("ul").css("display","block");
		},
		function(){
			$(this).children("ul").css("display","none");
		}
	);


	/* hover for top navigation */
	$('ul#principal li').not('.on').hover(
		function(){
			var getClass = $(this).attr('class');
			$(this).css('background-color','#706f6e');
			$('ul#secundar li#'+getClass).addClass(getClass);
		},
		function(){
			var getClass = $(this).attr('class');
			$(this).css('background-color','#838382');
			$('ul#secundar li#'+getClass).removeClass(getClass);
		}
	);

	// clear site map last link
	$('#sitemap ul li:last a').css('border','none');

	// cycle text in masthead
	if ( $('#masthead').length ) {
		$('#masthead div').innerfade({ animationtype: 'fade', speed: 1500, timeout: 3000, type: 'random', containerheight: '210' }); ;
	}
	
	// handle description in catalog
	if ( $('ul.catalog li p.moreDesc').length ){
		$('ul.catalog li p.moreDesc').hide();
	}
	$('ul.catalog li a.heading').hover(
		function(){
			$(this).siblings('p.moreDesc').slideDown('fast');
		},
		function(){
			$(this).siblings('p.moreDesc').slideUp('fast');
		}
	);

	
	if($("#art_fund_tracker_container").length) {
		start("art_fund_tracker_container", $("#art_fund_tracker_container .pagination a.on").attr("title"));
	}

});

var detect = navigator.userAgent.toLowerCase();
var os_ = navigator.platform.toLowerCase();
var browser,thestring;

if (checkIt('safari')) browser = "Safari"
else browser = "not Safari"

if ( os_ == 'macppc' || os_ == 'macintel' ) os = "Mac"
else os = "not Mac"

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function start(id, uri) {

	$("#"+id).load(uri+" #"+id+" .inner", false, function() {
		next = $(".next", this).attr("title");
		timeout = setTimeout("start('"+id+"', '"+next+"')",4000);
		$(".paging").click(function(){
			clearTimeout(timeout);
			start(id,$(this).attr('title'));
		});
	});
}

function stop() {
	clearTimeout(timeout);
}

