jQuery(document).ready(function($){
	
	if( $('#s').length ){		
		if( $('#s').val() == '' ){
			$("#s").val( 'Search tealartgallery.com' );
		}
	}
	
	$( 'input:text, textarea' ).each(function(){
		$( this ).data( 'default', $( this ).val() );
		$( this )
			.addClass( 'inactive' )
			.focus( function(){
					if( $(this).val() == $(this).data( 'default' ) ){
						$(this).val("");
					}
					$(this).removeClass( 'inactive' );
				})
			.blur( function(){
					if( $.trim( $( this ).val() ) == "" ){
						$( this ).val( $(this).data( 'default' ) );
					}
					$(this).addClass( 'inactive' );
				});
	});
	
	
	// FANCY BOX GALLERY
	$('dt a').attr('rel', 'gallery').fancybox({
		titlePosition: 'inside',
		onStart: function(){
			$('#wrapper').animate({opacity:0}, 1000 );
		},
		onClosed: function(){
			$('#wrapper').animate({opacity:1}, 1000 );
		}
	});
	
	if( typeof($.browser) != 'undefined' ){
		if( $.browser.msie && parseFloat($.browser.version) < 7 ){
			$('body').addClass('ie6');
		}
	}
	
	// Join MailChimp Email List
	subscribing = false;
	
	$('.eventsSubscription').click(function(){
	
		if(subscribing == false){ //only run if it's the first time
			obj=$(this);
			replacementPar=$(this).parent();
			href=$(this).attr('href');
			
			function outputForm(data){
				obj.attr('href', '');
				if(!obj.hasClass('keep')){
				obj.hide();}
				newHTML='<div id="subscriptionForm">'+data+'</div>';
				replacementPar.after(newHTML);
				$('#subscriptionForm').slideDown();
			}
			
			$.ajax({
			  url: href,
			  cache: false,
			  success: function(html){
				outputForm(html);
			  },
			  error:function () {
				  msg="We apologize, but our subscription system has had a hiccup. Please email us at <a href=\"mailto:contact@tealartgallery.com\">contact@tealartgallery.com</a> and we will add you to the mailing list.";
				 outputForm(msg);
				}
			});
			
			subscribing = true; // cancels future action
		} // if subscribing
		
		return false; // return false every time
	});
	
	
	(function selectArtist(){ // jquery selects the current artist by comparing URL and href and adds a class to the link in the artist nav
	
	// broken...
	
	
//					   
//		href=window.location.href;
//		var regexp = [^\/]+\(?=\/[^\/]+$\);
//		newHref = regexp.exec(href);
//		
//		if( $('ul.artists').length ){
//			$('ul.artists a').each(function(i){
//				linkHref=$(this).attr('href');
//				if(linkHref==newHref[0]){
//					$(this).addClass('active');
//				}
//			});
//		}

	})();
		
});
