﻿
var _DEV = 0; // disables slideshow
var project = null;

function loadSlide()
{
	init_state_mgr();
	project = new Project();
}

function loadProject(pid, url, name, type)
{
	project.loadProjectSummary(pid);
}
function confirmAndGo(url)
{
	if(confirm('Etes vous sur?')) window.location = url;
	else return;
}

function hide_text_edition()
{
	obj = _$('texts_table');
	obj.style.display = "none";
}

function show_text_edition()
{
	obj = _$('texts_table');
	obj.style.display = "";
}

//open and show image for lightshow form slideshow
function oifl(obj)
{
	if(obj.childNodes[1]) return obj.childNodes[1].src;
	if(obj.childNodes[0]) return obj.childNodes[0].src;
	return null; // for the eclipse debugger to shut up
}

function display_floor(floor)
{
	if(document.getElementById('floor_' + floor).style.display == 'none') document.getElementById('floor_' + floor).style.display = '';
	else document.getElementById('floor_' + floor).style.display = 'none';
}

function display_document(documentName)
{
	if(document.getElementById('document_' + documentName).style.display == 'none')
	{
		document.getElementById('document_' + documentName).style.display = ''
		document.getElementById('document_' + documentName).style.backgroundColor = "#444";
	}
	else
	{
		document.getElementById('document_' + documentName).style.display = 'none'
		document.getElementById('document_' + documentName).style.backgroundColor = "";
	}
}

function projects_show(id)
{
	obj = _$(id);
	if(obj.style.display == "") obj.style.display='none';
	else obj.style.display = '';
}

function openUnit(uid)
{
	window.location = "?page=unit&uid=" + uid;
}

function openEditUnit(uid)
{
	obj = _$('edit_unit_'+uid);
	if(obj.style.display == "") obj.style.display = 'none';
	else obj.style.display = '';
}

function saveTextsForm()
{
	form = _$('texts_form');
	form.text_fr.value =  escape(WYSIWYG.getEditorWindow('text_editor_fr').document.body.innerHTML);
	form.text_en.value =  escape(WYSIWYG.getEditorWindow('text_editor_en').document.body.innerHTML);
	form.submit();
}

function translate(text, fromLang, toLang, container)
{
	if(confirm("Voulez vous vraiment traduire de " + fromLang + " à " + toLang))
	{
		length = text.length;
		
		end = 0;
		container.innerHTML = '';
		while(end < length)
		{
			//get part of text
			charSub = text.substring((end + 400), (end + 450));
			endCharPos = charSub.search(' ') * 1 + end + 400;
			
			part = text.substring(end, endCharPos);
			//alert(part);
			end = endCharPos;
			google.language.translate(part, fromLang, toLang, function(result) {
				if(!result.error) container.innerHTML = container.innerHTML+' '+result.translation;
				else alert('Une erreur c\'est produite durant la traduction automatisée');
			});
		}
	}
	else return;
}

function backPicLeft(picName)
{
	document.getElementById('intro_left').style.backgroundImage = 'url(images/home/' + picName + ')';
}

function backPicRight(picName)
{
	document.getElementById('intro_right').style.backgroundImage = 'url(images/home/' + picName + ')';
}

function restorePicLeft()
{
	document.getElementById('intro_left').style.backgroundImage = 'url(images/index/home_intro_buttons_middle.gif)';
}
function restorePicRight()
{
	document.getElementById('intro_right').style.backgroundImage = 'url(images/index/home_intro_buttons_middle.gif)';
}

function changeLang(lang)
{
	var loc = window.location.toString();

	var hash = '';
	var hash_start = loc.indexOf('#');
	if(hash_start != -1)
	{
		hash = loc.substr(hash_start);
		loc = loc.substr(0, hash_start);
	}

	var gets = '';
	var gets_start = loc.indexOf('?');
	if(gets_start != -1)
	{
		var gets_array = loc.substr(gets_start + 1).split('&');
		loc = loc.substr(0, gets_start);
		var lang_found = false;

		for(var i = 0; i < gets_array.length; i++)
		{
			gets_array[i] = gets_array[i].split('=');

			if(gets_array[i][0] == 'l')
			{
				lang_found = true;
				gets_array[i][1] = lang;
			}
		}

		if(!lang_found) gets_array.push(new Array('l', lang));

		gets = '?';
		for(var i = 0; i < gets_array.length; i++) gets += (i > 0 ? '&' : '') + gets_array[i][0] + '=' + gets_array[i][1];
	}
	else gets = '?l=' + lang;

	window.location = loc + gets + hash;
}

/*function makeKenburns(data, showId)
{
	var show = new Slideshow.KenBurns(showId, data, { zoom: 0,captions: true, controller: false,resize:'length', delay: 12000, duration: 2000, height: 400, linked: false, hu: 'images/projects/websize/', width: 398 });
	return show;
}*/
