$(document).ready(function() {
	// lightbox background
	$("#background").css({"opacity" : "0.9"});
	
	// random photos
	var bigPhotos = ["big-photo-1", "big-photo-3", "big-photo-5"];
	var smallPhotos = ["small-photo-5", "small-photo-7", "small-photo-8", "small-photo-9"];
	var randomBigPhoto = Math.floor(Math.random() * bigPhotos.length);
	$("#left-image a").attr({"href" : "images/" + bigPhotos[randomBigPhoto] + ".jpg"});
	$("#left-image img").attr({"src" : "images/" + bigPhotos[randomBigPhoto] + "-th.jpg"});
	
	// randomize small photos array
	function randomOrder() {
		return (Math.round(Math.random())-0.5);
	}
	smallPhotos.sort(randomOrder);

	$("#right-images a").each(function(index) {
		$(this).attr({"href" : "images/" + smallPhotos[index] + ".jpg"});
	});
	$("#right-images img").each(function(index) {
		$(this).attr({"src" : "images/" + smallPhotos[index] + "-th.jpg"});
	});
	
	$("#left-image a, #right-images a").click(function() {
		// background
		$("#background")
			.width($(window).width())
			.height($(window).height())
			.fadeIn().css({
				"position" : "fixed",
				"top" : "0px"
			});
		
		// image
		var width = $(this).children("img").width();
		var height = $(this).children("img").height();
		var top = ($(window).height() / 2) - 240;
		var left = ($(document).width() / 2) - 320;	
		var position = $(this).children("img").offset();
		var href = $(this).attr("href");
		
		if (top < 0) {
			top = 50;
		}
		
		$("#image")
			.width(width)
			.height(height)
			.css({
				"background" : "white url(images/loader.gif) no-repeat center center",
				"top" : position.top - $(window).scrollTop(),
				"left" : position.left						
			})
			.fadeIn("fast")
			.animate({
				"width" : 640,
				"height" : 480,
				"top" : top,
				"left" : left,
				"padding" : "10px"},
				500,
				function() {
					var image = new Image();
					$(image).load(function() {
						$(this).hide();
						$("#image").html(this);
						$(this).fadeIn();
					}).attr("src", href);
				}
			);		

		// close
		$("#background, #image").click(function() {
			$("#background").fadeOut();
			$("#image").fadeOut(function() {
				$(this).css({"padding" : "0px"}).children("img").hide();
			});
		});
		return false;
	});
	
	// random quotes
	var quotes = [
		"\"Animals are such agreeable friends&mdash;they ask<br /> no questions, they pass no criticisms.\" &mdash;George Eliot",
		"\"In order to keep a true perspective of one's importance, everyone should have<br /> a dog that will worship him and a cat that will ignore him.\" &mdash;Dereke Bruce",
		"\"I wish I could write as mysterious as a cat.\" &mdash;Edgar Allan Poe",
		"\"Dogs come when they're called; cats take a message<br /> and get back to you later.\" &mdash;Mary Bly",
		"\"If dogs could talk, it would take a lot of the fun out of owning one.\"<br /> &mdash;Andy Rooney",
		"\"The most affectionate creature in the world is a wet dog.\" &mdash;Ambrose Bierce",
		"\"A good snapshot stops a moment from running away.\" &mdash;Eudora Welty",
		"\"I named my dog Stay so I can say,<br /> \'Come here, Stay.  Come here, Stay.\' &mdash;Steven Wright",
		"\"I think dogs are the most amazing creatures; they give unconditional love.<br /> For me they are the role model for being alive.\" &mdash;Gilda Radner"

	]
	var randomQuote = Math.floor(Math.random() * quotes.length);
	$("#quote").html(quotes[randomQuote]);
	
	
	// random backgrounds
	var backgrounds = ["background-1.jpg", "background-2.jpg", "background-3.jpg", "background-4.jpg", "background-5.jpg", "background-6.jpg", "background-7.jpg", "background-8.jpg"];
	var randomBackground = Math.floor(Math.random() * backgrounds.length);
	$("body").css({"background-image" : "url(images/" + backgrounds[randomBackground] + ")"});
	
	// defer google analytics http://phasetwo.org/post/defer-google-analytics-until-after-page-load.html
	var _googleInterval;
	function addGoogleTracking() {
		var sc = document.createElement('script');
		sc.type = 'text/javascript';
		sc.src = 'http://www.google-analytics.com/ga.js';
		document.getElementsByTagName("head").item(0).appendChild(sc);
		_googleInterval = setInterval(activateGoogle,250);
	}
	function activateGoogle() {
		if(typeof _gat != 'undefined') 
		{
			clearInterval(_googleInterval);
			var pageTracker = _gat._getTracker("UA-4116867-3");
			pageTracker._initData();
			pageTracker._trackPageview();
		}
	}
	addGoogleTracking();
});






















