var fullSize;


function SizeDesktop(){
	
	if(fullSize == 1){
		$('content').setStyle({
			'height': '98%'
		});
	}else{	
		$('content').setStyle({
			'height':getHeight()-160+'px'
		});
	}
	
}


function maximizeDesktop(){
	  //setWidth(0);
	  $('header').switchOff();
	  $('footer').switchOff();	  
	  $('maxbutton').switchOff();
	  $('content-bg-top').switchOff();
	  $('content-bg-bottom').switchOff();
	  //setWidth(0);
	  $('normbutton').appear();	  
	  //$('content').setStyle({'backgroundImage':'none'});
	  //'height': getHeight()-25+'px',	
	  $('content').setStyle({
		  'position' : 'fixed',
		  'top' : '0px',
		  'left' : '20px',
		  'bottom' : '0px',
		  'right' : '0px',
		  'width': getWidth()-25+'px',
		  'height': getHeight()+'px',	  
		  'margin':'0px',
		  'padding' : '0px',
		  'backgroundImage' : 'url("./assets/images/bg.png")',
		  'backgroundRepeat':'repeat'
			  
	});
	  $('content').setOpacity(100);
	  

	 /* $('photosInContent_ShowPhoto').setStyle({
			'height':getHeight()-45+'px',
			'width': getWidth()-45+'px'			
		});
	  */
	  setWidth(0);
}

function setWidth(full){
	  oldwidth = $('photoShowed').getStyle('width');
	 
	  
	  var url = '/ajax.php';
	  var pars = 'function=calcWidth&w='+getWidth()+'&h='+getHeight()+'&f='+full;
		
	 new Ajax.Request(
				url, 
				{
					method: 'get', 
					parameters: pars,
					onComplete:function(transport) {
					  var nw = transport.responseText || "no response text";
					  setNewWidth(nw);
				}					
				});
	 $('photoShowed').setStyle({
		 	'width' :  getNewWidth()+'px'});	
	
}

var newWidth;
function setNewWidth(nw){
	newWidth=nw;	
}

function getNewWidth(){	
	return newWidth;
}

function NormalizeDesktop(){
	  //setWidth(1);
	  $('header').appear();
	  $('footer').appear();
	  $('content-bg-top').appear();
	  $('content-bg-bottom').appear();	  
	  
	$('content').setStyle({
		  'filter':'Alpha(opacity=80)',
			'opacity':'0.8',
			'-moz-opacity':'0.8',
			'position': 'static',
			'width': '970px',
			'margin': 'auto',
			'backgroundImage' : 'url("./assets/images/content_bg_middle.png")'
	});
	

	  
	  $('normbutton').switchOff();
	  $('maxbutton').appear();
	  setWidth(1);
	  
}

function photos(){
	
	/*
	$('h1-pagename').update('Galleries');
	var url = '/ajax.php';
	var pars = 'function=loadGalleryInfo';
	var myAjax = new Ajax.Updater(
		'content', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});	
	
	
	*/
	
	$('gallery').appear();
	$('galleryScroller').appear();
	$('galbutton-left').appear();
	$('galbutton-right').appear();
	$('galhandle').appear();
	$('galtrack').appear();
	$('galleryScroller').setStyle({
		'width':'600px',
		'height':'25px',
		'display':'block',
		'margin':'auto',
		'position':'absolute',
		'bottom':'0px',
		'left':'1em',
		'right':'1em'
		
	});
	

	
	AddSlider();

	var url = '/ajax.php';
	var pars = 'function=getGalleries';
	
	var myAjax = new Ajax.Updater(
		't1', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});
}

function disclaimer(){
	var url = '/ajax.php';
	var pars = 'function=showDisclaimer';
	
	var myAjax = new Ajax.Updater(
		'content', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});
}

function contactdetails(){
	var url = '/ajax.php';
	var pars = 'function=showContactDetails';
	
	var myAjax = new Ajax.Updater(
		'content', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});	
}


