(function () { // START closure
eval(JELLY.local);


var tsandcs = Q('#terms-and-conditions');
var popUp = function () {
	return !window.open(this.href, '', 'width=350,height=450,scrollbars,location=no');
}

if (tsandcs) {
	tsandcs.onclick = popUp;
}

})(); // END closure


JELLY.getFlashVersion = function () {
  var version = 0,
		description;
  if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
	 description = navigator.plugins["Shockwave Flash"].description;
	 if (description != null) {
		var versionString = description.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
		version = parseInt(versionString.replace(/^(.*)\..*$/, "$1"));
	 }
  } else if (JELLY.browser.ie) {
	 
	 // FIX THIS!!
	 //return 8;
	 try {
		var flashObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
		description = flashObject.GetVariable("$version");
		if (description != null) {
			  var versionNumbers = description.replace(/^\S+\s+(.*)$/, "$1").split(",");
			  version = parseInt(versionNumbers[0]);
			}
	 } catch(ex) {}
  }
  return version;
};


JELLY.createFlashObject = function (config) {
	var path = config.path,
		 width = config.width,	
		 height = config.height,
		 fallback = config.fallback || 
		 	'<a href="http://www.adobe.com/">You need Flash player to view this content</a>',
		 params = config.params || {},	
		 vars = config.vars || {},
		 data = [],
		 pathData,
		 output = '',
		 standard = navigator.plugins && 
		 	typeof navigator.plugins['Shockwave Flash'] == 'object';
	
	for (var i in vars)
		data.push(i + '=' + escape(vars[i]));
	pathData = path + (data.length ? '?' + data.join('&') : '');
	
	output = '<object type="application/x-shockwave-flash" ' + '"data="' + pathData + '" ';
	if (!standard && JELLY.browser.ie) {
		output += 'classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	}
	output += ('width="' + width + '" height="' + height + '">\n');
	output += ('<param name="movie" value="' + pathData + '" />\n');
	for (var i in params) {
		output += ('<param name="' + i + '" value="' + params[i] + '" />\n'); 
	}
	output += fallback;

	return output + '</object>';
};

JELLY.flashReplacement = function () {

	var titles = JELLY.Q('#content .flash-text');
	for (var i=titles.length-1; i >= 0; i--) {
		var title = titles[i],
			 height = title.offsetHeight,
			 html = title.innerHTML.trim(),
			 align = JELLY.getStyle(title, 'text-align', false) === 'right' ? 'right' : 'left';

		title.style.height = height + 'px';
		title.style.padding = '0';
		
		html = '<p align="' + align + '">' + html + '</p>';		
		
		if (JELLY.hasClass(title, 'alt')) {
			html = html.
						replace(/<span>/gi, '<font color="#74828D">').
						replace(/<\/span>/gi, '</font>');
			
			html = /<br/gi.test(html) ? '<textformat leading="-5">' + html + '</textformat>' : html;
		} else {
			html = html.
						replace(/<span>/gi, '<font color="#FF031F">').
						replace(/<\/span>/gi, '</font>');
			
			if (JELLY.hasClass(title, 'white')) {
				html = '<font color="#ffffff">' + html + '</font>'
			}
		}
		title.innerHTML = 
			JELLY.createFlashObject({ 
				path: '_assets/swf/replacement.swf',
				width: '100%',
				height: height,
				fallback: html,
				params: {wmode: 'transparent'},
				vars: {
					HTML: html,
					timestamp: JELLY.browser.ie ? new Date().getTime() : 'none'
				}
			});
	}
};

JELLY.flashReplacement(); 

(function () {
			  
if (JELLY.getFlashVersion() < 8) return;

var movie_index = Math.floor(Math.random() * 7) + 1;
var wallpaper_align = 'T';

if (/Download/.test(document.body.id)) {
	movie_index = 6;
	wallpaper_align = 'B';
	document.body.style.backgroundColor = '#000';
} else {
	while (movie_index === 6) {
		movie_index = Math.floor(Math.random() * 7) + 1;
	}
}

if (movie_index === 4) {
	wallpaper_align = 'B';
}

var wallpaper = JELLY.Q('#wallpaper');

if (JELLY.browser.ie6) {
	var fixHeight = function () {
		wallpaper.style.height = JELLY.getViewport()[1] + 'px';
	};
	fixHeight();
	JELLY.addEvent(window, 'resize', fixHeight);
} 
wallpaper.innerHTML = 
	JELLY.createFlashObject({ 
		path: '_assets/swf/anims.swf',
		width: '100%',
		height: '100%',
		fallback: '&nbsp;',
		params: {wmode: 'transparent'},
		vars: {
			align: wallpaper_align,
			anim: movie_index 
		}
	});

})();



