// Title: lifeinmono.net - javascript
// Author: Kalon Edser, http://www.kalonedser.com/
// Updated: 27 September 2009

jQuery(document).ready(function() {
	
	$('body').addClass('js');
	$('.png').ifixpng(); 
	$.preloadImages('http://www.lifeinmono.net/img/prettyPhoto/light_rounded/sprite.png');
	
	var addressHash = window.location.hash;
	
	$.fn.imageLoader = function() {
		return this.each(function() {
			var $thisImage = $(this).hide();
			var $loadIcon = $('<div>')
				.addClass('load-icon')
				.width($thisImage.width()).height($thisImage.height())
				.html('<img src="../img/prettyPhoto/light_square/loader.gif" />')
				.insertBefore($thisImage);

			if ($thisImage.hasClass('master')) { $('#imagenav').hide(); }

			function showImage() {
				$loadIcon.hide();
				$thisImage.fadeIn(1000);
				if ($thisImage.hasClass('master')) { $('#imagenav').fadeIn(1500); }
			}

			$thisImage.each(function() {
				if ($thisImage[0].complete) {
					showImage();
				} else {
					$thisImage.bind('load', showImage);
				}
			});
		});
	}
	
	$('img:not(.gravatar)').imageLoader();

	// more info tooltip
	// $('.dev a#toggle').easyTooltip({
	// 	xOffset: -160,
	// 	yOffset: -10,
	// 	useElement: '#information .body'
	// });
	
	// main nav hover
	$('#nav a, .backtotop a').hover(
	      function() {
	        $(this).css('background-position','0 0').animate({ opacity: 0 }, 'fast' );
	      }, 
	      function() {
	        $(this).animate({ opacity: 1 }, 'fast' );
	      }
	);

	function prevNext() {
		$('a.tooltip').hover(
			function() {
				if ($(this).hasClass('next')) { var $direction = 'right';} else { var $direction = 'left'; }
				$('.tip',this).stop(false,true).hide().show('drop', { direction: $direction, easing:'easeOutBack' }, 'slow');
			}, 
			function() {
				if ($(this).hasClass('next')) { var $direction = 'right';} else { var $direction = 'left'; }
				$('.tip',this).stop(false,true).show().hide('drop', { direction: $direction, easing:'easeInBack' }, 'normal');
			}
		);
	}
	// tooltips for browsers with opacity support
	if ($.support.opacity) {
		prevNext();
	}

	// window scroll effect for anchor links
	$.localScroll({ margin:true, easing:'easeInOutExpo' });
	$.localScroll.hash({ margin:true, easing:'easeInOutExpo' });

	// toggle display of information
	if ($('#information') && !addressHash) {
		$('#information').hide();
		$('#toggle').click(function () {
			$('#information').animate({ opacity: 1.0 }, 800).toggle('blind', { direction: 'vertical', easing:'easeInOutExpo' }, 1000);
		});
	}

	// toggle display of project thumbs
	if ($('#project-thumbs') && (addressHash != '#project-thumbs')) {
		$('#project-thumbs').hide();
		$('#toggle2').click(function () {
			$('#project-thumbs').animate({ opacity: 1.0 }, 800).toggle('blind', { direction: 'vertical', easing:'easeInOutExpo' }, 500);
		});
	}
	
	// picture box controls
	$("a[rel^='picturebox']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 1, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: false /* If set to true, only the close button will close the window */
	});

	// open new window for external links
	$('.flickr .recent-images a').attr({rel: "external"});
	
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

});