// JavaScript Document

// Lafite collection scripts to go here.

// Jquery countdown main scripts held in a separate file.

// function to get a date object from the ID of the object
function getDateFromID(myid) {
	// ID in format YYYYMMDDHH[mmss]
	year = parseInt(myid.substring(0,4));
	month = parseInt(myid.substring(4,6));
	day = parseInt(myid.substring(6,8));
	hour = parseInt(myid.substring(8,10));
	minute = parseInt(myid.substring(10,12));
	sec = parseInt(myid.substring(12,14));
	
	// Javascript date format: Date(year, month, day, hours, minutes, seconds, milliseconds)	
	mydate = new Date(year,month-1,day,hour,minute,sec);
	return mydate;
}

	
$(document).ready(function () {
    //pointers
    $(".expandable-header").hover(function () {
        $(this).css("cursor", "pointer");
    });
    $(".expand").hover(function () {
        $(this).css("cursor", "pointer");
    });

    //show and hide
    $(".expandable-header").toggle(function () {
        $(this).next().fadeIn("slow");
    }, function () {
        $(this).next().fadeOut("slow");
    });

    $(".expand").click(function () {
		$(this).fadeOut("slow");
        $(this).next().fadeIn("slow");
    });
	
	// Press area - jump to tasting notes for a vintage when selected from dropdown
	$('#vintageselect select').change(function() {
		window.location = window.location.pathname + $(this).val() + "/";
	});
	
	
	//var startOfBiddingWindow = new Date(2011,11-1,03,11,00,00);
	$(".timer").click(function () {
		var theid = $(this).attr("id");
		$(this).countdown({until:getDateFromID(theid),format:'dHMS'});
	});
	
	// Call timer functions
	$(".timer").trigger("click");	
	
	// Home page slideshow
	$('#fade').cycle({random:0, timeout: 5000, startingSlide:0 });
    $('#fade img').click(function () {
    	document.location.href = $(this).attr('rel');
    }).css('cursor', 'pointer');
	
	
});
