
/* Debug Variable */
var debug;


/* Start Up */
var StartUp = Class.create(); StartUp.prototype = {

	initialize: function(runnable)
	{
		Event.observe(document, 'dom:loaded', runnable.run.bindAsEventListener(runnable));
	}

}


/* External Links */
var ExternalLinks = {

	run: function()
	{
		$$('a[rel="external"]').each(ExternalLinks.each);
	},

	each: function(link)
	{
		link.observe('click', ExternalLinks.click.bindAsEventListener(link));
	},

	click: function(event)
	{
		event.stop();
		open(this.href);
	}

}
new StartUp(ExternalLinks);


/* Menu CSS Hack */
var Menu = {

	run: function()
	{
		$$('table#menu td').each(Menu.each);
	},
	each: function(td)
	{
		Menu.setActive(td);
		td.observe('mouseover', Menu.observeMouseOver.bindAsEventListener(td));
		td.observe('mouseout', Menu.observeMouseOut.bindAsEventListener(td));
	},
	setActive: function(td)
	{
		var next_td = td.nextSibling;
		if (next_td) {
			var td_a = td.down();
			if (td_a && td_a.hasClassName('active')) {
				next_td.removeClassName('line');
			}
		}
	},
	observeMouseOver: function(event)
	{
		var next_td = this.next();
		if (next_td) {
			next_td.removeClassName('line');
		}
	},
	observeMouseOut: function(event)
	{
		var next_td = this.next();
		if (next_td) {
			var td_a = this.down();
			if (td_a && td_a.hasClassName('active')) {
				next_td.removeClassName('line');
			} else {
				next_td.addClassName('line');
			}
		}
	}

}
new StartUp(Menu);


/* content media box */
var MediaBox = {

	run: function()
	{
		var media_box = $$('.content_media').first();
		if (media_box) {
			var image = media_box.down('img');
			var video = media_box.down('a');

			if (video) {
				var width  = 270;
				var height = 220;
				media_box.id = 'content_media_'+ Math.floor(Math.random() * 1000 + 1);
				var so = new SWFObject('/media/js/mediaplayer/mediaplayer.swf', media_box.id, width, height, 9);
				so.addParam('allowfullscreen', 'true');
				so.addParam('wmode', 'transparent');
				so.addVariable('width', width);
				so.addVariable('height', height);
				so.addVariable('file', video.href);
				if (image) {
					so.addVariable('image', image.src);
				}
				so.addVariable('searchbar', 'false');
				so.addVariable('volume ', '100');
				so.write(media_box.id);
			}
		}
	}

}
new StartUp(MediaBox);


/* flash box */
var FlashBox = {

	run: function()
	{
		$$('.home div.flash').each(function(flash) {
			var rel = flash.getAttribute('rel');
			if (rel) {
				flash.id = 'flash_'+ Math.floor(Math.random() * 1000 + 1);
				var width  = 431;
				var height = 241;
				var so = new SWFObject(rel, flash.id, width, height, 9);
				so.addParam('allowfullscreen', 'true');
				so.addParam('wmode', 'transparent');
				so.write(flash.id);
			}
		});
	}

}
new StartUp(FlashBox);


