jQuery.fn.rotate = function(degrees) {
var d = degrees;
var rmat = {'-webkit-transform' : 'rotate('+ d +'deg)','-moz-transform' : 'rotate('+ d +'deg)','-ms-transform' : 'rotate('+ d +'deg)','transform' : 'rotate('+ d +'deg)'};
//alert(cssstring);
$(this).css(rmat);
};
function setanaloguehands(currenttime){
var minrotation = ((currenttime % 60) * 6) - 90;
var hourrotation = ((currenttime % 720) / 2) - 90;
$("#minutehand").rotate(minrotation);
$("#hourhand").rotate(hourrotation);
}
function padoutnumber(num, size) {
var s = num.toString();
while (s.length < size) s = "0" + s;
return s;
}
function getdigitaltime(currenttime){
var minute = currenttime % 60;
var hour = Math.floor((currenttime % 1440)/60);
hour = (hour % 12);
return(padoutnumber(hour,2) + ":" + padoutnumber(minute,2));
}
function getrandomtime(currenttime){
var randomtime;
do {
randomtime=Math.floor(Math.random()*1440);
alert("random = " + randomtime);
}
while (randomtime == currenttime);
return randomtime;
}
function init(){
var size = 450;
//ADD AJAX CALL to get the random time and the array of times
$.ajax({
type: "POST", /*method type*/
url: "/php/e-clock/match-time-to-numbers-get-array.php",
data: { "size": size },
dataType: 'json',
success: function(data)
{
$("#eclock").html(data[2]);
$("#resultpanel").hide();
var scale = 450/600;
style0=data[3][0];
//alert(style1);
$( '#hourhand' ).attr("style", data[3][0]);
$( '#hourimage' ).attr("style", data[3][1]);
$( '#minutehand' ).attr("style", data[3][2]);
$( '#minuteimage' ).attr("style", data[3][3]);
$( '#mainclock' ).attr("style", data[3][4]);
$( '#mainclock' ).css( "background-image", "url(/images/M001bg.png)" );
$( '#hourimage' ).css( "background-image", "url(/images/HourHand.png)" );
$( '#minuteimage' ).css( "background-image", "url(/images/MinHand.png)" );
$( '.digitalTimeBlock' ).css( "height", "50px" );
currenttime = data[0];
setanaloguehands(currenttime);
$(".digitalTimeBlock").attr("style","background-color:#fff; height:40px; width:120px; text-align:center;color:black; line-height:35px;margin:5px;font-size:30px;");
for ( var i = 0; i < 6; i++ ) {
$("#digitalblock").children(".digitalTimeBlock").eq(i).text(data[1][i]);
}
$("#resetbutton").click(function(){
init();
});
$(".digitalTimeBlock").click(function() {
theanswer = ($(this).html());
$.ajax({
type: "POST", /*method type*/
url: "/php/e-clock/match-time-to-numbers-check-result.php",
data: { "question": currenttime, "answer": $(this).html()},
dataType: 'json',
success: function(data)
{
$('#result').html(data[2]);
$('#resultpanel').css("background-color",data[1]);
$('#resetbutton').html(data[3]);
$('#resultpanel').show();
if (data[0]){
$('#resetbutton').show();
} else {
$('#resetbutton').hide();
}
},
error: function(xhr, textStatus, errorThrown)
{
alert('request failed: ' + errorThrown + " text status: " +textStatus);
}
});
});
},
error: function(xhr, textStatus, errorThrown){
// alert('request failed: ' + errorThrown + " text status: " +textStatus);
}
});
}
init();