var tux = document.getElementById('tux');
var menu = document.getElementById('menu');
var photo = document.getElementById('option1');
var rub = document.getElementById('option2');
var feed = document.getElementById('option3');
var photoCount = 0;
var rubCount = 0;
var feedCount = 0;
var totalCount = 0;
var visible = function(e){
menu.style.display = 'block';
menu.style.left = e.pageX + "px";
menu.style.top = e.pageY + "px";
e.preventDefault();
}
var hide = function(){
menu.style.display = 'none';
}
var tired = function(){
alert("Tux is tired of you now. Please leave him alone.");
}
var photoFunc = function(){
if(totalCount > 5){
tired();
} else if (photoCount < 1){
alert("Tux is smiling for the camera!");
} else {
alert("Tux does not want to take more photographs right now...");
}
photoCount++;
totalCount++;
}
var rubFunc = function(){
if(totalCount > 5){
tired();
} else if (rubCount == 1){
alert("Tux is already satisfied with his belly rubs!");
} else if (rubCount > 1){
alert("Tux wants you to stop now please...");
} else {
alert("Tux loves a good belly rub!");
}
rubCount++;
totalCount++;
}
var feedFunc = function(){
if(totalCount > 5){
tired();
} else if (feedCount == 1){
alert("Tux is already full.");
} else if (feedCount > 1){
alert("Tux wants you to stop now please...");
} else {
alert("Tux enjoyed his fish! Thank you!");
}
feedCount++;
totalCount++;
}
tux.addEventListener('contextmenu', visible, false);
document.addEventListener('click', hide, false);
photo.addEventListener('click', photoFunc, false);
rub.addEventListener('click', rubFunc, false);
feed.addEventListener('click', feedFunc, false);