
;(function () { eval(JELLY.local);  // START CLOSURE 	
					

var dummy = ''; //'index.php?refresh=' + new Date().getTime();

var navigation = escape(([
							'home :: 	 ../home/' + dummy,
							'news :: 	 ../news/' + dummy,
							'about :: 	 ../about/' + dummy,
							'gigs :: 	 ../gigs/' + dummy,
							'gallery ::  ../gallery/' + dummy,
							'video :: 	 ../video/' + dummy,
							'shop :: 	 http://itunes.apple.com/gb/album/if-we-only-had-the-time/id415938131',
							'signup :: 	 ../signup/' + dummy,
							'contact ::  ../contact/' + dummy,
							'myspace ::  http://www.myspace.com/petedupon',
							'facebook :: http://www.facebook.com/pages/Pete-du-Pon/7897870417?ref=s',
							'twitter :: http://www.twitter.com/peteduponmusic'
						].join(',').replace(/\s+/g, '')));


var flash_nav = new SWFObject("../assets/swf/nav.swf", "nav-swf-object", 850, 30, 8, "#F1EFEC");
flash_nav.addParam("scale", "noscale");
flash_nav.addParam("wmode", "transparent");
flash_nav.addVariable("navigation", navigation);
flash_nav.addVariable("region", document.body.id.toLowerCase());
flash_nav.write("nav");

switch (document.body.id) { 
	
	case 'Home' : 
		//stopAudioPlayer();
		var player = new SWFObject("../assets/swf/player.swf", "xxx", 430, 345, 8, "#F1EFEC");
		player.addParam("scale", "noscale");
		player.addParam("wmode", "transparent");
		player.addVariable("YOUTUBE_ID", Q('#youtube-id').getAttribute('title'));
		player.write("video-player");
	break;
	
	case 'Video' : 
		//stopAudioPlayer();
		var youtubeid = parseQueryString().youtube || Q('#content a')[0].href.split('youtube=')[1].split('&')[0];
		var player = new SWFObject("../assets/swf/player.swf", "xxx", 430, 320, 8, "#F1EFEC");
		player.addParam("scale", "noscale");
		player.addParam("wmode", "transparent");
		player.addVariable("YOUTUBE_ID", youtubeid);
		player.write("video-player");
	break;

}

/*
function stopAudioPlayer() {
	if (parent.document.getElementById("header-swf-object")) { 
	//alert(parent.document.getElementById("header-swf-object").offsetWidth)
		parent.document.getElementById("header-swf-object")._stopPlayer();
	}
}

function startAudioPlayer() {
	if (parent.document.getElementById("header-swf-object")) { 
		parent.document.getElementById("header-swf-object").startPlayer();
	}
}
*/




function gallery(options) {
	
	var links = Q('#thumbs a'),
	    loading = false,
	    placeholder = Q('#placeholder'),
		 container = Q('#image-container'),
		 caption = Q('#caption'),
		 pager = Q('#pager'),
	    fader = new Tween(placeholder),
		 first = links[0],
		 current_index = 0;

	fader.setStyle('opacity', 0);
	
	links.each(function (hlink, index) {
		hlink.image = new Image();
		hlink.image.index = index;
		hlink.image.loaded = false;
		addEvent(hlink.image, 'load', function () {
														this.loaded = true;
														this.dims = [this.width, this.height];
													});
		hlink.image.alt = hlink.getElementsByTagName('img')[0].alt;
		hlink.image.src = hlink.href;
		addEvent(hlink, 'click', function (e) {
												clickHandler(e, this)
											});
	});
	
	function clickHandler(e, hlink) {
		stopEvent(e);
		if (loading) return;
		if (!hlink.image.loaded) {
			loading = true;
			placeholder.innerHTML = '';
			container.className = 'loading';
			addEvent(hlink.image, 'load', function () {
				this.loaded = true;
				showImage(hlink);
			});
			return;
		}
		if (options.fadeup) { 
			showImage(hlink, true);
		} else {
			showImage(hlink);
		}
	}

	function showImage(hlink, fade) {
		pagerRefresh(hlink);
		loading = false;
	   placeholder.innerHTML = '';
		placeholder.style.width = hlink.image.dims[0] + 'px';
		placeholder.style.height = hlink.image.dims[1] + 'px';
		container.className = '';
		
		fader.setStyle('opacity', 0);
		caption.innerHTML = hlink.image.alt;
		insertElement(hlink.image, placeholder);
		
		if (fade) { 
			browser.ie ?  
				fader.start('opacity', 1) :
				fader.start('opacity', .999);
		} else {
			fader.setStyle('opacity', 1);
		}
	}
	
	function pagerRefresh(hlink) {
		current_index = hlink.image.index;
		if (current_index === 0 && back_btn) {
			addClass(back_btn, 'disabled');
			removeClass(next_btn, 'disabled');
		} else if (current_index === links.length-1 && back_btn) {
			addClass(next_btn, 'disabled');
			removeClass(back_btn, 'disabled');
		} else if (back_btn) {
			removeClass(next_btn, 'disabled');
			removeClass(back_btn, 'disabled');
		} 
	}

	
	var next_btn = createElement('a', {'setHTML': 'Next &gt;', 'class': 'fr next', 'href': '#'});
	var back_btn = createElement('a', {'setHTML': ' &lt; Back', 'class': 'fl back', 'href': '#'});
	insertElement(back_btn, caption, 'before');
	insertElement(next_btn, caption, 'before');


	next_btn.onclick = function (e) {
		stopEvent(e);
		if (current_index === links.length-1) return;
		clickHandler(e, links[current_index + 1])
	};
	back_btn.onclick = function (e) {
		stopEvent(e);
		if (current_index === 0) return;
		clickHandler(e, links[current_index - 1])
	};
	 
	
	if (options.loadandgo) { 
		if (first.image.loaded) { 
			showImage(first, true);
		} else {
			loading = true;
			container.className = 'loading';
			addEvent(first.image, 'load', function () {
				this.loaded = true;
				this.dims = [this.width, this.height];
				showImage(first, true);
				removeEvent(first.image, 'load', arguments.callee); // fixes opera
			});
		}
	}

} // END GALLERY

if (document.getElementById('placeholder')) {
	gallery({ 'loadandgo': true, 'fadeup': true  });
}







})(); // END CLOSURE
