$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};


$(document).ready(function() {
	
	
	if ( jQuery.trim( $('#left-window').html() ) != "" ) {
		$('#left-window').fadeTo('normal', 1, function() {
			if ( jQuery.trim( $('#vert-menu').html() ) != "" ) {
				$('#vert-menu').fadeTo('normal', 1, function() {
					if ( jQuery.trim( $('#right-window').html() ) != "" )
						$('#right-window').fadeTo('normal',1);
				
				});
			} else { 
				if ( jQuery.trim( $('#right-window').html() ) != "" ) {
					$('#right-window').fadeTo('normal', 1);
				}
			}
		});
	}
	
	if ( $('#lockerTable') ) {
		$('#lockerTable').find('td').mouseover(function() {
			$('#lockersModel').attr( 'src', '../images/lockers/locker_models_'+$(this).attr('id')+'.jpg' );
		}).mouseout(function() {
			$('#lockersModel').attr( 'src', '../images/lockers/locker_models.jpg' );
		});
	
	}
	
	if ( $('#model-a') ) {
		$('#model-a').find('li').mouseover( function() {
			id = $(this).attr('id').substr(4,1);
			$('#model-a-img').attr( 'src', '../images/lockers/ModelA-'+id+'.gif' );
		}).mouseout( function() { 
			$('#model-a-img').attr( 'src', '../images/lockers/ModelA.gif');
		});
	}
	
	if ( $('#model-b') ) {
		$('#model-b').find('li').mouseover( function() {
			id = $(this).attr('id').substr(4,1);
			$('#model-b-img').attr( 'src', '../images/lockers/locker_interiors-'+id+'.gif' );
		}).mouseout( function() { 
			$('#model-b-img').attr( 'src', '../images/lockers/locker_interiors.gif');
		});
	}
	
		
});

oldImg = ""; 
function flipImage(img, gallery) { 
	$prev = $('#prevImage');
	
	
	if ( gallery == true ) {
		$prev.attr( 'src', img ).wait(100);
			$prev.fadeTo(1,1, function() {
				$prev.css( 'display', 'block' );
				var height = $prev.outerHeight();
				var width = $prev.outerWidth();
				$prev.click(function(){flipImage(false);});
				
				theTop = (200 - (parseInt(height) / 2));
				theLeft = (700 - (parseInt(width) / 2));
			
				
			
				$prev.css('top',theTop+2);
				$prev.css('left',theLeft);
				$prev.fadeTo(1,1);	
			});	
	
	} else {	
		if ( oldImg == "" ) oldImg = $prev.find('img').attr( 'src' );
		
		if ( img == false ) {

			$prev.fadeTo('fast',.01, function() {
				$prev.css( 'display', 'none' );
			});		
		} else {
			
			$prev.attr( 'src', img ).wait(250);
			$prev.fadeTo(1,.01, function() {
				$prev.css( 'display', 'block' );
				var height = $prev.outerHeight();
				var width = $prev.outerWidth();
				$prev.click(function(){flipImage(false);});
				
				theTop = (200 - (parseInt(height) / 2));
				theLeft = (700 - (parseInt(width) / 2));
			
				
			
				$prev.css('top',theTop+2);
				$prev.css('left',theLeft);
				$prev.fadeTo('fast',1);	
			});
		}
	}
}

function hideContent() { 
	$('#content').children().add('#prevImage').fadeTo(1,.01);
	
}
function do_accordion() {
	$('.accordion').accordion({clearStyle: true, autoHeight: false, alwaysOpen: false});
}