var imageClicked='';
var imageStyle='';
var myIndex=1;
var myDiaporamaTimer;
var selectedTool = 'tool_pointer';
var logoDrag = null;
var	menuDrag = null;
var	smenuDrag = null;
var	windowDrag = null;
var	texteDrag = null;
var	imagesDrag = null;
var	thumbnailsDrag = null;
var	toolBoxDragTop = null;
var	toolBoxDragBottom = null;
var	pictomosIndexLink = null;
var	resizableArray = null;
var isSlideshowRunning = false;
var oTransition;
var myImageTitle;
var myImageYear;
var currentHeading='';

function displayContent(str){	
	if (str =='ALERT'){
		alert('Cette rubrique n\'a pas d\'image !');
	} else {
		myId = str.substring(9);
		myId = myId.substring(0,myId.indexOf('"'));
		header = '<div id="'+myId+'">';
		
		myReloadContent = str.substring(header.length);
		myReloadContent = myReloadContent.substring(0,myReloadContent.length-6);
		
		if ($(myId) == undefined){
			//document.body.innerHTML += str;
			$$('body')[0].insert({'bottom': str });
		} else {
			$(myId).innerHTML = myReloadContent;
			$(myId).show();
		}
		if(myId == 'thumbnails') {
			displayFirstImage();
		}			
		if (isAdminMode) {
			enableDrag( (selectedTool == 'tool_move') );
			enableResize( (selectedTool == 'tool_pointer') );
		}

	}
}


function displayBox(templateId, boxId, label){
	var myIndex = 0;	
	if (label == undefined) label = '';
	if (typeof boxId =='string' && boxId.indexOf('|') != -1){
		if($('smenu') != undefined){
			$('smenu').hide();
		}
	}
	if (templateId == 'images'){
		if ($('window') != undefined) $('window').style.display='none';
		if ($('texte') != undefined) $('texte').style.display='none';
		if ($('images') != undefined) $('images').style.display='';
		if ($('thumbnails') != undefined) $('thumbnails').style.display='';
	} else if (templateId == 'smenu'){
		if ($('texte') != undefined) $('texte').style.display='none';
		if ($('images') != undefined) $('images').style.display='none';
		if ($('thumbnails') != undefined) $('thumbnails').style.display='none';		
	}
	if (templateId == 'text' || templateId == 'menu_text'){
		if ($('window') != undefined) $('window').style.display='none';
		if ($('images') != undefined) $('images').style.display='none';
		if ($('thumbnails') != undefined) $('thumbnails').style.display='none';
		if ($('texte') != undefined) $('texte').style.display='';
		
	}
 	req = new GetRequest ({url:'/getsubmenu.php',func:displayContent});
	req.send(
		'box='+encodeURIComponent(boxId)
		+'&template='+encodeURIComponent(templateId)
		+'&userId='+encodeURIComponent(pictomosUserId)
	);
	if (templateId == 'images'){
	 	req = new GetRequest ({url:'/getsubmenu.php',func:displayContent});
		req.send(
			'box='+encodeURIComponent(boxId)
			+'&template=thumbnails'
			+'&userId='+encodeURIComponent(pictomosUserId)
		);
	}
	var url = document.location.href;
	if (url.indexOf('#') != -1) url = url.substring(0,url.indexOf('#'));
	document.location.href = url + '#' + templateId + '/' + boxId + '/' + label;
	currentHeading = boxId;
}

function displayPage(pictomosId, templateId, boxId, page){
	myIndex = 0;
 	req = new GetRequest ({url:'/getsubmenu.php',func:displayContent});
	req.send(
		'userId='+pictomosId
		+'&box='+boxId
		+'&template='+templateId
		+'&page='+page
	);
}

function executeJs(str){
	eval(str);	
}

