mmove=0;
mtimer=50;
function timerMove() {
	mtimer--;
	if(mtimer==0){
		$('.central_image .right').click();
		mtimer=50;
	}
	setTimeout("timerMove()",150);
}
$(document).ready(function(){

        $('a.hider').css('text-decoration', 'none');
	$('a.hider').css('border-bottom','1px dashed');
	$('.hider a').css('text-decoration', 'none');
	$('.hider a').css('border-bottom','1px dashed');
	$('.hider').each(function(){
		$(this).next().hide();
	});
	$('.hider').click(function(){
		if($(this).next().css('display')=='none'){
			$(this).next().slideDown(200);
		} else {
			$(this).next().slideUp(200);
		}
		return false;
	});

	timerMove();
	$('.gallery').each(function(){
		if($(this).find('.item').length>4){
			$(this).find('.arrow').css('display','block');
			$(this).find('.container').wrapInner('<div class="slide" />');
			$(this).find('.slide').css('position','relative');
			$(this).find('.slide').css('width', '200%');
			$(this).find('.slide').css('white-space','nowrap');
			$(this).find('.item').css('width','12.5%');
		}
		for(i=0;i<$(this).find('.item').length;i++){
			$(this).find('.item').first().insertAfter($(this).find('.item').last());
		}
	});
	$('.central_image').each(function(){
		$(this).children('div').css('z-index',10);
		$(this).children('div').css('left',900);
		$(this).children('div').first().css('z-index',20);
		$(this).children('div').first().css('left',0);
		$(this).children('div').first().addClass('selected');
	});
	$('.central_image .right').click(function(){
		mtimer=50;
		if(mmove==0){
			mmove=1;
			$(this).parent().children('.selected').animate({left: -300, opacity: 0}, 1000, function(){$(this).removeClass('selected'); mmove=0;});
			if($(this).parent().children('.selected').nextAll().length>0){
				$(this).parent().children('.selected').next().css('opacity',0);									  
				$(this).parent().children('.selected').next().css('left',300);									  
				$(this).parent().children('.selected').next().animate({left: 0, opacity: 1}, 1000, function(){$(this).addClass('selected')});
			} else {
				$(this).parent().children('div').first().css('opacity',0);									  
				$(this).parent().children('div').first().css('left',300);									  
				$(this).parent().children('div').first().animate({left: 0, opacity: 1}, 1000, function(){$(this).addClass('selected')});
			}
		}
	});
	$('.central_image .left').click(function(){
		mtimer=50;
		if(mmove==0){
			mmove=1;
			$(this).parent().children('.selected').animate({left: 300, opacity: 0}, 1000, function(){$(this).removeClass('selected'); mmove=0;});
			if($(this).parent().children('.selected').prevAll().length>2){
				$(this).parent().children('.selected').prev().css('opacity',0);									  
				$(this).parent().children('.selected').prev().css('left',-300);									  
				$(this).parent().children('.selected').prev().animate({left: 0, opacity: 1}, 1000, function(){$(this).addClass('selected')});
			} else {
				$(this).parent().children('div').last().css('opacity',0);									  
				$(this).parent().children('div').last().css('left',-300);									  
				$(this).parent().children('div').last().animate({left: 0, opacity: 1}, 1000, function(){$(this).addClass('selected')});
			}
		}
	});
	
	$('.gallery .arrow.right').click(function(){
		if(mmove==0){
			mmove=1;
			dx=$(this).parent('.gallery').find('.item').first().outerWidth(true);
			$(this).parent('.gallery').find('.slide').animate({left: '-'+dx+'px'},dx*1.5, function(){
				$(this).css('left',0);
				$(this).find('.item').first().insertAfter($(this).find('.item').last());
				mmove=0;
			});
		}
	});
	
	$('.gallery .arrow.left').click(function(){
		if(mmove==0){
			mmove=1;
			dx=$(this).parent('.gallery').find('.item').last().outerWidth(true);
			$(this).parent('.gallery').find('.slide').css('left','-'+dx+'px');
			$(this).parent('.gallery').find('.item').last().insertBefore($(this).parent('.gallery').find('.item').first());
			$(this).parent('.gallery').find('.slide').animate({left: '0'},dx*1.5, function(){mmove=0; });
		}
	});
	$('#geography area').click(function(e){
		$('.popup').css('left',e.pageX-$('.map_image').offset().left);
		$('.popup').css('top',e.pageY-$('.map_image').offset().top);
		$('.popup').load($(this).attr('href'));
        $('.popup').fadeIn(200);
        return false;
	});
});

