var url = "http://c0119391.cdn.cloudfiles.rackspacecloud.com/";
var flashvars = {
	prerollvars: false,
	midrollvars: false,
	postrollvars: false,
	zoomcontrol: false,
	playlist: false,
	http: true,
	hd: 0,
	width: 600,
	height: 368,
	autoplay: 1,
	fs: 1
};
var params = {
	allowfullscreen: true,
	allowscriptaccess: 'always',
	wmode: 'transparent'
};
var videos = [
	{
		file: url+"ltd_1.f4v",
		width: 600,
		height: 360,
		autoplay: true,
		hd: false
	}
];

google.setOnLoadCallback(function(){
	if ($('gallery')) embedgallery('gallery', '928','197', 5);
	$$('a.productlink').each(function(e){
		e.observe('click', prodlinkclick);
	});
	$$('a.envlink').each(function(e){
		e.observe('click', envlinkclick);
	});
	$$('a.vidlink').each(function(e){
		e.observe('click', vidlinkclick);
	});
});

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 prodlinkclick(){
	if($('prod_home').visible()){
		closegallery();
	}else{
		this.writeAttribute('href', '#');
		if ($('gallery') && $('gallery').visible()) Effect.BlindUp('gallery');
		if ($('envpol_home') && $('envpol_home').visible()) Effect.BlindUp('envpol_home');
		if ($('vid_home') && $('vid_home').visible()) Effect.BlindUp('vid_home');
		Effect.BlindDown('prod_home', { queue: 'end'});
	}
}

function envlinkclick(){
	if ($('envpol_home').visible()){
		closegallery();
	}else{
		this.writeAttribute('href', '#');
		if ($('gallery') && $('gallery').visible()) Effect.BlindUp('gallery');
		if ($('prod_home') && $('prod_home').visible()) Effect.BlindUp('prod_home');
		if ($('vid_home') && $('vid_home').visible()) Effect.BlindUp('vid_home');
		Effect.BlindDown('envpol_home', { queue: 'end'});
	}
}

function closegallery(){
	if ($('prod_home') && $('prod_home').visible()) Effect.BlindUp('prod_home');
	if ($('envpol_home') && $('envpol_home').visible()) Effect.BlindUp('envpol_home');
	if ($('vid_home') && $('vid_home').visible()) Effect.BlindUp('vid_home');
	if ($('gallery')) Effect.BlindDown('gallery', {queue: 'end'});
}

function vidlinkclick(){
	if($('vid_home').visible()){
		closevideo();
	}else{
		if ($('gallery') && $('gallery').visible()) Effect.BlindUp('gallery');
		if ($('prod_home') && $('prod_home').visible()) Effect.BlindUp('prod_home');
		if ($('envpol_home') && $('envpol_home').visible()) Effect.BlindUp('envpol_home');
		var id=this.readAttribute('rel');
		if (id == null) id=0;
		var vf = Object.extend(flashvars, videos[id]);
	
		if (videos[id]['file']){
			var height = videos[id]['height']+30;
			swfobject.embedSWF('/flash/hdplayer.swf', 'vid_container', videos[id]['width'], height, '9','', flashvars, params, {});
			
		}else{
			var height = 356;
			swfobject.embedSWF('http://www.youtube.com/v/'+videos[id]['yt']+'&enablejsapi=1&playerapiid=ytplayer', 'vid_container', 425, height, '9', '', flashvars, params, {id: 'ytplayerid'});
		}
		this.writeAttribute('href', '#');
		$('vid_home').setStyle({height: height+'px'});
		Effect.BlindDown('vid_home', { queue: 'end'});
	}
}

function closevideo(){
	if ($('vid_home')) Effect.BlindUp('vid_home');
	if ($('vid_container')) swfobject.removeSWF('vid_container');
	if ($('vid_home')) $('vid_home').insert('<div id="vid_container"> </div>');
}

function onvideostop(){
	closeplayer();
}

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

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

