window.addEvent('domready', function(){
	$('flashThumb').removeEvents().addEvent('click', function(e){
		$('flashPlayer').setStyle('cursor', 'pointer');
		
		var so = new SWFObject("flashpub/swf/HomeVideoHTML.swf", "flashContainerBig", "700", "392", "9", "#FFFFFF");
		so.addVariable("xmlpath", "flashpub/xml/siteconfig.xml");
		so.addVariable("avatarTempFolder", "/avatar_tmp/");
		so.write("flashContainerBig");
		
		showPopupLayer('flashPlayer');
	});
});

function showPopupLayer(strId){	
	var el = $(strId);			
	if(!el)	return;
	var _opacity = 0.5;		
	
	new Element('div',{
		'id': 'divPopup'+ strId,
		'styles':{
			'display': 'block',
			'visibility': 'visible',
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'width': window.getWidth() + 'px',				
			'height': window.getScrollSize().y,
			'z-index':'500',
			'backgroundColor': '#000000',
			'opacity': 0
		},
		'events': {
			'click': function(e){
				if($$('#' + strId + ' div[id=flashContainerBig]').length > 0){
					$('flashContainerBig').set('html', '');
				}
				hideLayer(strId);
			}
		}
	}).injectInside($$('body')[0]);	
	
	new Fx.Tween($('divPopup'+strId), {
		duration: 500
	}).start('opacity', _opacity);
	
	
	el.injectInside($$('body')[0]);
	
	el.setStyle('display', 'block');
	var zIndex = 999;		
	
	el.setStyles({
		'opacity': 0,
		'position': 'absolute',
		'top': (window.getHeight() - el.getCoordinates().height)/2 + window.getScrollTop(),
		'left': (window.getWidth() - el.getCoordinates().width)/2 + 'px',
		'z-index': zIndex
	});
	new Fx.Tween(el).start('opacity', 1);
	
	if(document.body.getScrollSize().y > window.getScrollTop()) {
		window.removeEvents().addEvent('scroll',function(){			
			if(el){
				el.setStyle('top',((window.getHeight() - el.getCoordinates().height)/2 + window.getScrollTop() + 'px'));				
				var width = window.getScrollSize().x;
				var height = window.getScrollSize().y;
				if (height < document.body.clientHeight) {
					height = document.body.clientHeight;
				}				
				if($('divPopup'+strId)){
					$('divPopup'+strId).setStyles({
						'width': width, 
						'height': height
					});
				}
			}
		});
	}
	window.addEvent('resize', function(e){
		var w = window.getWidth();			
		if($('divPopup'+strId)) {
			$('divPopup'+strId).setStyles({
				'width': window.getWidth() + 'px',
				'height': document.body.getScrollSize().y
			});
		}
	});
	//add event close 
	if($$('#' + strId + ' a.close')[0]){
		$$('#' + strId + ' a.close')[0].removeEvents().addEvent('click', function(e){
			e.stop();	
			new Fx.Tween(el).start('opacity', 0);				
			setTimeout(function(){
				el.setStyle('top',-1500);
				if($('divPopup'+strId)) {
					$('divPopup'+strId).destroy();
				}					
				if(Browser.Engine.trident4) {
					window.removeEvent('scroll');
				}
			}, 500);
			window.removeEvents();
		});
	}
}

function hideLayer(id){
	if(id && $(id)) $(id).setStyles({
		'top': -1500
	});

	if($('divPopup'+id)) {
		new Fx.Tween($('divPopup'+id), {
			duration: 500
		}).start('opacity', 0);
		setTimeout(function(){
			$('divPopup'+id).destroy();
		}, 500);
	}		
	if(Browser.Engine.trident4) {
		window.removeEvent('scroll');
	}
	window.removeEvents();
}