function displayPicture(id,title, year, myCursor){
	myIndex = myCursor;
 	req = new GetRequest ({url:'/getsubmenu.php',func:executeJs});
	req.send(
		'id='+id
		+'&action=getDescription'
		+'&slideshowPicture='+$('slideshowPicture').visible()
	);
	if ($('thumb_'+imageClicked) != undefined){
		element = $('thumb_'+imageClicked);
		element.className = 'img_thumbnail';
	} else if ($('thumb_'+id) != undefined){
		imageClicked = id;
	}
	$('thumb_'+id).className = 'selectedThumbnail';
	if ($('imageTitle') != undefined) $('imageTitle').innerHTML = title;
	if ($('imageYear') != undefined) $('imageYear').innerHTML = year;
	
	if(!$('slideshowPicture').visible()) {
		if ($('pictureScreen') != undefined) $('pictureScreen').innerHTML = '<img src="/__pictomosUserFiles__/pictures/grand/'+id+'.jpg" />';		
	}
	imageClicked = id;
}

function playDiaporama(){
	var diaporamaDelay = pictomosSlideShowDelay;
	isSlideshowRunning = true;
	displayNextImage();
	
	var myBackground = $('playPauseButtons').getStyle('background-image');
	if (document.all) $('playPauseButtons').outerHTML = '<div id="playPauseButtons" onclick="pauseDiaporama()"></div>';
	else $('playPauseButtons').writeAttribute('onclick','pauseDiaporama()');	
	
	myDiaporamaTimer = setTimeout('playDiaporama('+diaporamaDelay+')',diaporamaDelay);
	myBackground = myBackground.replace(/play/, "pause");
	$('playPauseButtons').style.backgroundImage = myBackground;
	
	if (document.all) $('slideshowControlsPlay').outerHTML = '<div id="slideshowControlsPlay" onclick="pauseDiaporama()"></div>';
	else $('slideshowControlsPlay').writeAttribute('onclick','pauseDiaporama()');
	
	var myFSBackground = $('slideshowControlsPlay').getStyle('background-image');
	myFSBackground = myFSBackground.replace(/play/, "pause");
	$('slideshowControlsPlay').style.backgroundImage = myFSBackground;

}

function pauseDiaporama(){
	isSlideshowRunning = false;
	if (document.all) $('playPauseButtons').outerHTML = '<div id="playPauseButtons" onclick="playDiaporama()"></div>';
	else $('playPauseButtons').writeAttribute('onclick','playDiaporama()');	
	
	var myBackground = $('playPauseButtons').getStyle('background-image');
	var myOnClick = $('playPauseButtons').readAttribute('onClick');
	clearTimeout(myDiaporamaTimer);
	myBackground = myBackground.replace(/pause/, "play");
	$('playPauseButtons').style.backgroundImage = myBackground;
	
	if (document.all) $('slideshowControlsPlay').outerHTML = '<div id="slideshowControlsPlay" onclick="playDiaporama()"></div>';
	else $('slideshowControlsPlay').writeAttribute('onclick','playDiaporama()');
	var myFSBackground = $('slideshowControlsPlay').getStyle('background-image');
	myFSBackground = myFSBackground.replace(/pause/, "play");
	$('slideshowControlsPlay').style.backgroundImage = myFSBackground;
	
}

function toggleDiaporama(diaporamaDelay){
	if (isSlideshowRunning) pauseDiaporama();
	else playDiaporama(diaporamaDelay);
}


function displayPreviousImage(){
	if ($('link_'+(myIndex-1)) == undefined) {
		if ($('previousThumbnailsPage') != undefined){
			myHref = $('previousThumbnailsPage').getAttribute('onclick');
			eval(myHref);
			myIndex = 0;
		} else {
			pauseDiaporama();
		}	
	} else {
		myIndex--;
		myHref = $('link_'+myIndex).getAttribute('href');
		myHref = myHref.substring(11);
		eval(myHref);
	}
}



function displayNextImage(){	
	if ($('link_'+(myIndex+1)) == undefined) {
		if ($('nextThumbnailsPage') != undefined){
			myHref = $('nextThumbnailsPage').readAttribute('onclick');
			if (myHref != null)  eval(myHref);
			myIndex = 0;
		} else {
			pauseDiaporama();
		}	
	} else {
		myIndex++;
		myHref = $('link_'+myIndex).getAttribute('href');
		myHref = myHref.substring(11);
		eval(myHref);
	}
}

