if (YAHOO) {
	var gotyoucovered = YAHOO.namespace('com.digitas.amex.wegotyoucovered');

	//total number of blinds
	gotyoucovered.totalBlinds = 4;
	gotyoucovered.animations = new Array();

	gotyoucovered.onStartCallback = function() {
		var drawer = this.getEl();

		YAHOO.log('onStart fired','debug','com.digitas.amex.wegotyoucovered.onStartCallback');

		if (drawer) {
			for (var i=0;i<gotyoucovered.totalBlinds;i++) {
				var tmpDrawer = 'drawer_'+i;

				if (drawer.id != tmpDrawer) {
					gotyoucovered.animate(tmpDrawer,'close');
				}
			}
		}
	}

	gotyoucovered.onCompleteCallback = function() {
		var action = 'close';
		var drawer = this.getEl();

		YAHOO.log('onComplete fired','debug','com.digitas.amex.wegotyoucovered.onCompleteCallback');

		if (drawer) {
			if (parseInt(drawer.style.height) > 0)
				action = 'open';

			switch (action) {
				case 'open':
					YAHOO.util.Dom.replaceClass(drawer.id+'_open','inline', 'hide');
					YAHOO.util.Dom.replaceClass(drawer.id+'_close','hide', 'inline');
					break;
				case 'close':
					YAHOO.util.Dom.replaceClass(drawer.id+'_open','hide', 'inline');
					YAHOO.util.Dom.replaceClass(drawer.id+'_close','inline', 'hide');
					break;
			}
		}
	}

	gotyoucovered.animate = function(id,action) {
		YAHOO.log('Animating drawer ' + id + ' ' + action,'debug','com.digitas.amex.wegotyoucovered.animate');

		action = action.toLowerCase();

		var hgt = 221;
		if (action == 'close')
			hgt = 0;

		var drawer = document.getElementById(id);
		if (drawer && drawer.style) {
			var currentDrawerHeight = parseInt(drawer.style.height);

			if (currentDrawerHeight != hgt) {
				if (gotyoucovered.animations[id+action]) {
					animation = gotyoucovered.animations[id+action];
				} else {
					animation = new YAHOO.util.Anim(id, {
						height: { to: hgt }
		    			}, 1, YAHOO.util.Easing.easeOut);

					if (action == 'open')
						animation.onStart.subscribe(gotyoucovered.onStartCallback);

					animation.onComplete.subscribe(gotyoucovered.onCompleteCallback);

					gotyoucovered.animations[id+action] = animation;
				}

				YAHOO.log('Animating ' + id + ' to a height of ' + hgt,'debug','com.digitas.amex.wegotyoucovered.animate');

				//run animation
				animation.animate();
			}
		}
	}

	gotyoucovered.startTransition = function(e) {
		YAHOO.util.Event.preventDefault(e);

		var results = /drawer_([0-9])+_(open|close)$/.exec(this.id);

		if (results && results.length > 0) {
			var idx = Number(results[1]);
			var action = results[2].toLowerCase();

			switch (action) {
				case 'close':
					gotyoucovered.animate('drawer_'+idx,'close');
					break;

				case 'open':
					gotyoucovered.animate('drawer_'+idx,'open');
					break;
			}
		}
	}

	gotyoucovered.Initialize = function() {
    	initializeWidget(); //in horiz_widget_scroll.js

    	initPageText(1);
		switchWidgetCompany(1);
		setUpBackNextBTNS(1, "left");
		timedCount();

		var transitionActions = YAHOO.util.Dom.getElementsByClassName('transitionAction');
		for (var i=0;i<transitionActions.length;i++) {
			YAHOO.util.Event.addListener(transitionActions[i],'click',gotyoucovered.startTransition,transitionActions[i],true);
		}

		gotyoucovered.animate('drawer_1','open');
	}

	YAHOO.util.Event.onDOMReady(gotyoucovered.Initialize);
}