//*-----JQUERY FUNCTIONS-----*//

$(document).ready(function(){
	
	/*-----QTIP ACTIONS-----*/
	
	$('.btn_info').qtip({
		content: {
			text: function(api) {
				return $(this).siblings('.info_qtip').clone();	
			}
		},
		show: {
			event: 'click'
		},
		position: {
			my: 'middle right',
			at: 'middle left'	
		},
		style: {
			classes: 'ui-tooltip-dark'
		}
	});
	
	/*-----SCRATCH OFF ACTIONS-----*/
	
	var hostPath = window.location.pathname.split( '/' );
	var host = hostPath[0];
	
	var topImage = new Image();
	var bottomImage = new Image();
	var coinImage = new Image();
	bottomImage.src = host +'/damien/wp-content/themes/damien/im/empty.png';
	coinImage.src = host +'/damien/wp-content/themes/damien/im/circle.png';	
	
	function init()
	{
		var isMouseDown = false;
		var canvasWidth = $('#canvas').width();
		var canvasHeight = $('#canvas').height();
		var overlayctx = $('canvas')[1].getContext('2d');
		overlayctx.drawImage(coinImage, 0, 0);
	
		function scratchOff(x, y)
		{
			mainctx.save();
			mainctx.beginPath();
			mainctx.arc(x, y, radius, 0, Math.PI*2, false); // we don't fill or stroke the arc intentionally
			mainctx.clip();
			mainctx.drawImage(bottomImage, 0, 0);
			mainctx.restore();
		}
		
		$('#overlay').mousemove(function(e){
			var relX = e.pageX - $(this).offset().left;
			var relY = e.pageY - $(this).offset().top;
			overlayctx.clearRect(0, 0, canvasWidth, canvasHeight);
			overlayctx.drawImage(coinImage, relX-radius, relY-radius);
			scratchOff(relX, relY, false);
		});
	
		var mainctx = $('canvas')[0].getContext('2d');
		var radius = 15;
		topImage.onload = function(){
			mainctx.drawImage(topImage, 0, 0);
		};
		topImage.src = host +'/damien/wp-content/themes/damien/im/bar.png';
	}
	
	init();
	
	
	/*-----SHADOWBOX ACTIONS-----*/
	
	Shadowbox.init({
    	players: ['swf']
	});

});

