$('document').ready(function()
{
	if (document.getElementById('home-photos')) {
		var photos = { now: 1, speed: 300 }
		var hp = $('div#home-photos');
		var hc = $('nav#home-controls');
		var resetPhotos = function() {
			if (photos.now) hidePhoto(photos.now);
			photos.now = null;
			if (!$.browser.msie) {
				$('#hp-1').stop(true).fadeTo(photos.speed, 1);
			} else {
				$('#hp-1').stop(true).show();
			}
		};
		var showPhoto = function(id) {
			if (photos.now) hidePhoto(photos.now);
			photos.now = id;
			if (!$.browser.msie) {
				$('#hc-'+id, hc).stop(true).fadeTo(photos.speed, 0);
				$('#hh-'+id, hc).stop(true).fadeTo(photos.speed, 1);
				$('#hr-'+id, hc).stop(true).fadeTo(photos.speed, 0);
				$('#hp-'+id, hp).stop(true).fadeTo(photos.speed, 1);
				$('#ht-'+id, hp).stop(true).fadeTo(photos.speed, 1);
			} else {
				$('#hc-'+id, hc).stop(true).hide();
				$('#hh-'+id, hc).stop(true).show();
				$('#hr-'+id, hc).stop(true).hide();
				$('#hp-'+id, hp).stop(true).show();
				$('#ht-'+id, hp).stop(true).show();
			}
		};
		var hidePhoto = function(id) {
			if (!$.browser.msie) {
				$('#hc-'+id, hc).stop(true).fadeTo(photos.speed, 1);
				$('#hh-'+id, hc).stop(true).fadeTo(photos.speed, 0);
				$('#hr-'+id, hc).stop(true).fadeTo(photos.speed, 1);
				$('#hp-'+id, hp).stop(true).fadeTo(photos.speed, 0);
				$('#ht-'+id, hp).stop(true).fadeTo(photos.speed, 0);
			} else {
				$('#hc-'+id, hc).stop(true).show();
				$('#hh-'+id, hc).stop(true).hide();
				$('#hr-'+id, hc).stop(true).show();
				$('#hp-'+id, hp).stop(true).hide();
				$('#ht-'+id, hp).stop(true).hide();
			}
		};
		$('a', hc).each(function() {
			var id = parseInt($(this).attr('id').substr(3));
			$(this).bind('mouseover', function() { showPhoto(id); });
		});
		$('div.hover', hc).bind('click', function() {
			var id = parseInt($(this).attr('id').substr(3));
			//$('#hc-'+id, hc).trigger('click');
			window.location.href = $('#hc-'+id, hc).attr('href');
		});
		hc.bind('mouseleave', function(e) {
			if ($(e.relatedTarget).parent().attr('id') != 'home-photos') {
				resetPhotos();
			}
		});
		hp.bind('mouseleave', function(e) {
			if ($(e.relatedTarget).parent().attr('id') != 'home-controls') {
				resetPhotos();
			}
		});
	}
});
