var selected = null;
var tool = null;

$(document).ready(function(){
	var tool = document.createElement('img');
	$(tool).css({'position':'absolute', 'z-index':'200', 'display':'none' });
	$(tool).attr({'id':'tt'});
	$(tool).appendTo($('body'));
	
	var _id = 3;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	if (hashes.length > 0){
		var hash = hashes[0].split('=');
		if(hash[0]=='id' && !isNaN(hash[1])){
			var _id = parseInt(hash[1]);
		}
	}
	
	$("#gallery_left img").each(
		
		function(i){
			$(this).css('cursor', 'pointer');
						
			if(i!=_id){
				$(this).css('opacity', '0.5');
				$('#g'+$(this).attr('id').substring(2)).css({'display':'none', 'visibility':'hidden'});
			}
			else{
				selected = $(this).attr('id');
				$('#g'+$(this).attr('id').substring(2)).css({'display':'block', 'visibility':'visible'});
			}
				
			$(this).bind('mouseover', function(event){
								
				var sr = $(this).attr('src').substring(0, $(this).attr('src').length - 6) + 'tt.png';
								
				$('#tt').css({'top':$(this).position().top + 15, 'left':$(this).position().left + 50, 'display':'block'});
				$('#tt').attr({'src':sr});
				$(this).stop();
				$(this).fadeTo('300', '1.0');
				
			});
			
			$(this).bind('mouseout', function(){
				$(this).stop();
				$('#tt').css({'display':'none'});
				if(selected != $(this).attr('id')){
					$(this).fadeTo('300', '0.5');
				}
				
			});
			
			
			$(this).bind('click', function(){
				if(selected != $(this).attr('id')){
					$('#'+selected).fadeTo('300', '0.5');
					
					$('#g'+selected.substring(2)).css({'display':'none', 'visibility':'hidden'});
					selected = $(this).attr('id');
					$('#g'+selected.substring(2)).css({'display':'block', 'visibility':'visible'});
				}
			});
		}
	);
});
