var video = {};
video.url = "sBf_hqgrtmg";
video.height = 315;
video.width = 560;
video.ratio = video.width/video.height;
window.addEvent('domready', function () {
	if(!Cookie.read('video')){
//		Cookie.write('video', true);
		$(document.body).setStyles({
			'height': '100%',
			'overflow': 'hidden'
		});
		var container = new Element('div',{id: 'container'}).setStyles({
			'background': '#000000',
			'position': 'absolute',
			'z-index': 1000,
			'top':0,
			'left':0,
			'width': "100%",
			'height': "100%",
			'overflow': 'hidden'
		}).inject($(document.body));
		new Element('div', {id: 'video'}).inject(container);
		new Element('div', {id: 'mask'}).setStyles({
			'background': 'url(intro/pixel-bg.png)',
			'position': 'absolute',
			'z-index': 2000,
			'top':0,
			'left':0,
			'width': 40000,
			'height': 40000
		}).inject(container);
		new Element('div',{'html': 'Skip Intro'}).setStyles({
			'position': 'absolute',
			'cursor': 'pointer',
			'color': '#ffffff',
			'z-index': 2002,
			'bottom':6,
			'right':0,
			'width': 100,
			'height': 20,
			'border-bottom': '1px solid #ffffff',
			'font-size': '12px',
			'line-height': '20px',
			'font-family': 'Verdana'
		}).inject(container).addEvent('click', function () {
	    	$('container').fade('out');
	    	(function () {
	    		$('container').destroy();
				$(document.body).setStyles({
					'height': 'auto',
					'overflow': 'auto'
				});
	    	}).delay(1000)
		});
		embedVideo(video.url);
		resizeVideo();
	}
}).addEvent('resize', function () {
	resizeVideo();
});
function embedVideo(idVideo){
    var params = { allowScriptAccess: "always" , 'wmode' : 'transparent'};
    var atts = { id: "video" };
    swfobject.embedSWF("http://www.youtube.com/e/" + idVideo + "?enablejsapi=1&controls=0&playerapiid=video&hl=en_US&rel=0&showinfo=0&controls=1&autohide=1&fs=1&modestbranding=1&hd=0autoplay=0",
    "video", video.width, video.height, "8", null, null, params, atts);
}
function resizeVideo(){
	if ( window.getSize().x / window.getSize().y >= video.ratio){
		$$('#video').setStyles({
			'width': window.getSize().x,
			'height': window.getSize().x / video.ratio,
			'margin-top': ( window.getSize().y - window.getSize().x / video.ratio ) / 2,
			'margin-left': 0
		});
	} else {
		$$('#video').setStyles({
			'width': window.getSize().y * video.ratio,
			'height': window.getSize().y,
			'margin-left': ( window.getSize().x - window.getSize().y * video.ratio ) / 2,
			'margin-top': 0
		});
	}
}
function onYouTubePlayerReady(idPlayer) {

	resizeVideo();
	$('video').addEventListener('onStateChange', 'onStateChange');
    $('video').playVideo();

}

function onStateChange( state ){

    if(state == 0){
    	$('container').fade('out');
    	(function () {
    		$('container').destroy();
			$(document.body).setStyles({
				'height': 'auto',
				'overflow': 'auto'
			});
    	}).delay(1000)
    } else if(state == -1){
    } else if(state == 1){
    } else if(state == 2){
    } else {
    }
}

