$(document).ready(function(){

	/* ----- form input functionality ----- */

	$("input.dynamic").focus(function() {
		if ($(this).val() == $(this).attr("title")) $(this).val('');
	});

	$("input.dynamic").blur(function() { 
		if ($(this).val() == '') $(this).val($(this).attr("title"));
	});

	$("textarea.dynamic").focus(function() {
		if ($(this).val() == $(this).attr("title")) $(this).val('');
	});

	$("textarea.dynamic").blur(function() { 
		if ($(this).val() == '') $(this).val($(this).attr("title"));
	});

	/* ----- image captions ----- */

	$("#main img").each(function() {
	    var img_class = $(this).attr('class');
	    var img_caption = ($(this).attr('alt').length > 0) ? $(this).attr('alt') : '';
	    var imagespan = $('<span/>').attr('class', img_class).css('display', 'block');
	    $(this).removeAttr('class').wrap(imagespan);
	    $('<span class="image_caption">'+img_caption+'</span>').insertAfter(this);
	});

	/* ----- lightbox ----- */

	$("a[rel='lightbox']").colorbox();
	
	/* ----- slideshow(s) ----- */
	
	$('.slideshow').cycle();

	/* ----- locations ----- */

	$("a.mapit").colorbox({iframe:true, innerWidth:520, innerHeight:500});

	$("a.video").colorbox({iframe:true, innerWidth:950, innerHeight:560});

	$("a.foamed").colorbox({iframe:true, innerWidth:600, innerHeight:484});

	$('#locations li strong a').click(function(e) {
		
		// remove any callouts
		$('#location-callouts li').hide();
		
		// show callout
		$($(this).attr('href')).show();
		
		// remove any current location info
		$('#locations li').removeClass('current').find('address').slideUp('fast');

		// remove any mapit links
		$('#locations a.mapit').hide();

		// show location info + mapit
		$(this).parents('li:first').addClass('current').find('address').slideDown().find('a.mapit').fadeIn('fast');		

		e.preventDefault();
		
	});

	// no hover event on locations page for iPad
	if (ipad == false) {

		$('#locations li').mouseover(function(e){
		
		    e.stopPropagation();
	
			// show callout by href (for main locations page)
			$($(this).find('a.callout').attr('href')).show();
			
			// or show callout by rel for 'fixed' locations page
			$($(this).find('a.callout').attr('rel')).show();
		
		});
		
		
		$('#locations li').mouseout(function(e){
		
		    e.stopPropagation();                    
		
			// remove any callouts
			$('#location-callouts li').hide();
		
		});
	
	}

});
