/** * Lock the control bar in place when the user scrolls beyond the fold **/// Calculator the offset of the control bar to determine the threshold var controlBar = {	mainControlOffsetTop: 0,	mainControlHeight: 0,	ignoreNextHover: false,	timeOut:null,	isHiddenFlag:true,		init: function() {				// Disable scroll effect		if($('#control-bar').hasClass("no-scroll"))	{			return;		}			var that = this;				this.mainControlOffsetTop = $('#control-bar').offset().top;		this.mainControlHeight = $('#control-bar').height();								// Look for user state in cookie 0 or null is normal, 1 is expanded 						// Place the bar on load		this.setPosition();		$('#control-bar').bind('mouseleave', function() {			if(that.isHidden()) { return; }			clearTimeout(that.timeOut);			that.timeOut = setTimeout(function() {				that.toggle();			},400);		}).bind('mouseenter', function(e) { 			if(that.isHidden()) { return; }			clearTimeout(that.timeOut);		});		// Hover on mini bar		$('#view-nav').hover(function() {			if(!that.ignoreNextHover) {				that.toggle();				// when the mouse leaves the bar set a timeout to close it again 			} else {				that.ignoreNextHover = false;			}		});				// Fire onscroll		$(window).scroll(function() {			that.setPosition();		});	},		isHidden: function() {		return this.isHiddenFlag;				},		setHidden: function(hidden) {		return this.isHiddenFlag = hidden;						},			toggle: function() {		var that = this;			if(this.isHidden()) {			// If in hidden state, slide main bar down and hide mini			$('#control-bar-mini').slideUp('fast', function() {				that.setHidden(false);				$('#control-bar').hide();				that.attachMiniControlBar();				that.detachMainControlBar();			});					} else {			// Main controls are not hidden, let's hide them and show mini			$('#control-bar').slideUp('fast', function() {				that.setHidden(true);				that.detachMiniControlBar();				that.attachMainControlBar();			});		}	},	setPosition: function() {		if(!this.isHidden()) {			if ($(window).scrollTop() > this.mainControlOffsetTop) {				this.detachMainControlBar();			} else {				this.attachMainControlBar();			}				} else {			if ($(window).scrollTop() > (this.mainControlOffsetTop + this.mainControlHeight)) {				this.detachMiniControlBar();			} else {				this.attachMiniControlBar();			}		} 	},	detachMainControlBar: function() {		$('#control-bar').slideDown('fast').css({'position' : 'fixed', 'top' : '0', 'border-top' : '1px solid #ccc' });		$('#toggle-control').fadeIn('fast');	},		attachMainControlBar: function() {		$('#control-bar').slideDown('fast').css({'position' : 'absolute', 'top' :this.mainControlOffsetTop + 'px', 'border-top' : '1px solid #ccc' });		$('#toggle-control').fadeOut('fast');			this.setHidden(true);	},		detachMiniControlBar: function() {		$('#control-bar-mini').slideDown('fast').css({'position' : 'fixed', 'top' : '0','border-top' : '1px solid #ccc' });	},		attachMiniControlBar: function() {		$('#control-bar-mini').slideUp('fast');	}			};// Fire onloadcontrolBar.init();
