// --------------------------------------------------------------------------------
//
//	Hangtag Animation v0.2
//	by plan p. GmbH - http://www.plan-p.de/
//	Last Modification: 29. Mai 2009 - for Cheezy Rider
//
// --------------------------------------------------------------------------------

//
//  Hangtag Class
//
var Hangtag = Class.create();

Hangtag.prototype = {

	hangtag_elem: undefined,
	animation_active: false,
	timer_cd: 0,
	
	//
    // initialize()
    // Constructor runs on completion of the DOM loading.
	//
    initialize: function() {

		hangtag_elem = $('hangtag');
		if(hangtag_elem)
		{
			// setup observer
			hangtag_elem.observe('mouseover', (function() { this.doAnimationJump(); }).bind(this));
		}
		
		animation_active = false;
		
		// start timer for shake
		timer_cd = 30;
		this.tickTimerForShake();
	},


	//
	//  tickTimerForShake()
	//  Animation for mouseover
	//
	tickTimerForShake: function(){
		timer_cd = timer_cd -1;
		if(timer_cd<=0)
		{
			this.doAnimationShake();
			timer_cd = 30;
		}
		
		var tmpc = function()
		{
			this.tickTimerForShake();
		}.bind(this).delay(1.00);			
	},

	
	//
	//  doAnimationShake()
	//  Animation for mouseover
	//
	doAnimationShake: function(){
		if(!animation_active)
		{
			animation_active = true;
			
			new Effect.Shake(hangtag_elem, { duration: 0.75, distance: 3 });
			
			var tmpx = function()
			{
				animation_active = false;
			}.delay(0.80);			
		}
	},


	//
	//  doAnimationJump()
	//  Animation for mouseover
	//
	doAnimationJump: function(){
		if(!animation_active)
		{
			animation_active = true;

			timer_cd = 30;	// reset the shake timer

			new Effect.Move(hangtag_elem, {
				y: +20,
				duration: 0.20
			});

			new Effect.Move(hangtag_elem, {
				y: -60, 
				duration: 0.30,
				queue: 'end'
			});

			new Effect.Move(hangtag_elem, {
				y: +40, 
				transition: Effect.Transitions.spring,
				duration: 1.00,
				queue: 'end'
			});
			
			var tmpx = function()
			{
				animation_active = false;
			}.delay(1.60);			
		}
	}

}
document.observe('dom:loaded', function () { var myHangtag = new Hangtag(); });