/*

	@Class:	InputClearAndReplace
	@Author:	Brandon Gray for O3 World 2008
	@Brief:	Loops through all elements with a class name of 'clear_replace' and clears the default text when focused.
			When focus is lost it checks to see if the field is blank (no new data entered), if value is blank the default text is placed back in.
	@Example: <input type="text" name="firstname" id="firstname" value="" class="clear_replace" />
			
*/

var InputClearAndReplace = new Class ({
	
	options: {
		
		InputElement: '.clear_replace'
		
	},
	
	initialize: function()  {
		
		var inputElementList = $$( this.options.InputElement );
		var originalValue = new Array();
		
		inputElementList.each( function( element, i ) {
			
			originalValue.push( inputElementList[ i ].value );
			
			element.onfocus = function() {
				
				if( this.value == originalValue[ i ] ) this.value = '';
				
			},
			
			element.onblur = function() {
				
				if( this.value == '' ) this.value = originalValue[ i ];
				
			}
			
		});
		
	}

});


function initEventTabs() {

	var menuAnchors = $( 'events_nav_tabs' ).getElements( 'a' );

	for ( var i = 0; i < menuAnchors.length; i++ ) {

		if ( menuAnchors[ i ].getAttribute( 'href' ) && menuAnchors[ i ].getAttribute( 'rel' ) == 'swap' ) {

			menuAnchors[ i ].addEvent( 'click', function() {
				
				// Remove the active state from all links
				for ( var j = 0; j < menuAnchors.length; j++ ) {
					
					menuAnchors[ j ].removeClass( 'active' );
					
				}
				
				swapEventContent( this.id );

			});

		}

	}

}

function swapEventContent( _id ) {
	
	// Set the active state on the selected link
	$( _id ).addClass( 'active' );

	var tabs = $$( '#events .tab_content' );
	
	for ( var i = 0; i < tabs.length; i++ ) {

		tabs[ i ].setStyle( 'display', 'none' );		

	}

	var newID = 'content_' + _id;

	var content = $( newID ).setStyle( 'display', 'block' );
	
}

function initGalleryTabs() {

	var menuAnchors = $( 'galleries_nav_tabs' ).getElements( 'a' );

	for ( var i = 0; i < menuAnchors.length; i++ ) {

		if ( menuAnchors[ i ].getAttribute( 'href' ) && menuAnchors[ i ].getAttribute( 'rel' ) == 'swap' ) {

			menuAnchors[ i ].addEvent( 'click', function() {
				
				// Remove the active state from all links
				for ( var j = 0; j < menuAnchors.length; j++ ) {
					
					menuAnchors[ j ].removeClass( 'active' );
					
				}
				
				swapGalleryContent( this.id );

			});

		}

	}

}

function swapGalleryContent( _id ) {
	
	// Set the active state on the selected link
	$( _id ).addClass( 'active' );

	var tabs = $$( '#gal_retail .tab_content' );
	
	for ( var i = 0; i < tabs.length; i++ ) {

		tabs[ i ].setStyle( 'display', 'none' );		

	}

	var newID = 'content_' + _id;

	var content = $( newID ).setStyle( 'display', 'block' );
	
}

window.addEvent( 'load', function() {
							  
	var InputList = new InputClearAndReplace();
	
	if ( $( 'locations_map' ) ) displayMap();
	if ( $( 'events_nav_tabs' ) ) initEventTabs();
	if ( $( 'galleries_nav_tabs' ) ) initGalleryTabs();
	
});
// Takes three parameters: this, 'focus' or 'blur', 'default field value'
function SwapFocus(obj, state, msg){
	if(state == 'focus'){
		if(obj.value == msg){
			obj.value = '';
		}
	} else if(state == 'blur') {
		if(obj.value == ''){
			obj.value = msg;
		}
	}
}