function displayFirstImage(){
	myIndex = 1;
	myHref = $('link_'+myIndex).getAttribute('href');
	myHref = myHref.substring(11);
	eval(myHref);
}


function selectTool(tool){
	enableResize(false);
	if ($('colorpicker') != undefined) {
		$('colorpicker').style.display = 'none';
	}
	displayTexture(false,'');
	displayLogo(false);
	if ($('Input_windowTitle') != undefined || $('Input_menuTitle') != undefined){
		alert('Vous devez valider le texte en cours d\'&eacute;dition avant de changer d\'outil');
	}

	else {
		$(selectedTool).style.backgroundImage = 'url(/admin/images/'+selectedTool+'_off.png)';
		$(tool).style.backgroundImage = 'url(/admin/images/'+tool+'_on.png)';
		
		if ($('background_modify').visible()) Effect.Fade('background_modify', { duration: 0.5 });
		if ($('textColorDiv').visible()) Effect.Fade('textColorDiv', { duration: 0.5 });

		enableDrag(false);
		
		switch(tool){
			case 'tool_pointer':
				document.body.style.cursor = 'default';
				enableResize(true);
			break;
			
			case 'tool_move':
				
				enableDrag(true);
			break;
			
			case 'tool_text':
				Effect.Appear('textColorDiv', { duration: 0.5 });			
				document.body.style.cursor = 'text';
			break;
			case 'tool_background':
				Effect.Appear('background_modify', { duration: 0.5 });				
			break;
		}
		selectedTool = tool;
	}
}

function saveMyPosition(element){

	positionTop = element.getStyle('top');
	positionLeft = element.getStyle('left');

 	req = new GetRequest ({url:'update_style.php',func:executeJs});
	req.send(
		'name='+element.getAttribute('id')
		+'&top='+positionTop
		+'&left='+positionLeft		
	);
	
	return true;
}

function enableResize(b){
	if (b){
		resizableArray = new Array();
		resizableArray.push(new Resizeable($('menu'),{onEnd: function(el) { saveMySize(el)}}));	
		if ($('texte')!= undefined) resizableArray.push(new Resizeable($('texte'),{onEnd: function(el) { saveMySize(el)}}));
		if ($('thumbnails')!= undefined) resizableArray.push(new Resizeable($('thumbnails'),{onEnd: function(el) { saveMySize(el)}}));
	} else {
		for(i=0 ; i<resizableArray.length ; i++){
			resizableArray[i].destroy();
		}
	}
}

