
var PeachGully = {
	init: function(){
		//if ($('booking')) window.location = 'http://www.globalavailability.com/art/guests/guest-main.php?pid=786';
		if ($('enquiries')) window.location = 'http://www.peachgully.co.nz/contact.html';
		PeachGully.revealMenu();
		PeachGully.revealThumbs();
		PeachGully.rewriteLinks();
		if ($('gallery')) PeachGully.setupGallery();
		if (!window.ie && !window.opera) PeachGully.addMagnifier();
	},

	rewriteLinks: function(){
		var a = $$('a');

		for (var i=0; i < a.length; i++) {
			if (a[i].rel == 'external') a[i].target = '_blank';
		}
	},

	revealMenu: function(){
		var timer = 0;
		var easeFxs = [];
		var menuItems = $$('#menu li');

		menuItems.each(function(el, i){
			var tran = 'bottom';
			var tval = -50;
			el.setStyle(tran, tval);

			timer += 100;
			easeFxs[i] = new Fx.Style(el, tran, {
				wait: false,
				duration: 1500,
				transition: Fx.Transitions.Back.easeOut,
				onComplete: PeachGully.addMenuHover.pass([el, i])
			});
			easeFxs[i].start.delay(timer, easeFxs[i], 0);
		}, this);
	},

	addMenuHover: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a' || el.hasClass('here')) return;
		var overFxs = new Fx.Styles(first, {'duration': 200, 'wait': false});
		el.mouseouted = true;
		el.addEvent('mouseenter', function(e){
			overFxs.start({
				'color': '777',
				'margin-bottom': -5
			});
		});
		el.addEvent('mouseleave', function(e){
			overFxs.start({
				'color': 'fff',
				'margin-bottom': 0
			});
		});
	},

	revealThumbs: function(){
		var timer = 0;
		var menuItems = $$('#head img');
		var easeFxs = [];

		menuItems.each(function(el, i){
			var tran = 'opacity';
			var tval = 0;
			el.setStyle(tran, tval);

			timer += 100;
			easeFxs[i] = new Fx.Style(el, tran, {
				duration: 1500,
				//onComplete: PeachGully.addThumbHover.pass([el, i]),
				wait: false
			});
			easeFxs[i].start.delay(timer, easeFxs[i], 1);
		}, this);
	},

	addThumbHover: function(el, i){
		var first = el;
		if (!first || first.getTag() != 'img' || el.hasClass('here')) return;
		var overFxs = new Fx.Styles(first, {'duration': 500, 'wait': false});
		el.mouseouted = true;
		el.addEvent('mouseenter', function(e){
			overFxs.start('opacity', .75);
		});
		el.addEvent('mouseleave', function(e){
			overFxs.start('opacity', 1);
		});
	},

	resizeSidebar: function(){
		$('side').setStyle('height', ($('guts').getCoordinates().height - 235) + 'px');
	},

	addMagnifier: function(){
		var zoomables = $$('a.zm');

		zoomables.each(function(el, i){
			steez = (i == 2) ? 'zm last' : 'zm';
			zm = document.createElement('img');
			zm.setAttribute('class', steez);
			zm.setAttribute('src', 'img/zm.png');
			el.appendChild(zm);
		});
	},

	setupGallery: function(){
		var qry = window.location.search.substring(1);
		var pos = qry.indexOf('=');
		var val = qry.substring(pos+1);

		if (val) (function(){Lightbox.show('gallery/' + val + '.jpg', '')}).delay(500);
	}
};

window.addEvent('domready', Lightbox.init.bind(Lightbox));
window.addEvent('domready', PeachGully.init);
window.addEvent('load', PeachGully.resizeSidebar);
