$(document).ready(function(){
	$('div.peoples:gt(0)').hide();
	$('ul.peoples li:first').addClass('active');
	$('ul.peoples li').click(function(){
		$('ul.peoples li').removeClass('active');
		$(this).addClass('active');
		var index = $('ul.peoples li').index(this);
		$('div.peoples').hide();
		$('div.peoples:eq('+index+')').show();
		$('.footer .left').get(0).innerHTML+=''; // for ie
	});

	$('div.gallery:gt(0)').hide();
	$('ul.gallery li:first').addClass('active');
	$('ul.gallery li').click(function(){
		$('ul.gallery li').removeClass('active');
		$(this).addClass('active');
		var index = $('ul.gallery li').index(this);
		$('div.gallery').hide();
		$('div.gallery:eq('+index+')').show();
		$('.footer .left').get(0).innerHTML+=''; // for ie
	});
	$('.footer .left').get(0).innerHTML+=''; // for ie

	$('div.gallery a').click(function(){
		var gwrap = $(this).parents('.gallery').find('div.wrap');
		gwrap.html('').addClass('loading');
		var title = $(this).find('img').get(0).title;
		var gimg = $('<img src ="'+this.href+'" alt="" />').css({'visibility':'hidden'}).load(function(){
			$(this).css({'visibility':'visible'});
			gwrap.parent().find('>p').html(title);
		}).appendTo(gwrap);
		return false;
	});


	$('#sl').click(function(){
		if ($('.footer .sl').css('display')=='none'){
			$('.footer .sl').css({display:'block'});
			$(document.body).click(function(){
				$('.footer .sl').css({display:'none'});
				$(document.body).unbind('click');
			});
			return false;
		}else{
			$('.footer .sl').css({display:'none'});
			return false;
		}
	});

	$(window).load(function(){
	    if ($('ul.main').length){
			$('.footer .left').get(0).innerHTML+=''; // for ie

			$('ul.main img').css({'opacity':0.6});
			$('ul.main img').hover(
			function(){
				$(this).animate({'opacity':1},200);
			},
			function(){
				$(this).animate({'opacity':0.6},200);
			});
		}
	});

	if ($('.next a').length || $('.previous a').length){
		function ctrlr(e){
			if (e.ctrlKey && e.which==39 && $('.next a').length){
				document.location = $('.next a').get(0).href;
				return false;
			}
			if (e.ctrlKey && e.which==37 && $('.previous a').length){
				document.location = $('.previous a').get(0).href;
				return false;
			}
		}
		$(document).keypress(function(e){ctrlr(e)});
		$(document).keydown(function(e){ctrlr(e)});
	}
	var play = false;
	$('div.play').click(function(){
		play = !play;
		if (play){
			$('div.bgn').css({display: 'block','opacity': 0});
			$('div.bgn').animate({'opacity': 1},1500,function(){
				$(document.body).addClass('pls');
			});
		}else{
			$('div.bgn').animate({'opacity': 0},1500,function(){
				$(document.body).removeClass('pls');
			});
		}
	});
});

