var url = "http://cdn.cloudfiles.mosso.com/c119391/";
var flashvars = {
	prerollvars: false,
	midrollvars: false,
	postrollvars: false,
	zoomcontrol: false,
	playlist: false,
	http: true,
	hd: 1,
	width: 600,
	height: 368,
	autoplay: 1,
	fs: 1
};
var params = {
	allowfullscreen: true,
	allowscriptaccess: 'always',
	wmode: 'transparent'
};
var videos = [
	{
		file: url+"1_low.f4v",
		hdpath: url+"1_high.f4v",
		width: 600,
		height: 450,
		autoplay: true,
		hd: true
	},
	{
		file: url+"2_low.f4v",
		hdpath: url+"2_high.f4v",
		width: 600,
		height: 338,
		autoplay: true,
		hd: true
	},
	{	yt: '9QCcjUN2WXM'},
	{	yt: 'HY9dK_32jsE'},
	{	yt: 'wlhJsx_8rJQ'},
	{   yt: 'F1xJwulCJww'}
];

google.setOnLoadCallback(function(){
	if ($('gallery')) embedgallery('gallery', '928','197', 5);
	if ($('gallery_f')) embedgallery('gallery_f', '928','297', 3);
	if ($('gallery_c')) embedgallery('gallery_c', '928','197', 3);
	if ($('gallery_s')) embedgallery('gallery_s', '928', '148', 3);
	$$('a.videolink').each(function(e){
		e.observe('click', vlinkclick);
	});
});

function embedgallery(id, w, h, s){
	var flashvars = {file: '/imagexml'+location.pathname, repeat: true, shuffle: false, rotatetime: s, showicons: false, shownavigation: false, transition: 'lines', width: w, height: h};
	var params = {};
	swfobject.embedSWF("/flash/imagerotator.swf", id, w, h, '9','', flashvars, params, {});
}

function vlinkclick(){
	if($('vp_home').visible()) closeplayer();
	
	var id=this.readAttribute('rel');
	if (id == null) id=1;
	var vf = Object.extend(flashvars, videos[id]);
	
	// show the right description if there is one
	var descs = $$('#vp_home .desc');
	if (descs.length > 1){
		descs.each(function(d){
		  var rel = d.readAttribute('rel');
		  if (rel == id){
		  	d.show();
		  }else{
		  	d.hide();
		  }
		});
	}

	if (videos[id]['file']){
		swfobject.embedSWF('/flash/hdplayer.swf', 'vp_home_container', videos[id]['width'], videos[id]['height']+30, '9','', flashvars, params, {});
		$('vp_home').setStyle({height: (videos[id]['height']+30)+'px'});
		$$('#vp_home .desc')[0].setStyle({width: (928-videos[id]['width'])+'px'});
	}else{
		swfobject.embedSWF('http://www.youtube.com/v/'+videos[id]['yt']+'&enablejsapi=1&playerapiid=ytplayer', 'vp_home_container', 425, 356, '9', '', flashvars, params, {id: 'ytplayerid'});
		$$('#vp_home .desc')[0].setStyle({width: '503px'});
		$('vp_home').setStyle({height: (356)+'px'});
	}
	
	this.writeAttribute('href', '#');
	if ($('gallery')) Effect.BlindUp('gallery');
	if ($('gallery_c')) Effect.BlindUp('gallery_c');
	if ($('vidroll')) Effect.BlindUp('vidroll');
	Effect.BlindDown('vp_home', { queue: 'end'});
}

function closeplayer(){
	if ($('vp_home')) Effect.BlindUp('vp_home');
	if ($('gallery')) Effect.BlindDown('gallery', {queue: 'end'});
	if ($('vidroll')) Effect.BlindDown('vidroll', {queue: 'end'});
	if ($('vp_home_container')) swfobject.removeSWF('vp_home_container');
	if ($('vp_home')) $('vp_home').insert('<div id="vp_home_container"> </div>');

	if ($('vp')) Effect.BlindUp('vp', {queue: 'end'});
	if ($('vp_container')) swfobject.removeSWF('vp_container');
	if ($('vp')) $('vp').innerHTML = '<div id="vp_container"> </div>';
}

function onvideostop(){
	closeplayer();
}

function onYouTubePlayerReady(id){
	var yt=$('ytplayerid');
	yt.addEventListener("onStateChange", "ytstatechange");
}

function ytstatechange(state){
	if (state == 0){
		closeplayer();
	}
}

function playvid(id){
	if($('vp').visible()) closeplayer();
	var vf = Object.extend(flashvars, videos[id]);
	if (videos[id]){
		if (videos[id]['file']){
			swfobject.embedSWF('/flash/hdplayer.swf', 'vp_container', videos[id]['width'], videos[id]['height']+30, '9','', flashvars, params, {});
			$('vp').setStyle({height: (videos[id]['height']+30)+'px'});
		}else{
			swfobject.embedSWF('http://www.youtube.com/v/'+videos[id]['yt']+'&enablejsapi=1&playerapiid=ytplayer', 'vp_container', 425, 356, '9', '', flashvars, params, {id: 'ytplayerid'});
			$('vp').setStyle({height: '356px'});
		}
		Effect.BlindDown('vp', {queue: 'end'});
	}
}
	
