var iIntroSpeed	= 0.3; 
/**
 *	Runs through the profile system step by step..
 */
var bGoNext 	= false;




function __ist_toggleTools(){
	if ( $('body-wrap').hasClassName('fullscreen-clothes') ) {
		$('body-wrap').removeClassName('fullscreen-clothes');
	} else {
		$('body-wrap').addClassName('fullscreen-clothes');
	}
}














/**
 *	This needs to be a real method cos the SAF calls it too...
 */
function __istHookUp_BasketLinks() {
	$$('a.addBasket').each(function(ele){
		var anchor = ele;
		anchor.observe('click',function(e) {
			Event.stop(e);
			element = Event.element(e).up('a');
			if ( element.hasClassName('fullScreen') ) { 
				Lightview.show({
				  href: element.href,
				  rel: 'iframe', 			
				  options: {
				  	overlayClose: false,
					closeButton	: false,
					overflow	: 'hidden',
					fullscreen	: true
				  }
				});	// end Lightview.show
			} else {
				Lightview.show({
				  href: element.href,
				  rel: 'iframe', 			
				  options: {
				  	overlayClose: false,
					closeButton	: false,
					overflow	: 'hidden',
					width		: 600,
					height		: 430
				  }
				});	// end Lightview.show
			}
		}); // end click observe
	});
	// observe the "Add to Basket" button and when clicked create "Back to iStylista button"
	$$('a.addBasket').each(function(ele) {
		var anchor = ele;
		anchor.observe('click',function(e) {
			if (!$('backLink')) {
				var attrs = {
		                href   : location.href,
						id	   : "backLink"
		            };
		
				var backLink = new Element('a', attrs);
				backLink.update('Return to iStylista');	
				backLink.hide();	
				$('wrapper').insert(backLink);		
			}
			
			var backLink = $('backLink');
			backLink.appear({duration: 1});
			backLink.highlight();
			backLink.observe('click', function(sic) {
				Event.stop(sic);
				Lightview.hide();
			});
		});
		
	});
}

// Hacked in for now.. .
// saf.addCallback({ on_complete: __istHookUp_BasketLinks});

Event.observe(document,'dom:loaded',function() {
	
	
	
	
	/**
	 *	CHANGING ROOM HELP/WELCOME BOX
	 */
	 	 
	if ($('changing-room-help') ) {
		var changingRoomHelp = $('changing-room-help');
		
		
		// COMPLETE PROFILE BUTTON
		if ( completeProfile = changingRoomHelp.down('a') ) {
			completeProfile.observe('click', function(e) {
				Event.stop(e);
				goNextSection( 1 );
			});
		}
		
		// START SHOPPING BUTTON
		if ( startShopping = changingRoomHelp.down('ul li#start-shopping-cta a') ) {
			startShopping.observe('click', function(e) {
				Event.stop(e);
				changingRoomHelp.fade({
					delay		:	0.3,
					duration	:	1
				});
				new Ajax.Request('/ajax_sys/null?start-shopping=true');
			});
		}
	}
	
	
	
	
	
	
	
	
	
	
	
		
	// observe the "Add to Basket" button 
		
	/**
	 *	
	// __istHookUp_BasketLinks(); // end .each loop 
	
	
	
	
	document.observe('lightview:hidden', function(event) {
		if ($('backLink')) {
			var backLink = $('backLink');
			backLink.fade({ queue: 'front' });
		}
	});
	
	
	
	
	
	/**
	 *	HOME PAGE GET STARTED
	 * /
	 
	 var getStartBtn 	= $('get-started-cta-link');
	 var bodyShapes 	= $('get-started-cr-bodyshape');
	 var signupBasics 	= $('get-started-cr-basics');
	 var delayLoader 	= $('get-started-cr-delay-loader');
	 var stages 		= $('get-started-cr-stages');
	 
	/**
	 *	Remove the offScreen class and hid instead..
	 * /
	 
	 if( bodyShapes ) {
	 	bodyShapes.hide();
	 	bodyShapes.removeClassName('offScreen');
		bodyShapesHeight = bodyShapes.getHeight();
	 }
	 if(delayLoader){
	 	delayLoader.hide();
	 	delayLoader.removeClassName('offScreen');
	 }
	 if(signupBasics){
	 	signupBasics.hide();
	 	signupBasics.removeClassName('offScreen');
		signupBasicsHeight = bodyShapes.getHeight();
	 }

	
	 if (getStartBtn) {
		 getStartBtn.observe('click',function(btnClick) {
		 	Event.stop(btnClick);
			if ( getStartedInner = $('get-started-inner') ) {
				stages.fade({ duration : iIntroSpeed });
				var bodyShapesHeight = bodyShapes.getHeight();
				var attrs = {
				                src  : '/images/ajax-loader-large.gif',
								style: 'position: absolute; right: 10px; top: 10px'
							};
				
				//var ajaxLoadingLarge = new Element('img', attrs);
				//getStartedInner.insert(ajaxLoadingLarge);		
				
				
				
				new Effect.Morph('get-started-inner', { 
					style		: 'height:' + bodyShapesHeight + 'px',
					duration 	: iIntroSpeed,
					afterFinish: function() { 
						bodyShapes.appear({
							duration : iIntroSpeed,
							afterFinish: function() { 						
								//ajaxLoadingLarge.remove();					
							}				
						});
						
					}
				});
			}// end getStartedInner
		 });
	 }
	/* */
	 
	
	
	
	/**
	 *	HomePage Bodyshapes...
	 */
	if ( $('homepage-body-list') ) {
		Event.observe($('homepage-body-list'),'mouseover',function(e){
			if ( (oLi = Event.element(e).up('li')) && (oSpan = oLi.select('span.defenition')[0]) ) {
				$('hpbsdesc').innerHTML = oSpan.innerHTML;
			}
		});
	}
	
	
	
});