function enableDrag(b){
	toolBoxDragTop = new Draggable('toolBox', {handle:'toolBoxDragZoneTop'});
	toolBoxDragBottom = new Draggable('toolBox', {handle:'toolBoxDragZoneBottom'});
	if (b){
		document.body.style.cursor = 'move';
		if ($('logo') != undefined) {
			pictomosIndexLink = $('logo').getAttribute('onclick');
			$('logo').setAttribute('onclick','');
			$('logo').style.cursor = 'move';
			logoDrag = new Draggable('logo', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		}
		if ($('menu') != undefined) menuDrag = new Draggable('menu', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		if ($('smenu') != undefined) smenuDrag = new Draggable('smenu', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		if ($('window') != undefined) windowDrag = new Draggable('window', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		if ($('texte') != undefined) texteDrag = new Draggable('texte', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		if ($('images') != undefined) imagesDrag = new Draggable('images', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
		if ($('thumbnails') != undefined) thumbnailsDrag = new Draggable('thumbnails', {onEnd:function(draggable, eventName){saveMyPosition(draggable.element);}});
	} else {
		document.body.style.cursor = 'default';
		if (logoDrag !=null) {
			logoDrag.destroy();
			$('logo').setAttribute('onclick',pictomosIndexLink);
			$('logo').style.cursor = 'pointer';
		}
		if (menuDrag !=null) menuDrag.destroy();
		if (smenuDrag !=null) smenuDrag.destroy();
		if (windowDrag !=null) windowDrag.destroy();
		if (texteDrag !=null) texteDrag.destroy();
		if (imagesDrag !=null) imagesDrag.destroy();
		if (thumbnailsDrag !=null) thumbnailsDrag.destroy();
	}
}

function enableLink(b){
	
}

function displayMessage(str){
	
}
/*
function toggleMenu(){
	myElement = window.parent.document.getElementById('header_menu');
	if (myElement.style.display == ''){
		$('tool_fullscreen').setAttribute('src','/admin/images/tool_fullscreen_on.png');
		myElement.style.display = 'none';
	} else {
		$('tool_fullscreen').setAttribute('src','/admin/images/tool_fullscreen_off.png');
		myElement.style.display = '';
	}
}


--ici bas version de an3---*/
function toggleMenu(){
	myElement = window.parent.document.getElementById('header_menu');
	if (myElement.style.display == ''){
		$('tool_fullscreen').style.backgroundImage = 'url(/admin/images/tool_fullscreen_on.png)';
		myElement.style.display = 'none';
	} else {
		$('tool_fullscreen').style.backgroundImage = 'url(/admin/images/tool_fullscreen_off.png)';
		myElement.style.display = '';
	}
}

function updateText(id, text){
 	req = new GetRequest ({url:'ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=updateText'
		+'&pictomosId='+id
		+'&pictomosText='+text
	);	
}

function updateStyle(pictomosId, cssName, cssChild, cssKey, cssValue) {
	
    myEditableBoxes = document.getElementsByClassName(cssName+'EditableColor');
    for (i=0 ; i<myEditableBoxes.length ; i++){       
        myElement = myEditableBoxes[i];
        myElement.setStyle(cssKey,cssValue);
        switch (cssKey){
        	case 'color' :
        		myElement.style.color = cssValue;
        	break;
        	case 'font-size':
        		myElement.style.fontSize = cssValue;
        	break;
        }
    }
	
 	req = new GetRequest ({url:'ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=updateStyle'
		+'&pictomosId='+encodeURIComponent(pictomosId)
		+'&cssName='+encodeURIComponent(cssName)
		+'&cssChild='+encodeURIComponent(cssChild)
		+'&cssKey='+encodeURIComponent(cssKey)
		+'&cssValue='+encodeURIComponent(cssValue)
	);	
}

function submitenter(myfield,e,text) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
		myName = myfield.getAttribute('name');
		updateText(myName, myfield.value);
		$(myName).innerHTML = myfield.value;
		$(myName).setAttribute('onClick',"$('"+myName+"').setAttribute('onClick','');$('"+myName+"').innerHTML='<input id=\"Input_"+myName+"\" name=\""+myName+"\" onKeyPress=\"return submitenter(this,event)\" style=\"width:100%;border:0px\" type=\"text\" value=\"'+$('"+myName+"').innerHTML+'\"/>';$('Input_"+myName+"').focus();");
		return false;
	}
	else
	   return true;
}

function submitEnterV2(e,callback, cancelCallBack){
	var keycode;
	var charcode;
	if (window.event) {
		keycode = window.event.keyCode;
		charcode = window.event.charCode;
	} else if (e) {
		keycode = e.keyCode;
		charcode = e.charCode;
	}
	else return true;
	if (keycode==0){
		keycode = charcode;
	}
	if (keycode == 13) {
		if (callback!='') {
			eval(callback);
			return false;
		} else {
			return true;
		}
		
	} else if(keycode == 27){
		eval(cancelCallBack);
		return false;
	} else {
		return true;
	}
}

function updateBackgroundImage(pictomosId, textureFile){
 	req = new GetRequest ({url:'ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=updateBackGroundImage'
		+'&pictomosId='+pictomosId
		+'&textureFile='+textureFile
	);	
}

function saveLayout(pictomosId){
 	if (confirm(getTranslation(LANG,'PublicationConfirmMessage'))){
 		req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
		req.send(
			'pictomosAction=saveLayout'
			+'&pictomosId='+pictomosId
		);	
	}
}

function cancelLayout(pictomosId, pictomosLogin){
	if (confirm(getTranslation(LANG,'PublicationCancelConfirmMessage'))){
	 	req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
		req.send(
			'pictomosAction=cancelLayout'
			+'&pictomosId='+pictomosId
			+'&pictomosLogin='+pictomosLogin
		);	
	}
}

function changecss(theClass,element,value) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	} else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				//alert('style : '+document.styleSheets[S][cssRules][R].selectorText+', => '+value);
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}	
}

function displayLogo(b){
	if ($('background_logo') != undefined){
		if (b){
			$('background_logo').appear();
		} else {
			$('background_logo').fade();
		}
	}
}

function displayTexture(b,type){
	if ($('background_texture') != undefined){
		if (b){
			if (type == 'tomos') {
				$('background_texture_title').innerHTML = 'TOMOS <span class="text_fr">Fond - </span><span class="text_en">Background</span>';
			} else if (type == 'body')  {
				$('background_texture_title').innerHTML = 'Image de fond du site';
			}
			$('background_texture').appear();
		} else {
			$('background_texture').fade();
		}
	}
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
	
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	if ($('help_panel')!=null) {
		$('help_panel').style.top = (tempY+25)+'px';
		$('help_panel').style.left = (tempX+10)+'px';
	}
	return true;
}

function displayPanel(index){
	$('help_panel').innerHTML = tipsArray[index];
	$('help_panel').style.display = '';
}

function hidePanel(){
	$('help_panel').style.display = 'none';
	$('help_panel').innerHTML = '';
}

function displayCssEditor(){
	req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=displayCssEditor'
	);
}

function savePageCssContent(){
	
	req = new PostRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=savePageCssContent'
		+'&cssContent='+encodeURIComponent($F('cssContent'))
	);
}

function toggleSlide(divId){
	
	if ($(divId).visible()){
		Effect.BlindUp(divId);
	} else {
		Effect.BlindDown(divId);
	}
	return false;
}

function toggleFade(divId){
	if (divId){
		if ($(divId).visible()){
			$(divId).fade();
		} else {
			$(divId).appear();
		}
	}
}

function checkAllCheckbox(checkBoxClass){
	var elementArray = document.getElementsByClassName(checkBoxClass);
	var isChecked = ( $('checkAll').checked == true );
	for(i=0 ; i<elementArray.length ; i++){
		elementArray[i].checked = isChecked;
	}
}

function deleteSelection(){
	var elementArray = document.getElementsByClassName('pictureCheckBoxClass');
	var hasSelection = false;
	for(i=0 ; i<elementArray.length ; i++){
		if (elementArray[i].checked){
			hasSelection = true;
		}
	}
	if(!hasSelection){
		alert('Veuillez sélectionner au moins une image !');
	} else {
		if( confirm('Voulez-vous vraiment effacer la sélection ?/\nDo you really want to delete the selection ?')){
			$('smartlist_action').value = 'delete_selection';
			$('pictureListForm').submit();
		}
	}
}

function cancelForm(formId, fckId, divId){
	$(formId).reset();
	if (fckId!='') FCKeditorAPI.__Instances[fckId].SetHTML('');
	toggleSlide(divId);
}

function checkImage(formId,inputFileId){
	var myValue = $F(inputFileId);

	if (myValue == ''){
		alert('Merci de choisir une image /\n Please choose an image');
	} else if(!eval('myValue.match (/^.+jpg$/i)') && !eval('myValue.match (/^.+png$/i)') && !eval('myValue.match (/^.+gif$/i)')){
		alert('Veuillez choisir un fichier image (jpg, png, gif)\nPlease choose a picture file (jpg, png, gif)');
	} else {
		$(formId).submit();
	} 
}


// login
function validateFormFields(formId){
	var formFieldElements = $(formId).getElementsBySelector(
		'input[type="text"]'
		, 'input[type="checkbox"]'
		, 'input[type="radio"]'
		, 'input[type="file"]'
		, 'input[type="password"]'
		, 'select'
		, 'textarea'
	);
	var myLabel = '';
	var myOutput = '';
	for (i=0 ; i<formFieldElements.length ; i++){       
		myElement = formFieldElements[i];
		if( myElement.readAttribute('mandatory')=='true' && $F(myElement)=='' ){
			if (myElement.readAttribute('label')!=null) {
				myLabel = myElement.readAttribute('label');
			} else if (myElement.readAttribute('name')!=null) {
				myLabel = myElement.readAttribute('name');
			} else if (myElement.readAttribute('id')!=null) {
				myLabel = myElement.readAttribute('id');
			}
			myOutput += ' - '+ myLabel +"\n";
		}
	}	
	return myOutput;
}

function loginToPictomos(){
	var validationMessage = validateFormFields('myLoginForm');
	$('formErrorMessageDiv').innerHTML = '&nbsp;';
	if(validationMessage != ''){
		alert('Les champs suivants sont requis /\nThe following informations are needed:\n\n'+validationMessage);
	} else {
		$('myLoginForm').submit();
	}
}
function getTranslation(lang,word){
	var lang;
	var word;
	if (wordTranslation[word] != undefined){
		return wordTranslation[word];
	} else {
		alert('Pas de traduction');
	}
}

function sendABug(){
 	var flashVersion = GetSwfVer();
	req = new PostRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=sendABug'
		+'&reportABugTxt='+encodeURIComponent($F('reportABugTxt'))
		+'&flashVersion='+encodeURIComponent(flashVersion)
	);
	toggleFade('reportABugDiv');
}

function displayTutorial(templateId){
 	req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=displayTutorial'
		+'&templateId='+encodeURIComponent(templateId)
	);
}

