var infoHidden = true;

$(document).ready(function() {

 $('#slickbox').hide();
 

  $('#infolink').click(function() {
    $('#slickbox').slideToggle(400);
   // return false;
   if (infoHidden == true) {
   infoHidden = false;
    //drawShape(344,400);
   } else if (infoHidden == false) {
   //drawShape(0,0);
infoHidden = true;
    }
    
  });
});
var xSpeed = 1;
var ySpeed = 1;
$(window).load(function(){
       resizeArea();
       setTimeout(function(){
               moveBouncer();
               $('#bouncer').show();
       }, 30);
       getCount();
});
$(window).resize(resizeArea);
function moveBouncer(){
var height = $('#bouncer').height();
var width = $('#bouncer').width();
var x = $('#bouncer').css('left');
x = parseFloat(x.substr(0, x.length-2));
var y = $('#bouncer').css('top');
y = parseFloat(y.substr(0, y.length-2));

var testX = x + xSpeed;
var testY = y + ySpeed;
if (testX > $(window).width() - width){
$('#bouncer').css('left', $(window).width() - width);
xSpeed = -xSpeed
}
if (testX < 0){
$('#bouncer').css('left', 0);
xSpeed = -xSpeed
}
if (testY > $(window).height() - height){
$('#bouncer').css('top', $(window).height() - height);
ySpeed = -ySpeed
} 
if (testY < 0){
$('#bouncer').css('top', 0);
ySpeed = -ySpeed
}
var newX = x + xSpeed;
var newY = y + ySpeed;
$('#bouncer').css({
'top':newY + 'px',
'left':newX + 'px'
});
/*if (infoHidden == true) {
        drawShape(newX,newY);
              } else {}*/
setTimeout(moveBouncer, 30);
}
// Arrow
function drawShape(newPointx,newPointy) {
  var canvas = document.getElementById('arrow');
  if (canvas.getContext){
    var ctx = canvas.getContext('2d');
    ctx.clearRect(0,0,500,500);


    // Filled triangle
    ctx.beginPath();
    ctx.moveTo(newPointx+20,newPointy-4);
    ctx.lineTo(0,50);
    ctx.lineTo(368,50);
     ctx.fillStyle = "rgba(255,0,0,.7)";
    ctx.fill();

  } else {
  }
}
function resizeArea(){
$('area').remove()
coords = getCoords();
newArea = document.createElement('area');
$(newArea).attr({
coords: coords,
href : href
});
$('map').append(newArea);
}
function getCoords(){
var xO = 2000;
var yO = 1250;
var x1 = 975;
var x2 = 1375;
var y1 = 440;
var y2 = 840;
var xN = $(window).width();
var yN = $(window).height();
x1 = Math.floor(x1 * xN / xO);
x2 = Math.floor(x2 * xN / xO);
y1 = Math.floor(y1 * yN / yO);
y2 = Math.floor(y2 * yN / yO);
return ([x1, y1, x2, y2].join(','));
}
function getCount(){
var dateFuture = new Date(2010,3,18,22,00,0);
   var dateNow = new Date();                                    //grab current date
   var amount = dateFuture.getTime() - dateNow.getTime();        //calc milliseconds between dates
   delete dateNow;

   // time is already past
   if(amount < 0){
       $('#timer').html('File #1: Sold Out!');
   }
   // date is still good
   else{
       days=0;hours=0;mins=0;secs=0;out="";
       amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
       var days=Math.floor(amount/86400);//days
       amount=amount%86400;
       var hours=Math.floor(amount/3600);//hours
       amount=amount%3600;
       var mins=Math.floor(amount/60);//minutes
       amount=amount%60;
       secs=Math.floor(amount);//seconds
       if(days != 0){out += days + ":";}
       if(days != 0 || hours != 0){out += hours +":";}
       if(days != 0 || hours != 0 || mins != 0){out += mins +":";}
       out += secs;
       $('#timer').html(out);
       setTimeout(getCount, 1000);
   }
}