// General JavaScript for Finding Edo.
// (C) Copyright 2008 Finding Edo/ScifienceNetworks. All rights reserved.

// Functions for dealing with cookies.
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0;i < ca; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// Resize layers
function resizeLayers() {
	var containerheight = $('container').getHeight();
	containerheight = containerheight - 80;
	$('readmore').setStyle({height: containerheight + 'px'});
	$('about').setStyle({height: containerheight + 'px'});
}

// Embed Flash video
function embedVideo(filename) {
	jQuery("#video").flashembed({
					src:'flash/FlowPlayerDark.swf',
					wmode:'transparent',
					bgcolor: '#000000',
					width:640,
					height:480,
					version:[9,0,115,0],
					expressInstall:'flash/expressinstall.swf'
				},
				{config: {
					autoPlay: false,
					videoFile: filename,
					streamingServer: 'fms',
					streamingServerURL: 'rtmp://67.23.13.164/vod',
					useNativeFullScreen: true,
					useHwScaling: true,
					showStopButton: true,
					controlsOverVideo: 'ease',
					controlBarGloss: 'high',
					controlBarBackgroundColor: 000000,
					loop: false,
					showMenu: false,
					protected: true,
					initialScale: 'fit',
					autoRewind: true
				}}
				)
}

function embedVideoJp(filename) {
	jQuery("#video").flashembed({
					src:'flash/FlowPlayerDark.swf',
					wmode:'transparent',
					bgcolor: '#000000',
					width:640,
					height:480,
					version:[9,0,115,0],
					expressInstall:'flash/expressinstall.swf'
				},
				{config: {
					autoPlay: false,
					videoFile: filename,
					streamingServer: 'fms',
					streamingServerURL: 'rtmp://67.23.13.164/vod',
					useNativeFullScreen: true,
					useHwScaling: true,
					showStopButton: true,
					controlsOverVideo: 'ease',
					controlBarGloss: 'high',
					controlBarBackgroundColor: 000000,
					loop: false,
					showMenu: false,
					protected: true,
					initialScale: 'fit',
					autoRewind: true
				}}
				)
}

// Set user connection speed.
function setVideoQuality(selection) {
	createCookie('vidquality',selection,365);
	Effect.Fade('chooser');
	setTimeout('window.location.reload()',1000);
}

// Set user server choice.
function setServer(selection) {
	createCookie('serverloc',selection,365);
	Effect.Fade('chooser');
	setTimeout('window.location.reload()',1000);
}

// Change the video quality set by the user.
function changeQuality() {
	new Ajax.Updater('video','/templates/quality_chooser.php', {method:'get'});
}

function changeServer() {
	new Ajax.Updater('video','/templates/server_chooser.php', {method:'get'});
}

// Show readmore div
function showReadMore() {
	var player = jQuery("#video > :first")[0];
	player.Pause();
	new Effect.BlindDown('readmore');
}

// Show about div
function showAbout() {
	var player = jQuery("#video > :first")[0];
	player.Pause();
	new Ajax.Updater('about','/templates/about.php', {method:'get'});
	new Effect.BlindDown('about');
}