function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

function imgPreview(){
		
		var pictureList=$$('div.foto img');
		
		pictureList.each(function(picture) {
			Event.observe(picture,'click', function(event){
				Event.stop(event);
				previewPicture(picture);
			});
		});
		
		function previewPicture(picture){
			if ($('modalWindow')!=null){
				$('modalWindow').remove();
				$('overlay').remove();
			}
			
			var modal=document.createElement("div");
			var overlay=document.createElement("div");
			overlay.className='overlay_modal';
			overlay.id='overlay';
			
			modal.className="modal";
			modal.style.zIndex=9999;
    		modal.style.display='block';
    		modal.id="modalWindow";
			//var dimension=document.viewport.getDimensions();
    		//alert(dimension.width);
			
			var windowWidth=Element.getWidth(document.body);
			var windowHeight=getPageSizeWithScroll()[1];		
			
			//console.log(Element.cumulativeOffset(document.body));
			//document.viewport.getScrollOffsets();
			overlay.style.width=windowWidth+'px';
			overlay.style.height=windowHeight+'px';
			var preloaded=new Image();
			preloaded.className="picture";
    		document.body.appendChild(overlay);
			//var position=picture.getPosition();
    		preloaded.onload=function(){
				modal.width=preloaded.width;
				modal.height=preloaded.height;
				modal.appendChild(preloaded);
				modal.style.top=parseInt(windowHeight/2-preloaded.height/2)+'px';
				modal.style.left=parseInt(windowWidth/2-preloaded.width/2)+'px';
				
				document.body.appendChild(modal);
				overlay.style.backgroundImage='none';
				Event.observe('modalWindow','click', function(event){Event.stop(event);modal.remove();$('overlay').remove();});
				
    		}
    		preloaded.src=src+module+"/"+picture.id;
    		
		}
}

function dm_window_open(file, width, height){

	window.open(file, "_blank", "width="+width+",height="+height+",titlebar=no,toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes");

}


function toggleMenu(el){
	el=$(el);
	var className='__open';
	if (el.hasClassName(className)){
		new Effect.Move (el,{ x: -500, y: 0, mode: 'absolute'});
		el.removeClassName(className);
	} else {
		new Effect.Move (el,{ x: 0, y: 0, mode: 'absolute'});
		el.addClassName(className);
		//el.effect('left',{duration: 500,onComplete:function(){el.addClassName(className);}}).start(-500,0);
		
	}
}


function getColor(){
	var colorSet=new Array();
	colorSet[0]={color:'1a7e78',light:'ddeceb',lighter:'f9fafa'};
	colorSet[1]={color:'7fbf33',light:'ecf5e1',lighter:'f9fafa'};
	colorSet[2]={color:'41a9b5',light:'e3f2f4',lighter:'f9fafa'};
	colorSet[3]={color:'a75b36',light:'f2e7e1',lighter:'f9fafa'};
	colorSet[4]={color:'aa41a6',light:'f2e3f2',lighter:'f9fafa'};
	colorSet[5]={color:'dfba00',light:'faf5d9',lighter:'f9fafa'};
	
	return colorSet[rand(0,5)]; 
}


function rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
 
    if( max ) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    } else {
        return Math.floor(Math.random() * (min + 1));
    }
}
var colorSet=getColor();