function hideTutorial(){
	$('popupTutorial').fade();
	$('disabledDiv').hide();
}

function rotate(id,orientation){
 	if(orientation=='left'){
 		$('rotateValue').value = (parseInt($F('rotateValue')) - 90);
 	} else {
 		$('rotateValue').value = (parseInt($F('rotateValue'))+ 90);
 	}
	req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=rotate'
		+'&id='+encodeURIComponent(id)
		+'&orientation='+encodeURIComponent(orientation)
	);
}


function saveMySize(element){
	
	document.body.style.cursor = 'default';
	var tomosWidth = element.getWidth() ;
	var tomosHeight = element.getHeight();
	var tomosTop = element.getStyle('top');
	var tomosLeft = element.getStyle('left');
	var myRequest = '';
 	req = new GetRequest ({url:'update_style.php',func:executeJs});
 	myRequest = 
	req.send(
		'&name='+element.readAttribute('id')
		+'&width='+tomosWidth
		+'&height='+tomosHeight
		+'&top='+tomosTop
		+'&left='+tomosLeft
		+'&contentHeight='+$(element).down('.content').getHeight()
		+'&contentWidth='+$(element).down('.content').getWidth()
		+'&box='+encodeURIComponent(currentHeading)
	);

	return true;
}

function displayOptions(){
	$('disabledDiv').show();
 	req = new GetRequest ({url:'/ajax_request.php',func:executeJs});
	req.send(
		'pictomosAction=displayOptions'
	);
}
function cancelOptions(){
	$('OptionsDiv').fade();
	$('disabledDiv').fade();
}
function cancelPopup(){
	$('disabledDiv').fade();
	if($('OptionsDiv').visible()) $('OptionsDiv').fade();
	if($('popupTutorial').visible()) $('popupTutorial').fade();
}
function saveOptions(){
 	$('pictomosOptionsForm').submit();
}
function getTotalHeight() {
	// firefox is ok
	var height = document.documentElement.scrollHeight;
	
	// now IE 7 + Opera with "min window"
	if(document.documentElement.clientHeight > height ) {
		height  = document.documentElement.clientHeight;
	}
	// last for safari
	if(document.body.scrollHeight > height) {
		height = document.body.scrollHeight;
	}
	return height;
}

