// Lifted from the Normative website and Justin Oullette's source code on Github.
// Justin is an extremely talented gentleman and all credit for the fanciness on mymixcafe.com goes to him.
// http://justinouellette.com/

var scroller = new Fx.Scroll('airlock',{
	transition: Fx.Transitions.Sine.easeOut,
	duration: 200,
	onComplete: refigure
});

function frame(number) {
	current = number;
	scroller.toElement('frame' + number);
	$$('div.navigation ul li a').setStyle('background-color','transparent');
	$$('div.navigation ul li a').setStyle('border-bottom','none');
	$$('div.navigation ul li a').setStyle('color','#275297');
	
	if(number >= 1) {
		$$('div.navigation ul li a').each(function(li,i) {
			if(i === number-1) {
			  li.setStyle('background-color','#31599b');
	      li.setStyle('border-bottom','1px solid #31599b');
			  li.setStyle('color','#fff');
			}
		});
	}
}

function brendan(divs) {
	divs.each(function(div) {
		var windowsize = window.getSize();
		var img = div.getElement('img');					
		var imgsize = img.getSize();
		var over = imgsize.x / imgsize.y;
		var under = imgsize.y / imgsize.x;
	
		div.setStyle('width',windowsize.x);
		div.setStyle('height',windowsize.y);
	
		if((windowsize.x / windowsize.y) >= over) {
			img.setStyle('width',windowsize.x);
			img.setStyle('height',under*windowsize.x);			
		} else {
			img.setStyle('width',over*windowsize.y);
			img.setStyle('height',windowsize.y);		
		}
	});
}

function refigure() {
	var height = window.getHeight();
	var width = window.getWidth();
	var frames = $$('li.frame');
	
	$('airlock').setStyle('width',width);
	$('frames').setStyle('width',width * frames.length);
	frames.setStyle('width',width);
	frames.setStyle('height',height);

	$$('div.container').each(function(div) {
		var w = width - div.getStyle('paddingLeft').toInt();
		var h = height - div.getStyle('paddingTop').toInt();
		div.setStyle('width',w);
		div.setStyle('height',h);		
	});
	
	brendan($$('div.scale'));
	$('airlock').scrollLeft = (current * width) - width;	
	$('airlock').setStyle('visibility','visible');	
}

window.addEvent('resize',function() {
	refigure();
	if(Browser.Engine.gecko) setTimeout(refigure,50);
});

switch(window.location.hash) {
	case '#/locations_and_hours': frame(2); break;
	case '#/menu': frame(3); break;
	case '#/delivery_and_catering': frame(4); break;
	case '#/reviews': frame(5); break;
	case '#/photos': frame(6); break;
	case '#/history': frame(7); break;
	case '#/investors': frame(8); break;
	case '#/contact': frame(9); break;
	default: frame(1);
}
