/**
  * main.js
  * author nschaden
  */


$(document).ready(function() {
	if ($.browser.msie && $.browser.version.substr(0,1)<=6) {
		if ($('#container_photo').length > 0) {
			$('#container_photo .hoverlink').css('height',$('#container_photo').height() + 'px');
			$('#container_photo .hoverlink').css('width',parseInt($('#container_photo').width()/3,10) + 'px');
		}
	}
	
	if ($('#container_photo .mainphoto.customdim').length > 0) {
		var newwidth = $('#container_photo img.mainphoto').width();
		if (newwidth > 300) {
			$('#container_photo').css('width',newwidth + 'px');
			$('#container_photo .details,#container_photo .details .bg').css('width',newwidth-20 + 'px');
		}
	}
	$('#nav_main li').hover( 
		function() {
			var $this = $(this);
			if (!$.browser.msie || $.browser.version.substr(0,1)>6)
				$this.children('.bg').stop(true,true).fadeIn(500);
			$this.children('a').stop(true,true).addClass('active',500);
		},
		function() {
			var $this = $(this);
			if (!$.browser.msie || $.browser.version.substr(0,1)>6)
				$this.children('.bg').stop(true,true).fadeOut(500);
			$this.children('a').stop(true,true).removeClass('active',500);
		}
		
	);
	
	// $('#container_photo').hover(
	// 	function() {
	// 		$(this).children('.details').stop(true,true).fadeIn(500);
	// 	},
	// 	function() {
	// 		$(this).children('.details').stop(true,true).fadeOut(500);
	// 	}
	// );
	
	var detailstimer;
	$('#container_photo').mouseenter(function() {
		var details = $(this).children('.details');
		details.stop(true,true).addClass('active').fadeIn(500);
		detailstimer = setTimeout(function() { details.removeClass('active').fadeOut(500); },3000);
	});
	
	$('#container_photo').mousemove(function() {
		var details = $(this).children('.details');
		if (!details.hasClass('active')) {
			details.stop(true,true).addClass('active').fadeIn(500);
		}
		clearTimeout(detailstimer);
		detailstimer = setTimeout(function() { details.removeClass('active').fadeOut(500); },3000);
	});
	
	$('#container_photo .details').mousemove(function(event) {
		console.log('others');
		clearTimeout(detailstimer);
		event.stopPropagation();
	});
	
	$('#container_photo').mouseleave(function() {
		var details = $(this).children('.details');
		details.removeClass('active animating');
		clearTimeout(detailstimer);
		details.stop(true,true).fadeOut(500);
	});
	
	$('#container_photo .hoverlink').hover(
		function() {
			$(this).children().stop(true,true).fadeIn(500);
		},
		function() {
			$(this).children().stop(true,true).fadeOut(500);
		}
	);
	
	$('#comments_toggle').click(function() {
		var comments = $('#comments');
		var cchildren = comments.children();
		cchildren.hide();
		comments.addClass('active',500);
		cchildren.delay(500).fadeIn(500);
	});
	
	$('#comments_close').click(function() {
		var comments = $('#comments');
		var cchildren = comments.children();
		cchildren.fadeOut(500);
		comments.delay(500).removeClass('active',500);
	});
		
	$('#subnav_archives .filters a').click(function() {
		var overlay = $('#archives_overlay');
		var ochildren = overlay.children();
		ochildren.hide();
		overlay.addClass('active',500);
		ochildren.delay(500).fadeIn(500);
	});
	
	$('#archives_overlay #close_button').click(function() {
		var overlay = $('#archives_overlay');
		var ochildren = overlay.children();
		ochildren.fadeOut(500);
		overlay.delay(500).removeClass('active',500);
	});
	
	$('#archives_grid li').hover(
		function() {
			$(this).children('.date').stop(true,true).fadeIn(300);
		},
		function() {
			$(this).children('.date').stop(true,true).fadeOut(300);
		}
	);
	
	
	
	
});
