RClock = function() {
	var options = ({
		container: null
	}, arguments[0] || { });
	
	$.extend(this, options);
	
	this.container = $(this.container);
	this.noImgCounter = null;
	this.hourArrow = null;
	this.minuteArrow = null;
	
	this.setup();
};

RClock.prototype = {
	setup: function() {
		this.createDom();
		this.startRuntime();
	},
	
	createDom: function() {
		$('<div class="r-clock">'+
			'<div class="no-img-counter" id="r-no-img-counter">00:00</div>'+
			'<div class="back-fade"></div>'+
			'<div class="hour-arrow">'+
				'<div class="png" id="r-hour-arrow"></div>'+
			'</div>'+
			'<div class="arrow-fade"></div>'+
			'<div class="minute-arrow">'+
				'<div class="png" id="r-minute-arrow"></div>'+
			'</div>'+
			'<div class="clock-dial"></div>'+
		'</div>').appendTo(this.container);
		this.noImgCounter = $("#r-no-img-counter");
		this.hourArrow = $("#r-hour-arrow");
		this.minuteArrow = $("#r-minute-arrow");
	},
	
	startRuntime: function() {
		var parent = this;
		var date = null
		var timer = setInterval(function() {
			date = new Date();
			parent.drawDigitalClock(date.getHours(), date.getMinutes());
			parent.drawAnalogClock(date.getHours(), date.getMinutes());
		},1000);
	},
	
	drawDigitalClock: function(hours, minutes) {
		var hvalue = (hours < 10) ? "0"+hours : hours;
		var mvalue = (minutes < 10) ? "0"+minutes : minutes;
		this.noImgCounter.html(hvalue+":"+mvalue);
	},
	
	drawAnalogClock: function(hours, minutes) {
		var blockHeight = 58;
		
		hours = (hours < 13) ? hours : hours-12;
		this.hourArrow.css("margin-top", "-"+((hours*5+(5-Math.round((60-minutes)/15)-1))*blockHeight)+"px");
		this.minuteArrow.css("margin-top", "-"+(minutes*blockHeight)+"px");
	}
};