function getTotalWidth() {
	// firefox is ok
	var width = document.documentElement.scrollWidth;
	
	// now IE 7 + Opera with "min window"
	if(document.documentElement.clientWidth > width ) {
		width  = document.documentElement.clientWidth;
	}
	// last for safari
	if(document.body.scrollWidth > width) {
		width = document.body.scrollWidth;
	}
	return width;
}


function showFullscreenSlideshow(){
	var mySrc = $('pictureScreen').down('img').readAttribute('src');
	mySrc = mySrc.replace(/grand/, "fullscreen");
	myTitle = $('imageTitle').innerHTML;
	myYear = $('imageYear').innerHTML;
	showFullscreenPicture(mySrc,myTitle,myYear);
}

function showFullscreenPicture(mySrc,myTitle,myYear){
	var imgPreloader = new Image();
	var myImageWidth, myImageHeight;
	myImageTitle = myTitle;
	myImageYear = myYear;
	
	imgPreloader.onload = (function(){
		
		myImageWidth = imgPreloader.width;
		myImageHeight = imgPreloader.height;	

	 	if (!$('slideshowOverlay').visible()) {
	 		//$('slideshowOverlay').setStyle({ width: getTotalWidth() + 'px', height: getTotalHeight() + 'px' }); 
			if ($('slideshowOverlay').getStyle('background-color')=='rgb(0, 0, 0)' || $('slideshowOverlay').getStyle('background-color')=='#000' || $('slideshowOverlay').getStyle('background-color')=='#000000') {
				new Effect.Appear('slideshowOverlay', { duration: 0.2, from: 0.0, to:0.9 });
			} else {
				new Effect.Appear('slideshowOverlay', { duration: 0.2, from: 0.0, to:0.97 });
			}
	 		$('slideshowPicture').setStyle({ top: '50%', left: '50%', width: myImageWidth+'px', height: myImageHeight+'px', marginTop: '-'+(myImageHeight/2)+'px', marginLeft: '-'+(myImageWidth/2)+'px' }); 
	 		$('slideshowPicture').show();
	 		oTransition = new Transition( 'slideshowPicture', mySrc);
			if ($('slideshowPictureComment') != undefined) $('slideshowPictureComment').innerHTML = $('imageComment').innerHTML;		
	 		$('slideshowControls').show();
	 	} else {
	 		oTransition.loadAjaxImage(mySrc);
	 	}		
		if ($('slideshowPictureTitle') != undefined) $('slideshowPictureTitle').innerHTML = $('imageTitle').innerHTML;
		if ($('slideshowPictureYear') != undefined) $('slideshowPictureYear').innerHTML = $('imageYear').innerHTML;		
	}).bind(this);
	imgPreloader.src = mySrc;
}
function closeFullscreenSlideshow(isAdmin) {
	var mySrc = $('slideshowPicture').down('img').readAttribute('src');	
	if(isAdmin) {
		mySrc = mySrc.replace(/fullscreen/, "grand");
		$('pictureScreen').innerHTML = '<img src="'+mySrc+'" />';
	}
	$('slideshowPicture').hide();
	$('slideshowControls').hide();
	new Effect.Fade('slideshowOverlay');
	if(!isAdmin) {
		var myUrl = document.location.href;
		var reg=/^(http:\/\/[a-z0-9\-\._]+\/)([0-9]+)(s|h)([0-9]*)(\/play\/|\/fullscreen\/)*(.*)$/gi;
		var regSrc=/^(.*)\/([0-9]+)\.jpg$/gi;
		var myId = mySrc.replace(regSrc, "$2");
		myUrl = myUrl.replace(reg, "$1$2$3"+myId);
		document.location.href = myUrl;
	}
}

