/* Start Up */
function StartUp(runnable)
{
	$(document).ready(runnable.run);
}


/* External Links */
var ExternalLinks =
{
	run: function()
	{
		$('a[rel="external"]').bind('click', ExternalLinks.click);
	},
	click: function(event)
	{
		open(this.href);
		return false;
	}
}
StartUp(ExternalLinks);


/* Confirm Links */
var ConfirmLinks =
{
	run: function()
	{
		$('a.confirm').bind('click', ConfirmLinks.click);
	},
	click: function(event)
	{
		if (!confirm(this.title)) {
			return false;
		}
	}
}
StartUp(ConfirmLinks);


/* Vertical Align For IE Browsers */
var VerticalAlignIE =
{
	run: function()
	{
		if ($.browser.msie) {
			$('.vertical_align').each(function(i){
				var item = $(this);
				item.wrapInner('<span></span>');
				var span = item.find('span:first');

				var span_height = span.height();
				var item_height = item.height();

				var padding_top = Math.round((item_height - span_height) / 2);
				item.css('padding-top', padding_top);

				var new_height = item_height - padding_top;
				item.css('height', new_height);
			});
		}
	}
}
StartUp(VerticalAlignIE);


/* Multi Checkbox Select */
var MultiCheckboxSelect =
{
	run: function()
	{
		$('input.multi_select[type="checkbox"][value!=""]').bind('click', MultiCheckboxSelect.click);
	},
	click: function(event)
	{
		var checkbox = $(this);
		if (checkbox.attr('checked') == true) {
			$('input.'+ checkbox.attr('value')+'[type="checkbox"]').attr('checked', 'checked');
		} else {
			$('input.'+ checkbox.attr('value')+'[type="checkbox"]').removeAttr('checked');
		}
	}
}
StartUp(MultiCheckboxSelect);

/* IE6 png fix */
var IEpngFix =
{
	run: function()
	{
		$.ifixpng('/media/dsg/blank.gif');
		$('img[src$=".png"]').ifixpng();
	}
}
StartUp(IEpngFix);

/* Video player */
var VideoPlayer =
{
	run: function()
	{
		$('a[href$=".flv"]').each(VideoPlayer.substitute);
	},
	substitute: function(i)
	{
    var id = 'player_' + i
    this.id = id;
    var params = {
      allowfullscreen: 'true',
      wmode: 'opaque'
    }
    var flashvars = {
      file: this.href
    }
    var image  = this.firstChild;
    var width  = 320;
    var height = 240;
    if (image && image.src) {
      flashvars.image = image.src;
      if (image.width)  width  = image.width;
      if (image.height) height = image.height;
    }
    height += 19;
    swfobject.embedSWF('/media/js/player/player.swf',id,width,height,'9.0.0','expressInstall.swf', flashvars, params);
	}
}
StartUp(VideoPlayer);
