/*
 * 
 * Sidebar
 * 
 */
var voting = false;
$(document).ready(function(){
	$("#btnSeeTheCalendar").hover(function() {
		$(this).css('cursor', 'pointer');
	});
	$("#btnSeeTheCalendar").click(function() {
		window.location = "calendar2012.php";
	});
	$("#btnSeeMore").hover(function() {
		$(this).css('cursor', 'pointer');
	});
	$("#btnSeeMore").click(function() {
		window.location = "insideTheBottle.php";
	});
	$("#btnViewNow").hover(function() {
		$(this).css('cursor', 'pointer');
	});
	$("#btnViewNow").click(function() {
		window.location = "calendar2012.php";
	});
	
	$('#callout1 .blackout1').fadeOut('fast');
	$("#callout1").hover(function() {
		$('#callout1 .blackout1').fadeOut('slow');
   		$('#callout2 .blackout2').fadeIn('slow');
   		$('#callout3 .blackout3').fadeIn('slow');
   		$('#largeBgImage').fadeIn('slow');
   		$('#largeBgImage2').fadeOut('slow');
   		$('#largeBgImage3').fadeOut('slow');	   		
	});
   	$("#callout2").hover(function() {
   		$('#callout1 .blackout1').fadeIn('slow');
		$('#callout2 .blackout2').fadeOut('slow');
		$('#callout3 .blackout3').fadeIn('slow');
   		$('#largeBgImage').fadeOut('slow');
   		$('#largeBgImage2').fadeIn('slow');
   		$('#largeBgImage3').fadeOut('slow');			
	});
   	$("#callout3").hover(function() {
   		$('#callout1 .blackout1').fadeIn('slow');
   		$('#callout2 .blackout2').fadeIn('slow');
		$('#callout3 .blackout3').fadeOut('slow');
   		$('#largeBgImage').fadeOut('slow');
   		$('#largeBgImage2').fadeOut('slow');
   		$('#largeBgImage3').fadeIn('slow');
	});
	$('#largeBgImage').show();
   	$('#largeBgImage2').hide();
   	$('#largeBgImage3').hide();
   	
   	$("#sidebarPollButton1").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(1); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton2").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(2); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton3").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(3); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton4").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(4); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton5").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(5); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton6").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(6); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton7").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(7); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton8").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(8); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton9").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(9); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton10").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(10); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton11").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(11); }, function() {setHoverPollModel(0); });
   	$("#sidebarPollButton12").hover(function() { $(this).css('cursor', 'pointer'); setHoverPollModel(12); }, function() {setHoverPollModel(0); });
   	
   	$("#sidebarPollButton1").click(function() { voteModel(1); });
   	$("#sidebarPollButton2").click(function() { voteModel(2); });
   	$("#sidebarPollButton3").click(function() { voteModel(3); });
   	$("#sidebarPollButton4").click(function() { voteModel(4); });
   	$("#sidebarPollButton5").click(function() { voteModel(5); });
   	$("#sidebarPollButton6").click(function() { voteModel(6); });
   	$("#sidebarPollButton7").click(function() { voteModel(7); });
   	$("#sidebarPollButton8").click(function() { voteModel(8); });
   	$("#sidebarPollButton9").click(function() { voteModel(9); });
   	$("#sidebarPollButton10").click(function() { voteModel(10); });
   	$("#sidebarPollButton11").click(function() { voteModel(11); });
   	$("#sidebarPollButton12").click(function() { voteModel(12); });
   	
	 prefetchHomeImages();
});

function setHoverPollModel(index) {
	if(index==0) {
		//$("#sidebarPollSelected").hide()
	} else {
		if(!voting) {
			$("#sidebarPollSelected").css("background","url(./images/sidebar/"+index+".png) no-repeat");
			$("#sidebarPollSelected").fadeIn("fast");
		}
	}
}
function voteModel(answerIndex) {
	// Send results to server
	voting = true;
	$.post('data/pollHandler.php', {requestType:2, pollId:4, answerId:answerIndex}, function(data) {
		// Then show thank you
		$("#sidebarPollSelected").fadeOut("slow");
		$("#sidebarPoll").fadeOut("slow");
		$("#sidebarPollThankYou").fadeIn("slow");
	},"json");
}

function prefetchHomeImages() {
	for (i=1;i<=12;i++) {
		var image = new Image();	image.src = './images/sidebar/'+i+'.png';
	}
	var image = new Image();	image.src = './images/bkgrdHomeCoverGirl.jpg';
	var image = new Image();	image.src = './images/bkgrdHomeInsideTheBottle.jpg';
	var image = new Image();	image.src = './images/bkgrdHomeCalendar.jpg';
}