function changeSlideshowBackground(){
	if ($('slideshowOverlay').getStyle('background-color')=='rgb(0, 0, 0)' || $('slideshowOverlay').getStyle('background-color')=='#000' || $('slideshowOverlay').getStyle('background-color')=='#000000') {
		$('slideshowOverlay').morph('background-color:#FFF;filter: alpha(opacity=97);opacity: 0.97;', {duration:1});
	} else {
		$('slideshowOverlay').morph('background-color:#000;filter: alpha(opacity=90);opacity: 0.9;', {duration:1});
	}
}
//+++++++++
var tipsArray = Array();
tipsArray[0] = '<img src="/admin/images/ic_question.png" align="right"> <div style="font-family: hevetica, arial;color:#036; padding-bottom:15px;"><img src="/admin/images/ic_fr.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Titre</span><br/>Entrez ici le titre de l\'oeuvre. Il sera automatiquement écrit en gras et placé au bas de votre oeuvre.</div><div style="font-family: hevetica, arial;color:#cff;"><img src="/admin/images/ic_en.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Title</span><br/>Write the title of your piece here and it will automatically be written in bold and placed below your work.</div>';

tipsArray[1] = '<img src="/admin/images/ic_question.png" align="right"> <div style="font-family: hevetica, arial;color:#036; padding-bottom:15px;"><img src="/admin/images/ic_fr.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Année</span><br/>Entrez ici l\'année dans laquelle a été réalisée l\'oeuvre. Ce chiffre sera placé sous le titre.</div><div style="font-family: hevetica, arial;color:#cff; padding-bottom:15px;"><img src="/admin/images/ic_en.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Year</span><br/>Write the year that your work was taken here and it will be placed below the title.</div>';

