window.addEvent('domready', function() {

function getFlashVars()
{
	return flashvars = {
		src: $('home_player').get('href'),
		autostart: 'true',
		scaleMode: 'fit',
		frameColor: '242424'
	};
}

var requiredFlashVersion = "10.0.0.0";
var expressInstallPath = "/Files/expressInstall.swf";
var flashswfpath = "/Files/Player.swf";
var flashEmbedWidth = "100%";
var flashEmbedHeight = "100%";
var browserHeightPadding = 100;
var params = {allowFullScreen: 'true', quality: 'high', wmode: 'transparent'};

attributes = {id: 'home_player'};

firstATag = $('overlayed_thumbs').getElement('a');

if($(firstATag).get('class') == 'video')
{
	swfobject.embedSWF(flashswfpath, 'home_player' , 792 , 384, requiredFlashVersion, expressInstallPath, getFlashVars(), params, attributes);
}
		
$$('#overlayed_thumbs a').each(function(elem, i)
{
	elem.addEvent('click', function()
	{		
		var home_img = document.getElementById('home_img');
		var home_container = document.getElementById('home_container');
		var newHref = $(this).get('href');
		var index = i;
		
		var elem = this;
		
		var fx = new Fx.Morph(home_container, {
            duration: 1000
        });
		
		fx.start({
            'opacity': 0
        }).chain(function()
		{	
			if($(elem).get('class') == 'video')
			{
				$('home_container').set('html', '');
				$('overlayed_text').set('html', '');
				
				$('overlayed_thumbs').set('class', 'video');
	
				new Element('a',{ href:newHref, style:"display:block; margin-bottom: 80px; width:800px;height:484px;", id:"home_player"}).inject($('home_container'));
								
				fx.start({
					'opacity': 1
				});

				swfobject.embedSWF(flashswfpath, 'home_player' , 800 , 430, requiredFlashVersion, expressInstallPath, getFlashVars(), params, attributes);
			}
			else
			{			
				var images = [$(elem).getChildren('div.link').get('html')];
		
				var loader = new Asset.images(images, 
				{
					onComplete: function() 
					{
						images.each(function(im) 
						{
							$('home_container').set('html', '');
							
							new Element('a',{ href:newHref, id:"home_link"}).inject($('home_container'));
							new Element('img',{ src:im.toString(), id:"home_img"}).inject($('home_link'));
							$('overlayed_text').set('html', $(elem).getChildren('div.text').get('html'));
							
							var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
							
							if(ie6)
							{
								$('overlayed_thumbs').set('class', 'img_ie6');
							}
							else
							{
								$('overlayed_thumbs').set('class', 'img');
							}
						});
						
					fx.start({
						'opacity': 1
					});
					}
				});
			}
			

		});
		return false;
	});
});

});
