/**
 * Bootstrap.js - Bootstrap for all Javascript
 * 
 * @author  Webstores <info at webstores dot nl>
 *          Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

addEvent(window, 'load', function() {
	
	if($('product-tabs')) {
		var productTabs = new Tabs('product-tabs');
		productTabs.initialize();
	}
	
	if($('photo-gallery')) {
		var interval, playing = false;
		var gallery = new PhotoAlbum('gallery-main-image', $('gallery-images').getElementsByTagName('a'), { initial: 0 });
		
		addEvent('gallery-prev', 'click', function(e) {
			stopEvent(e);
			gallery.prev();
		});
		
		addEvent('gallery-slideshow', 'click', function(e) {
			stopEvent(e);
			if(playing) {
				clearInterval(interval);
				removeClass('photo-gallery', 'playing');
				playing = false;
			}
			else {
				interval = setInterval(gallery.next, 5000);
				addClass('photo-gallery', 'playing');
				playing = true;
			}
		});
		
		addEvent('gallery-next', 'click', function(e) {
			stopEvent(e);
			gallery.next();
		});
		
		var tabs = $('product-tabs').getElementsByTagName('a');
		for(var i = 0; i < tabs.length; i++) {
			addEvent(tabs[i], 'click', function(e) {
				stopEvent(e);
				gallery.setIndex(this.rel.split('-')[1]);
			});
		}
	}
});
