
Event.observe(window, 'load', function(){
	$$('.module.tabbed').each(function(module){
		new TabbedModule(module);
	});
	
	swfobject.embedSWF("/images/header.swf", "header", "960", "50", "9.0.45", "/images/express-install.swf", {}, {
		menu:'false', 
		wmode:'transparent'
	}, {});
});

Element.addMethods({
	insertCollection: function(element, collection){
		// TODO: Support placement: top, bottom, before, after.
		element = $(element);
		collection.each(function(item, i){
			this.insert(item);
		}, element);
		return element;
	}
});


var TabbedModule = Class.create({
	initialize: function(element){
		this.element = $(element);
		this.tabs = this.element.select('.nav li');
		this.images = this.element.select('img.thumb');
		this.pages = this.element.select('.entry');
		
		this.build();
	}, 
	
	build: function(){
		this.tabs.each(function(tab, i){
			tab.observe('click', function(){
				this.pages.each(function(page){ page.hide(); });
				this.pages[i].show();
				
				if(this.images.length > 1){
					this.images.each(function(image){ image.hide(); });
					this.images[i].show();
				}
				
				this.tabs.each(function(tab){
					tab.removeClassName('active');
					if(Prototype.Browser.IE) tab.removeClassName('ie7_class11');
				});
				this.tabs[i].addClassName('active');
				if(Prototype.Browser.IE) this.tabs[i].addClassName('ie7_class11');
			}.bind(this));
		}.bind(this));
	}
});

var Popup = Class.create({
	initialize: function(options){
		this.options = {
			location: '#', 
			name: 'popup', 
			width: 800, 
			height: 600, 
			left: false, 
			top: false, 
			
			directories: false, 
			menubar: false, 
			resizable: false, 
			toolbar: false, 
			scrollbars: false, 
			status: false, 
			
			alert: 'Your browser prevented a window from opening. Please disable your popup blocker to continue.'
		};
		Object.extend(this.options, options || {});
		
		if(!this.options.left) this.options.left = (screen.width - this.options.width) / 2;
		if(!this.options.top) this.options.top = ((screen.height - this.options.height) / 2) -50;
		
		return this.launch();
	}, 
	
	launch: function(){
		var option_string = new Hash({
			width: this.options.width, 
			height: this.options.height, 
			left: this.options.left, 
			top: this.options.top, 
			scrollbars: (this.options.scrollbars)? 'yes' : 'no', 
			directories: (this.options.directories)? 'yes' : 'no', 
			menubar: (this.options.menubar)? 'yes' : 'no', 
			resizable: (this.options.resizable)? 'yes' : 'no', 
			toolbar: (this.options.toolbar)? 'yes' : 'no', 
			scrollbars: (this.options.scrollbars)? 'yes' : 'no', 
			status: (this.options.status)? 'yes' : 'no'
		}).inject([], function(results, pair){
			results.push(pair.key+'='+pair.value);
			return results;
		}).join(',');
		
		this.window = window.open(this.options.location, this.options.name, option_string);
		
		if(this.window == undefined)
			return alert(this.alert);
		
		this.window.moveTo(this.options.left, this.options.top);
		this.window.focus();
		
		return this.window;
	}
});
