var w, h, ex_holder;

var submitForm = function() {
	if(arguments[1] > 0) {
	
	} else {
		$(arguments[0]).submit();
	}
}

var initViews = function() {
	/*
		1. get the width and height of the screen.
		2. split up the navbar accordingly
	*/
	w = window.getSize().x;
	h = window.getSize().y;
	
	var list = $('nav').getChildren();
	list.each(function(li) {
		li.set({
			'styles':{
				'width':w/6.05
			},
			'events':{
				'mouseover':function() {
					this.setStyles({
						'color':'#2163e3'
					});
				},
				'mouseout':function() {
					this.setStyles({
						'color':'#c8c8c8'
					});
				}
			}
		});
	});
	
	$('content').set({
		'styles':{
			'top':h * .2
		}
	});
	
	ex_holder = [$('example_1'),$('example_2'),$('example_3'),$('example_4')];
	ex_holder.each(function(ex) {
		ex.set({
			'class':'unTweened',
			'events':{
				'mouseover':function() {
					this.setStyles({
						'background-color':'#aaaaaa',
						'cursor':'pointer'
					});
				},
				'mouseout':function() {
					this.setStyles({
						'background-color':'#c8c8c8'
					});
				},
				'click':function() {
					if(this.className == 'unTweened') {
						$(this.id + "_txt").set({
							'styles':{
								'display':'block'
							}
						}); 
						this.tween('width',w * .67);
						this.set({
							'class':'tweened'
						});
					} else {
						this.tween('width',48);
						$(this.id + "_txt").set({
							'styles':{
								'display':'none'
							}
						}); 
						this.set({
							'class':'unTweened'
						});
					}
				}
			}
		});
	});
	$('examples').set({
		'styles':{
			'width':w * .67
		}
	});
	$('blurb').set({
		'styles':{
			'width':w * .32
		}
	});
};

var launch = function() {
	var bundle = arguments[0];
	if(arguments[1] == 1) {
		ex_holder.each(function(ex) {
			ex.set({
				'styles':{
					'display':'block'
				}
			});
			ex.tween('width',48);
			ex.set({
				'class':'unTweened'
			});
			ex.empty();
		
			var ex_name = ex.id + "_txt";
			var ex_tab = new Element("table");
			var ex_row = new Element("tr");
			var ex_textCell = new Element("td");
			var ex_imgCell = new Element("td");
			var ex_img = new Element("img",{
				'src':bundle + "_bundle/" + ex.id + ".png",
				'class':'bundleThumb'
			});
			var ex_text = new Element("div",{
				'id':ex_name,
				'styles':{
					'display':'none'
				}
			});
			ex_imgCell.adopt(ex_img);
			ex_textCell.adopt(ex_text);
		
		
			var zReq = new Request.HTML({
				method:'get',
				url:bundle + "_bundle/" + ex.id + ".html",
				update:$(ex_text)
			}).send();
		
			ex_row.adopt(ex_imgCell,ex_textCell);
			ex_tab.adopt(ex_row);
			ex.adopt(ex_tab);
		});
	} else if(arguments[1] == 0) {
		ex_holder.each(function(ex) {
			ex.setStyles({
				'display':'none'
			});
		});
	}
	
	$('blurb').empty();
	$('content').setStyles({
		'display':'block'
	});
	var xReq = new Request.HTML({
		method:'get',
		url:arguments[0] + "_bundle/" + arguments[0] + "_blurb.html",
		update:$('blurb')
	}).send();
	
};

window.addEvent('domready',initViews);
