var Site = {
	init: function() {
		this.stripFx = new Array();
		this.images  = new Array();
		this.first   = true;
		page         = $('mainimage') ? true : false;
		
		$$('.stripcontent').each(function(el, i){
			// Set up effects for photo strip.
			this.stripFx[i] = new Fx.Elements($$("#strip_"+el.id, "#strip_"+el.id+"_over"), { duration: 300 });
			this.stripFx[i].set({'1': { 'opacity': (i == 0 && page ? 1 : 0) }});
			el.addEvent('mouseover',  function(e){ this.fadeIn(i, el);  }.bind(this));
			el.addEvent('mouseleave', function(e){ this.fadeOut(i, el); }.bind(this));
			$(el.id+'_cont').addEvent('mouseover',  function(e){ this.fadeIn(i, el);  }.bind(this));
			$(el.id+'_cont').addEvent('mouseleave', function(e){ this.fadeOut(i, el); }.bind(this));
			
			// Set up effects for main image if it exists and pre-load all appropriate images.
			if (page && $(el.id+'_cont')) {
				var imgload = new Image();
				imgload.src = el.href;
				$(el.id+'_cont').addEvent('click', function(e){
					e = new Event(e);
					e.stop();
					this.changeImage(el.href);
				}.bind(this));
			}
		}.bind(this));
		
		if (page) {
			this.imageFx = new Fx.Style($('imageoverlay'), 'opacity', {duration:350});
			this.imageFx.hide();
		}
		
		// Set up Google Maps.
		if ($('contact5') && GBrowserIsCompatible()) {
			this.map = new GMap2($('contact5'));
			var markerlat = new GLatLng(51.531975, -1.900898);
			
			var infobubble = new Element('div', { 'id': 'mapbubble' });
			infobubble.innerHTML = "<strong>PG Events Ltd</strong><br /><span>Wootton Bassett</span><br /><span>SN4 7SR</span>";
			
			this.map.setCenter(new GLatLng(51.53987603054311, -1.8970298767089844), 14);
			this.map.addControl(new GSmallMapControl());
			this.map.addOverlay(new GMarker(markerlat));
			this.map.openInfoWindow(markerlat, infobubble);
			
			window.addEvent('unload', GUnload);
		}
	},
	
	fadeIn: function(i, el) {
		if (this.first && i > 0) {
			this.first = false;
			this.stripFx[0].start({'1': { 'opacity': 0 }});
		}
		this.stripFx[i].stop();
		this.stripFx[i].start({
			'1': { 'opacity': 1 }
		});
		el.setStyle('color', '#342458');
	},
	
	fadeOut: function(i, el) {
		this.stripFx[i].stop();
		this.stripFx[i].start({
			'1': { 'opacity': 0 }
		});
		el.setStyle('color', '#5a3f99');
	},
	
	changeImage: function(l) {
		this.imageFx.start(1).chain(function(){ $('mainimage').src = l; this.start(0); });
	}
};

window.addEvent('domready', Site.init.bind(Site));
