$(document).ready(function() {
	$("#menu").dropmenu();
	$("#menu ul li").mouseover(function () {
		var hoverclass = $(this).children("a");
		if (hoverclass.is('.menu_category')) {
			$(this).addClass("selected-left");
			$(this).children("a").addClass("selected-right");
		}
	});
	$("#menu ul li").mouseout(function () {
		$(this).removeClass("selected-left");
		$(this).children("a").removeClass("selected-right");
	});
	
	$('#splash-photos div').before('<div id="nav" class="nav">').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 3000, 
        pager:  '#nav',
        before: function() { if (window.console) console.log(this.src); }
    });
	
	$('#splash-photos div img').click(function() {
		window.open('gallery.html');
	});
	$('#splash-photos').hover(
        function() { 
			$('#text-overlay').css('opacity',0).show().animate({opacity: 0.85}); 
		},
        function() { 
			$('#text-overlay').animate({opacity: 0}); 
		}
    );
	
	var numofPhotos = $("#splash-photos div img").length;
	if (numofPhotos==1) {
		$("#nav").hide();
	}
	$("a[rel^='lightbox']").fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'inside'
	});
	$("#calc").fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'inside',
		'autoDimensions' : false,
		'type'			: 'iframe',
		'width'			: 300,
		'height'		: 550
	});
	$(".related").hover(function () { 
		$(this).removeClass("related");
		$(this).addClass("related-hover").fadeIn("slow");
	},function() {
		$(this).addClass("related").fadeIn("slow");
		$(this).removeClass("related-hover");
	});
	
	function parseDate(str) {
		var mdy = str.split('/')
		return new Date(mdy[2], mdy[0]-1, mdy[1]);
	}
	
	function daydiff(first, second) {
		return (second-first)/(1000*60*60*24)
	}
	
	var fullDate = new Date()
	var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);
	var currentDate = twoDigitMonth + "/" + fullDate.getDate() + "/" + fullDate.getFullYear();


	var count = 350000;
	var count_start = "10/17/2011";
	var count_day = 136.986301;
	var count_hour = 5.70776254;
	var count_min = 0.0951293757;
	var count_sec = 0.00158443823;
	
	// difference in date
	var date_diff = daydiff(parseDate(count_start), parseDate(currentDate));
	
	var str = Math.round(count + (date_diff * count_day));
	str = str + "";
	
	var max = 9;
	var start = max - str.length;
	var sel = 1 + start;
	
	for (var i = 0, len = str.length; i < len; i++) {
		$('#roll'+sel).spinCounter({spinTime: 3200, stopDigit: parseFloat(str[i])});
		sel++;
	}


	
});
