	$(window).scroll(function() {
		$('#gallery_fade').css({'top' : String($(window).scrollTop()) + 'px'});
	});

	var gal_current = 0;
	var gal_timer;
	var mseconds = 5000; /* 1s = 1000ms */

	
	$('#gal_list_down')
	.mouseenter(function(){
		$('#gal_list2').show();
	});
	

	$('#gal_list2')
	.mouseleave(function(){
		$('#gal_list2').hide();
	});
	
	
	$('#gal_list').find('li')
	.mouseenter(function(){	
		gal_list_enter($(this));				
		gal_current = $(this).index();		
	})
	.mouseleave(function(){	
		$(this).removeClass('gal_list_hover');		
	});
	$('#gal_list2').find('li')
	.mouseenter(function(){	
		gal_list_enter($(this));				
		gal_current = $(this).index() + $('#gl_full').find('li').size();		
	})
	.mouseleave(function(){	
		$(this).removeClass('gal_list_hover');		
	});
		
	
	$('#gl_full')
	.mouseenter(function(){	
		clearTimeout(gal_timer);
		$('#gal_list').find('li').removeClass('gal_list_hover');
		$('#gal_list2').find('li').removeClass('gal_list_hover');
	})
	.mouseleave(function() {
		gal_switch();
	});	
	$('#gl_full2')
	.mouseenter(function(){	
		clearTimeout(gal_timer);
		$('#gal_list').find('li').removeClass('gal_list_hover');
		$('#gal_list2').find('li').removeClass('gal_list_hover');
	})
	.mouseleave(function() {
		gal_switch();
	});	
	
			
	function gal_list_enter(obj) {			
		var id = obj.attr('id');
		var name = obj.text();
		var file = 'galleries/' + id + '/preview.jpg';
		
		$('#gal_preview_clone').css('background-image', $('#gal_preview').css('background-image'));
		$('#gal_preview').hide().css('background-image', 'url("' + file + '")').fadeIn(1000);
		obj.addClass('gal_list_hover');
		$('#gal_preview_title').text(name).attr('rel', id);
	}

	
	var gal_total = $('#gl_full').find('li').size() + $('#gl_full2').find('li').size();
	function gal_switch() {
		var elem = $.merge($('#gl_full').find('li'), $('#gl_full2').find('li'));
		
		if(gal_current > gal_total - 1) {
			gal_current = 0;
		}
		
		elem.eq(gal_current-1).triggerHandler('mouseleave');
		
		gal_list_enter(elem.eq(gal_current));
		
		gal_current++;
		
		gal_timer = setTimeout(gal_switch, mseconds);
	};
	
	gal_switch();
	
	
	function open_gallery(id) {
		$('#gallery_popup').css({
			'margin-left'	: '-475px',
			'width'			: '950px',
			'height'		: '520px'
		});
		$('#gallery_popup_inner').css({
			'width'			: '950px',
			'height'		: '520px',
			'overflow'		: 'auto'
		});

		$('#gallery_fade').fadeTo('fast', 0.9).css({'top' : String($(window).scrollTop()) + 'px'});
		$('#gallery_popup_inner').html('<img src="design/img/loading.gif"><br> <br>loading');
		$('#gallery_popup').fadeIn().css({'top' : String($(window).scrollTop() + 100) + 'px'});
		$('#gallery_popup_inner').load('scripts/gallery_load.php', { 'id': id }, function() {
			$('#gallery_popup_inner').hide();
			$('#gallery_popup_inner').scrollLeft(0);
			$('#gallery_popup_inner').show();
		});
	}
	
	$('#gal_preview_title').click(function(){
		open_gallery($(this).attr('rel'));
	});
	
	$('#gal_list').find('li').click(function(){
		open_gallery($(this).attr('id'));
	});	
	$('#gal_list2').find('li').click(function(){
		open_gallery($(this).attr('id'));
	});
	
	$('#gallery_popup_close').click(function(){
		$('#gallery_popup').fadeOut();
		$('#gallery_fade').fadeOut();
	});
	
	$('#gallery_fade').click(function() {
		$('#gallery_popup_close').click();
	});
	
	
	
	
	$('.exp').find('.exp_btn').click( function() {
		$(this).parent().find('.exp_cnt').slideToggle('fast');
	} );
