function mainFunctions(){
	$('#popup a.close').click(function(){
		$('#popup').fadeOut(400, function(){
			$('#popup-shadow').css('display','none');
		});	
	});
	$('div.video a img').click(function(){
		$('#popup-shadow').css('display','block');
		$('#popup').children('div.holder').css('width','0');
		$('#popup').fadeIn(400);
		var width = $('#popup').width();
		$('#popup').children('div.holder').animate({'width':width});
		poupUp_height();
	});
}

function poupUp_height()
{
	var _lightbox = document.getElementById("popup");
	var _popup_table = document.getElementById("popup-shadow");
	var _height = 0;
	var _width = 0;
	var _minWidth = 1020;
	if (window.innerHeight) {
		_height = window.innerHeight;
		_width = window.innerWidth;
	} else {
		_height = document.documentElement.clientHeight;
		_width = document.documentElement.clientWidth;
	}
	var _page = document.getElementsByTagName("body")[0];
	if (_lightbox && _popup_table && _page) {
		if (_height > _page.offsetHeight) _popup_table.style.height = _height + "px";
		else _popup_table.style.height = _page.offsetHeight + "px";
		if (_width < _minWidth) {_popup_table.style.width = _minWidth + "px";} else {_popup_table.style.width = '100%'}
		
		if (_height > _lightbox.offsetHeight) {
			if (!window.innerHeight) {
				_lightbox.style.position = "absolute";
				_lightbox.style.top = document.documentElement.scrollTop + (_height - _lightbox.offsetHeight) / 2 + "px"
			} else {
				_lightbox.style.position = "fixed";
				_lightbox.style.top = (_height - _lightbox.offsetHeight) / 2 + "px";
			}
		}
		else {
			_lightbox.style.top = "0px";
			_lightbox.style.position = "absolute";
		}
		if (_width > _lightbox.offsetWidth) _lightbox.style.left = (_width - _lightbox.offsetWidth) / 2 + "px";
		else {_lightbox.style.left = "0px";_lightbox.style.position = "absolute";}
	}
}


if (window.addEventListener){
	window.addEventListener("resize", poupUp_height, false);
	window.addEventListener("load", mainFunctions, false);
}
else if (window.attachEvent){
	window.attachEvent("onresize", poupUp_height);
	window.attachEvent("onload", mainFunctions);
	window.attachEvent("onscroll", poupUp_height);
}