// JavaScript Document

// Countdown
$(document).ready(function(){
  $("#countdown-box").MMCountdown();
});

(function($) {

  function writeNumber( countdownFrame, num, items )
  {
    $("#" + countdownFrame +" span").remove();
    var str, html = "";
    for( i=1; i<=items; i++ )
    {
      digit = num % 10;
      str= "<span class='countdown-digit' style='background: transparent url(" + webroot + "css/pic/countdown.gif) -" + ( 10 + digit*20 ) + "px -20px no-repeat;";
      //if( ( i==items ) && ( items<3 ) ) str += "margin: 0 0 0 10px;";
      str += "' ></span>";
      
      html = str+html;
      num = parseInt( ( num-digit ) / 10 );
    }
    
    $("#" + countdownFrame ).prepend( html ); 
    return;
  }
  
  function wtextcountdown()
  {
    var day = new Date( 2012,8,8,16,0,0);
    var today  = new Date();
    var todayEpoch  = today.getTime();

    var targetEpoch = day.getTime();
    
    var seconds = Math.floor((targetEpoch - todayEpoch) / 1000);

    var msg = "";
    
      var days  = Math.floor( seconds / ( 60*60*24 ) );  seconds -= days*( 60*60*24 );
      var hours = Math.floor( seconds / ( 60*60 ) );     seconds -= hours*( 60*60 );
      var mins  = Math.floor( seconds / ( 60 ) );        seconds -= mins*( 60 );
    
    writeNumber( "countdown-frame-ss", seconds,2  );
    writeNumber( "countdown-frame-mm", mins,2 );
    writeNumber( "countdown-frame-h", hours,2 );
    writeNumber( "countdown-frame-g", days, 3 );


    setTimeout( wtextcountdown,500);
    
  }
  
  $.fn.MMCountdown = function ()
  {
     $(this).append("<div id=\"countdown-frame-g\" class=\"countdown-frame\" ><h1></h1></div>")
    .append("<div id=\"countdown-frame-h\" class=\"countdown-frame\" ><h1></h1></div>")
    .append("<div id=\"countdown-frame-mm\" class=\"countdown-frame\" ><h1></h1></div>")
    .append("<div id=\"countdown-frame-ss\" class=\"countdown-frame\" ><h1></h1></div>")
    .append("<div style='clear:both;' /></div>");
    setTimeout( wtextcountdown,500);
  }
})(jQuery);

//************************************************************************
function hideElementByID( elID)
{
	var e= document.getElementById(elID);
	e.style.display = "none";
}
//************************************************************************
function getH(){
var h;
if(document.innerHeight){ h=document.innerHeight;
} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
} else if(document.body){ h=document.body.clientHeight; }
return h;
}
//************************************************************************
function getW(){
var w;
if(document.innerWidth){ w=document.innerWidth;
} else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
} else if(document.body){ w=document.body.clientWidth; }
return w;
}
//************************************************************************
function subImgShow( elementname, imgelement, e )
{
	var obj= document.getElementById(elementname);
	obj.style.display = 'block' ;
	obj.style.visibility = 'visible';	
	
	obj.innerHTML = imgelement;
/*	obj.style.position = "absolute";

	var tempX = 0;
	var tempY = 0;
	var mX = 0;
	var mY = 0;
	var offset = 5;
	
	// step 3
	if (document.all) {
	mX = event.clientX;
	mY = event.clientY;
	
	tempX = mX + document.body.scrollLeft;
	tempY = mY + document.body.scrollTop;
	} else {
	mX = e.clientX;
	mY = e.clientY;
          
	tempX = e.pageX;
	tempY = e.pageY;
	}       
	
	
	var hH = getH() / 2;	
	if( (mY > 0 ) && ( mY > hH ) ) tempY -= (150 + 12);  // vale solo x le immagini alte 150px
	var hW = getW() / 2;	
	if( (mX > 0 ) && ( mX > hW ) ) tempX -= (150 + 12);  // vale solo x le immagini larghe 150px
	
	// step 4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}

	// step 5
	obj.style.top  = (tempY + offset) + 'px';
	obj.style.left = (tempX + offset) + 'px';*/

}
//************************************************************************
function trakImgShow( point, e )
{
	html = "<img alt=\"foto percorso\" src=\"img/percorso/" + point + ".jpg\" />";
	subImgShow( 'trakImg', html, e )
}
//************************************************************************
function subImgHide( elementname )
{
	var e= document.getElementById( elementname );
	if ( e )
	{
		e.style.display = "none";
		e.innerHTML = "";
	}
}
//************************************************************************
function trakImgHide()
{
//	subImgHide('trakImg');
}
//************************************************************************