/**
 *	HomePage DelayLoader..
 */


/**
 *	Hides BodyShapes, shows basic signup
 */
 
function __istGoHomePageBasics(oLink){
	$('get-started-cr-bodyshape').fade({ duration : iIntroSpeed });
	new Effect.Morph('get-started-inner', { 
		style		: 'height:130px',
		duration 	: iIntroSpeed,
		afterFinish: function() { 
			$('get-started-cr-basics').appear({
				duration : iIntroSpeed,
				afterFinish: function() { 						
					//document.location.href = sUrl;
				}				
			});
		}
	});
	return false;
}

/**
 *	Hides basic signup, shows loader ( form is submitting meanwhile )
 */
function __istDelayLoaderGo(oLink){
	sUrl = oLink.href;
	$('get-started-cr-basics').fade({ duration : iIntroSpeed });
	new Effect.Morph('get-started-inner', { 
		style		: 'height:80px',
		duration 	: iIntroSpeed,
		afterFinish: function() { 
			$('get-started-cr-delay-loader').appear({
				duration : iIntroSpeed,
				afterFinish: function() { 						
					//document.location.href = sUrl;
				}				
			});
		}
	});
	return false;
}

/**
 *	PROFILE LIVE UPDATE 
 */
var __ist_profileLiveUpdate_TIMER 	= false;
var __ist_profileLiveUpdate_URI 	= false;
 
function __ist_profileLiveUpdate( oElement ){
	
	 // build our url.. 
	sPath 	= document.location.pathname;
	sQuery 	= '?' + unescape( Form.serializeElements($(oElement).select('input')) );
	// set the url..
	__ist_profileLiveUpdate_URI	= '/ajax' + sPath + sQuery;
	// cancel any outstanding timers.. 
	
	if ( __ist_profileLiveUpdate_TIMER ) { 
		window.clearTimeout(__ist_profileLiveUpdate_TIMER); 
	}
	// ... and place the next one in the future..
	
	__ist_profileLiveUpdate_TIMER = window.setTimeout( '__ist_profileLiveUpdate_GO()', 500 );
}

function __ist_profileLiveUpdate_GO(){
	if ( __ist_profileLiveUpdate_URI ) {
		saf.navigate( __ist_profileLiveUpdate_URI );
		__ist_profileLiveUpdate_URI = false;
	}
}

document.observe("dom:loaded", function() {
	var myCompanyLogos = new Glider( $('my-glider'), {
		autoGlide: true	
	});

});











