var carInt = 0;
var middleh = 0;
var maxh = 0;
var maxScroll = 0;
$(document).ready(function(){
	$('body').click (function (e) {
		var part = $(e.target).attr ('alt');
		var url = '';
		if (part.indexOf ('bodypart') >= 0) {
			$('.parts-links a').each (function () {
				if ($(this).attr ('rel') == part)
					url = $(this).attr ('href');
			})
			if (url) document.location = url;
			return false;
		}
	})
						   
	$('#bodymap area').hover(function(){
		var id = $(this).attr('alt');
		$('#statue img:not(.censored)').hide();
		if (id == 'bodypart-6') $('#statue .censored').hide();
		$('#' + id + ', .bodypixel').show();
	}, function(){
		var id = $(this).attr('alt');
		$('#' + id).hide();
		$('#statue .censored').show();
	});
	
	$('#bodymap-back area').hover(function(){
		var id = $(this).attr('alt');
		$('#statue-back img:not(.censored)').hide();
		if (id == 'bodypart-12') $('#statue-back .censored').hide();
		$('#' + id + ', .bodypixel').show();
	}, function(){
		var id = $(this).attr('alt');
		$('#' + id).hide();
		$('#statue-back .censored').show();
	});
	
	
	$('#turn-statue').click(function(){
		
		if ($(this).hasClass('to-left')) {
			$(this).attr('class','to-right');
			$('#statue, .front-parts').hide();
			$('#statue-back, .back-parts').show();
		} else {
			$(this).attr('class','to-left');
			$('#statue, .front-parts').show()
			$('#statue-back, .back-parts').hide();
		}
	});
	
	$('.parts-links a').click(function(){
						   
	});
	
	$('.parts-links a').hover(function(){
		var id = $(this).attr('rel');	
		$('#statue img:not(.censored), #statue-back img:not(.censored)').hide();
		if (id == 'bodypart-6') $('#statue .censored').hide();
		if (id == 'bodypart-12') $('#statue-back .censored').hide();
		$('#' + id + ', .bodypixel').show();
		
	}, function(){
		var id = $(this).attr('rel');
		$('#' + id).hide();
		if (id == 'bodypart-6') $('#statue .censored').show();
		if (id == 'bodypart-12') $('#statue-back .censored').show();
		
	});
	
	$('.carousel ul').width(($('.carousel ul li:first').width() + 55)*$('.carousel ul li').size());
	middleh = $('.carousel').width()/2;
	maxh = $('.carousel').width();
	maxScroll = $('.carousel ul').width() - $(window).width();
	$('.carousel ul').mouseover(function(e){
		//$('body').append(e.pageX + '<br />');
		if (!$('.carousel ul').is(':animated')) {
				if (e.pageX <= middleh) {
					//$('.carousel ul').stop().animate({'left': -maxScroll + 'px'},2000);
					carInt = setInterval("scrollRight()",50);
				} else {
					//$('.carousel ul').stop().animate({'left': '20px'},2000);
					carInt = setInterval("scrollLeft()",50);
				}
		}
	}).mouseout(function(){
		clearInterval(carInt);
	});
	
	$('.header .i-menu a.feedback, .popform .form .close img').click(function(){
		if ($('.popform').is(':visible')) $('.popform').hide(300);	
		else $('.popform').show(300);
		return false;								  
	});
	$('.compose-mail').click(function(){
		if ($('.popform').is(':visible')) $('.popform').hide(300);	
		else $('.popform').show(300);
						  
	});
	
	$('.mapwoman a').click(function(){
		$('#overlay').height($('.container').height() + 562).show().click(function(){
			$('#contact-map, #overlay').hide();
			return false;
		});
		$('#contact-map').show();
		$('#contact-map .close').click(function(){$('#overlay').click()});
		return false;
	});
	
	
	$(window).resize(function(){
		middleh = $('.carousel').width()/2;
		maxh = $('.carousel').width();
		maxScroll = $('.carousel ul').width() - $(window).width();						  
	});
});


function scrollLeft() {
	
	if ($('.carousel ul').get(0).offsetLeft <= -maxScroll) {
		clearInterval(carInt);
	} else
		$('.carousel ul').css('left', ($('.carousel ul').get(0).offsetLeft - 5)+ 'px');
}		
function scrollRight() {
	
	if ($('.carousel ul').get(0).offsetLeft >= 20) {
		clearInterval(carInt);
	} else 
		$('.carousel ul').css('left', ($('.carousel ul').get(0).offsetLeft + 5)+ 'px');
}
 