tipsArray[2] = '<img src="/admin/images/ic_question.png" align="right"> <div style="font-family: hevetica, arial;color:#036; padding-bottom:15px;"><img src="/admin/images/ic_fr.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Description</span><br/>Entrez ici une description (détaillée ou non) de votre oeuvre, les conditions de sa réalisation, ou tout autre commentaire utile.</div><div style="font-family: hevetica, arial;color:#cff; padding-bottom:15px;"><img src="/admin/images/ic_en.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Description</span><br/>Write a description (detailed or basic)  of your work, the technical specifications, or any other useful commentary here.</div>';

tipsArray[3] = '<img src="/admin/images/ic_question.png" align="right"> <div style="font-family: hevetica, arial;color:#036; padding-bottom:15px;"><img src="/admin/images/ic_fr.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Mots clés</span><br/>Entrez ici le(s) mot(s) que vous souhaitez associer à votre oeuvre. Ces mots serviront au référencement de l\'image dans les moteurs de recherche sur Internet.</div><div style="font-family: hevetica, arial;color:#cff; padding-bottom:15px;"><img src="/admin/images/ic_en.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Keywords</span><br/>Write key words that you would like to associate with your work.  These words will be used as Internet engine search strings.</div>';

tipsArray[4] = '<img src="/admin/images/ic_question.png" align="right"> <div style="font-family: hevetica, arial;color:#036; padding-bottom:15px;"><img src="/admin/images/ic_fr.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Mes Rubriques</span><br/>Associez votre oeuvre à un MENU ou un SOUS-MENU. Notez que si vous cochez un menu ET un sous-menu, l\'image illustrera le tomos sous-menus.</div><div style="font-family: hevetica, arial;color:#cff; padding-bottom:15px;"><img src="/admin/images/ic_en.gif" style="margin-right:5px;" align="left"><span style=" font-size:15px; ">Rubrics</span><br/>Associate your work to a MENU or a SUB-MENU.  Note that if you check a menu AND a sub-menu, the illustrated image will be in the tomos sub-menu.</div>';
//------------
function affecteToCategorie(form,thisObj){
    var checkedsTab =  $$('input.pictureCheckBoxClass').find(function(e) {return e.checked;}); 
	if(!checkedsTab){
		alert(getTranslation(LANG,'PleaseSelectOneOrMorePictures'));
		$(thisObj).selectedIndex = 0;
		return false;
	}
	
	var msg;
	var valTab = $F(thisObj).split('|');
	var textSelected = $(thisObj).options[$(thisObj).selectedIndex].text;
	
	if(valTab[0] && valTab[0].indexOf('add') != -1)
		msg = getTranslation(LANG,'DoYouReallyWantoToAddThesePicturesIntoTheGroup')+':\n'+textSelected+' ?';
	else if(valTab[0] && valTab[0].indexOf('delete') != -1)
		msg = getTranslation(LANG,'DoYouReallyWantoToFromThesePicturesFromTheGroup')+':\n'+textSelected+' ?';
		
	if(msg && confirm(msg)){
		$(form).action= "form.php";
		$(form).insert('<input type="hidden" name="affectTo" value="'+$F(thisObj)+'" />');
		$(form).insert('<input type="hidden" value="pictomos_oeuvre_rubrique_link_affecte" name="table_name"/>');
		$(form).submit();
	}else
		$(thisObj).selectedIndex = 0;
	return false;
}