// Spray Front - Javascript functions
var displayWindow = function(theURL,winName,width,height,features){
	var window_width = width;
	var window_height = height;
	var newfeatures = features;
	var window_top = (screen.height-window_height)/2;
	var window_left = (screen.width-window_width)/2;
	var newWindow = window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');
	newWindow.focus();
}

/*
 * MultiBox
 * mode: mb | advanced
 * 
 */
var initBoxImage = function(){ var box = new multiBox('mb'); window.addEvent('keydown', function(e){ if (e.key == 'esc' && box.opened) box.close(); }); }
var openBox = function(no_overlay,mode,type,url,title,desc,full,w,h){
	if ($$('a.mb').length>0 && $$('div.MultiBoxContainer').length>0) $$('div.MultiBoxContainer')[0].destroy();
	var showControls = (title!='') ? true : false; var fixedTop = (full && showControls) ? 20 : false;
	if (no_overlay){
		var mbBox = new multiBox(mode, { useOverlay: false, descClassName: 'advancedDesc', showControls: showControls, fixedTop: fixedTop, fullScreen: full, _onClose: closeBoxTT });
	}else{
		var mbBox = new multiBox(mode, { overlay: new overlay({ opacity: 0.7, zIndex: 2 }), descClassName: 'advancedDesc', showControls: showControls, fixedTop: fixedTop, fullScreen: full, _onClose: closeBoxTT });
	};
	mbBox.create({ url: url, type: type, title: title, description: desc, width: w, height: h });
	window.addEvent('keydown', function(e){ if (e.key == 'esc' && mbBox.opened){ mbBox.close(); closeBoxTT(); } });
}
var closeBoxTT = function(){
	setTimeout(function(){
		if ($('OverlayContainer')) $('OverlayContainer').destroy(); if ($$('div.MultiBoxContainer').length>0) $$('div.MultiBoxContainer')[0].destroy();
		window.removeEvent('keydown', function(e){ if (e.key == 'esc' && mbBox.opened){ mbBox.close(); closeBoxTT(); } }); 
		if ($$('a.mb').length>0) initBoxImage();
	}, 1000);
}
var showZoomButton = function(el){
	var zoomIcon = new Element('div', { 'id': 'zoomIcon'}).addClass('zoomButton').inject($(document.body));
	zoomIcon.setStyles({
		'position': 'absolute', 'width': '21px', 'height': '22px', 'background': 'url(/img/gui/boutons/loupe.png) no-repeat', 'zIndex': '1000',
		'-webkit-border-radius': '2px', '-moz-border-radius': '2px', 'padding': '2px', 'border': '1px solid #222', 'background-color': '#111', 'opacity': '0.8',
		'background-position': '2px 2px'
	});
	zoomIcon.setStyles({ 'top': (el.getCoordinates().top+5)+'px', 'left': (el.getCoordinates().left+el.getCoordinates().width-32)+'px' });
	el.setStyle('cursor','pointer');
}
var hideZoomButton = function(el){ if ($('zoomIcon')) $('zoomIcon').destroy(); }