function showGallery($gal){
	
	var url = '/ajax.php';
	var pars = 'function=showGallery&id='+$gal;
	
	var myAjax = new Ajax.Updater(
		'content', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});	
	
	var vis = $('galleryScroller').visible();
	
	if(vis == true){
		$('galleryScroller').switchOff();
		$('gallery').switchOff();				
	}
	$('galpicinfo').appear();
}


var slider = null;
function AddSlider(){
	slider = new Control.Slider('galhandle', 'galtrack', {
		axis: 'horizontal',
		range: $R(1,100),
		sliderValue:0,
		handleImage: 'galbutton-slider',		
		onSlide: function(v) { scrollHorizontal(v, $('galcontent'), slider);  },
		onChange: function(v) { scrollHorizontal(v, $('galcontent'), slider); }
		
/*
		slider.options.onChange = function(value) {
			  $('height_value').update(value);
			};
*/		
		
		
		
});
}
var SliderVar;
function ChangeSliderVar(vari){
	SliderVar = vari;
}


function ChangeSlider(value){	
	
	var pos=document.getElementById('galhandle').style.left;
	pos = parseInt(pos);
	if(value==0){
		pos+=1;
		if(pos>540){
			pos=540;
		}
	}else if(value==1){		
		pos-=1;
		if(pos<0){
			pos=0;
		}
		
	}
	
	$('galhandle').setStyle({
		'left':pos+'px'		
	});

	scrollHorizontal(pos/540*100, $('galcontent'), slider);
	
	if(SliderVar==1){
		window.setTimeout('ChangeSlider('+value+')', 7);
	}
}
	
// scroll the element horizontally based on its width and the slider maximum value
function scrollHorizontal(value, element, slider) {
	element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth));
}


function showInfo($text){
		
	if($text == null){
		$('galpicinfo').update('Infos about Galleries');
	}else{
		$('galpicinfo').update(
				'<div id="galpicinfo_inner"><p>'+
				$text +
				' </p></div>');
	}
	$('galpicinfo').appear(0);

	$('galpicinfo').setStyle(
			{'width':'500px',
			'height':'500px',
			'color':'white',
			'margin':'auto'});	
	
}

function CloseShowPictureInfo(){
	$('picinfo_inner').puff({ duration: 0 });

}
function CloseShowGalleryInfo(){
	$('galpicinfo_inner').puff({ duration: 0 });

}

function showPictureInfo($text){
	if($text == null){
		$('picinfo_inner').update('Infos about Pictures');
	}else{
		$('picinfo_inner').update(' : <span class="pictureinfo">'+$text+'</span>');
	}
	$('picinfo_inner').appear({ duration: 0 });
	$('picinfo').appear({ duration: 0 });

	/*$('picinfo').setStyle(
			{'width':'200px',
			'height':'100px',
			'color':'white',
			'margin':'auto'});
	*/
}
function showPicture(pid, gid){

	//$('galleryScroller').switchOff();
	//$('gallery').switchOff();	
	
	var url = '/ajax.php';
	var pars = 'function=showPicture&pid='+pid+'&gid='+gid+'&h='+getHeight()+'&w='+getWidth()+'&f='+fullSize;
	var myAjax = new Ajax.Updater(
		'content', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});
	if(fullSize == 1){
		  $('content').setStyle({
			  'position' : 'fixed',
			  'top' : '0px',
			  'left' : '20px',
			  'bottom' : '0px',
			  'right' : '0px',
			  'width': getWidth()-25+'px',
			  'margin':'0px',
			  'padding' : '0px',
			  'backgroundImage' : 'url("assets/images/bg.png")',
			  'backgroundRepeat':'repeat'
				  
		});
		setPhotoWidth();
	}
	 
}

function setPhotoWidth(){
	$('photoShowed').setStyle({"width": "10px"});
}

function getWidth() {
	var de = document.documentElement;
	var myWidth = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	return myWidth;
}

function getHeight() {
	var de = document.documentElement;
	var myHeight = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	return myHeight;
}

function setFullsize(size){
	fullSize = size;
}	


