/**
 * AUDI JavaScript library: animation.emointro
 * 
 * @projectDescription	Animation class handling the emointro / flash-overlay
 * @namespace			animation.emointro
 *
 * @author 				$Author: mkrause $
 * @version				$Revision: 3564 $
 * @copyright			NEUE DIGITALE GmbH, Berlin
 * 
 * @jslint: 2008-10-31
 * 
 * @file:				audi_ngw.animation.emointro.js
 * $URL: https://svn.pvtool.org/svn/day_audi_ngw/trunk/ngw_base/frontend/js/audi/audi.animation.emointro.js $
 */

/* create namespace */
audi_ngw.namespace(audi_ngw,'animation.emointro');

/**
 * Set up animation
 * @return {Void}
 */
audi_ngw.animation.emointro._setUp= function(){
	var scope = audi_ngw.animation.emointro;
	
	// cache the elements neccessary
	scope._$element = jQuery(scope._options.sIdWrapper);
	scope._$elHitbox = scope._$element.find('#audi_container_emo_button');
	scope._$elNavi = scope._$element.find('#audi_container_emo_slider');
	
	// setting the events
	scope._$elHitbox.mouseover(audi_ngw.animation.emointro.animate);
	scope._$elNavi.hover(function(){}, audi_ngw.animation.emointro.animate);
};
/**
 * Adds events 
 * @return {Void}
 * @deprecated
 */
//audi_ngw.animation.emointro._addEvents = function(){
//	// store reference
//	var _self = this;
//	// construct selector
//	var _sSelector = this._options.sIdWrapper;
//	_sSelector += ' ul li ';
//	
//	// add click event to first level navigation anchors
// 	jQuery(_sSelector).parent('ul.first').children().children('a').click(function(event){
//		_self.animate(event,_self, 1);
//	});
//
//	// add click event to second level navigation anchors
// 	jQuery(_sSelector).parent('ul.second').children().children('a').click(function(event){
//		_self.animate(event,_self, 2);
//	});
//
//	// add click event to third level navigation anchors
// 	jQuery(_sSelector).parent('ul.third').children().children('a').click(function(event){
//		_self.animate(event,_self, 3);
//	});
//};

/**
 * Animates emointro. Decides direction by looking at the marker classes set on hitbox
 * Brigde: _doShow || _doHide
 * @param {Event} 
 * @return {Void}
 */
audi_ngw.animation.emointro.animate = function(event){

	// cache scope
	var scope = audi_ngw.animation.emointro;
	
	// exit on running animation
	if ( audi_ngw.animation.getRunning(scope.__className) ) { 
		return false; 
	}
	
	// register animation
	audi_ngw.animation.setRunning(scope.__className);
	
	// check marker class
	if( scope._$elHitbox.hasClass(scope._options.sClassVisible) ) {
	
		// status open: hide 
		audi_ngw.animation.emointro._doHide(scope._$element);
		
	} else {
	
		// status closed : show
		audi_ngw.animation.emointro._doShow(scope._$element);
		
	}
	
	return false;
};

/**
 * Shows pagelevel by animating margin left to zero
 * @param {jQuery-Element} Element to animate  
 * @return {Void}
 */
audi_ngw.animation.emointro._doShow = function($element){
	
	// freeze flash
	audi_ngw.flash.pauseAll();
	
	// run animation
	$element.animate({
		'marginLeft': 0+'px'
	}, audi_ngw.animation.emointro.onCompleteShow);

};

 /**
 * onComplete callback for "show"
 * @return {Void}
 */
audi_ngw.animation.emointro.onCompleteShow = function(){
	
	// cache scope
	var scope = audi_ngw.animation.emointro;
	
	// set marker classes on hitbox 
	scope._$elHitbox.removeClass(scope._options.sClassHidden);
	scope._$elHitbox.addClass(scope._options.sClassVisible);
	
	// call default callback
	audi_ngw.animation.emointro._onCompleteDefault(scope);
};


/**
 * Hides pagelevel by animating margin left to defined width * -1 , normally the width 
 * of the pagelevel plus some padding.
 * @return {Void}
 */
audi_ngw.animation.emointro._doHide = function($element){

	// unfreeze flash
	audi_ngw.flash.resumeAll();

	// cache scope
	var scope = audi_ngw.animation.emointro;

	// cache width
	var _iWidth = scope._options.iWidth;

	// run animation
	$element.animate({
		'marginLeft': (-1*_iWidth)+'px'
	}, audi_ngw.animation.emointro.onCompleteHide);
};

/**
 * onMovieComplete callback. Should be called when the emointro has been 
 * completed or is manually skipped.
 * - Slides in hidden pagelevel (forced), skipping running animation flag
 * - clesrs bitbox by removing events, fading and finally deleting the element 
 * @return {Void}
 */
audi_ngw.animation.emointro.onMovieComplete = function(){

	// cache scope
	var scope = audi_ngw.animation.emointro;

	// show hidden pagelevel navigation
	audi_ngw.animation.emointro._doShow(scope._$element);

	// unbind the hover-event from the pagelevel
	scope._$elNavi.unbind('mouseout');
	scope._$elNavi.unbind('mouseenter');
	scope._$elNavi.unbind('mouseleave');
	
	// show rhe region selector
	audi_ngw.region.show();
	
	// handle hitbox
	scope._$elHitbox
		.unbind('*')
		.fadeOut(
			function () {
				audi_ngw.animation.emointro._$elHitbox.remove();
			}
		);
};

 

 /**
 * onComplete callback for "hide"
 * @return {Void}
 */
audi_ngw.animation.emointro.onCompleteHide = function(){
	// cache scope
	var scope = audi_ngw.animation.emointro;
	// set marker classes on hitbox
	scope._$elHitbox.removeClass(scope._options.sClassVisible);
	scope._$elHitbox.addClass(scope._options.sClassHidden);
	// call default callback
	audi_ngw.animation.emointro._onCompleteDefault(scope);
};


/**
 * On complete callback: slide up / down 
 * @method _onComplete
 * @param {Scope} scope
 * @private
 * @return {Void}
 */
audi_ngw.animation.emointro._onCompleteDefault = function(scope){

	// delay reset to enhance user experience
	scope.timer = window.setTimeout(function () {

		// unset running scope
		audi_ngw.animation.unsetRunning(scope.__className);

		// resume flash after everything is done
		//audi_ngw.flash.resumeAll();

		// remove timer
		audi_ngw.animation.emointro.timer = audi_ngw.clearTimer(audi_ngw.animation.emointro.timer);
	},250);
};
 
 

 
/**
 *Initialize animation "emointro"
 * @method initialize
 * @constructor
 * @param {Object} Options 
 * @return {Void}
 */
audi_ngw.animation.emointro.initialize = function(options){
	options = options || {};
	this.__className =  'audi_ngw.animation.emointro';
	this.__classVersion= '1.1';
	
	this._options = {};
	this._options.sIdWrapper = options.sIdWrapper || '#audi_container_emo';
	this._options.iWidth = 267;
	this._options.sClassVisible = 'audi_container_emo_button_out';
	this._options.sClassHidden = 'audi_container_emo_button_in';
	
	
	
	this._setUp();

	this.timer = window.setTimeout(function(){
		audi_ngw.animation.emointro._doHide(audi_ngw.animation.emointro._$element);
		// remove timer
		audi_ngw.animation.emointro.timer = audi_ngw.clearTimer(audi_ngw.animation.emointro.timer);
	},1000);

//	this.TEST();
};

 


 

	
