///////////////////////////////////////////////////////////////////////////////
//
//  clock.js
//
// 
// © 2007 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 1.0 SDK, for details look 
// here: http://go.microsoft.com/fwlink/?LinkID=89144&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////

function Clock() { }

Clock.prototype.handleLoad = function(control, userContext, rootElement) {
    var now = new Date();

    var hourAnimation = control.content.findName("hourAnimation");
    var minuteAnimation = control.content.findName("minuteAnimation");
    var secondAnimation = control.content.findName("secondAnimation");

    if (hourAnimation) {
        var hours = now.getHours();

        // We need to include minutes as well. Because each hour consists of 
        // 30 degrees, each additional minute adds half a degree to the angle
        // of the hour hand

        var angle = (hours / 12) * 360 + now.getMinutes()/2;
        angle += 180;

        hourAnimation.from = angle.toString();
        hourAnimation.to = (angle + 360).toString();
    }

    if (minuteAnimation) {
        var minutes = now.getMinutes();
        var angle = (minutes / 60) * 360;
        angle += 180;

        minuteAnimation.from = angle.toString();
        minuteAnimation.to = (angle + 360).toString();
    }

    if (secondAnimation) {
        var seconds = now.getSeconds();
        var angle = (seconds / 60) * 360;
        angle += 180;

        secondAnimation.from = angle.toString();
        secondAnimation.to = (angle + 360).toString();
    }
}

