var text_size=function(size){
	switch(size){
		case 'small':
		$$('.art_content').setStyle('font-size','10px');
		break;
		case 'normal':
		$$('.art_content').setStyle('font-size','12px');
		break;
		case 'big':
		$$('.art_content').setStyle('font-size','14px');
		break;		
	}	
}
var title_and_text_size=function(size, title, content){
	switch(size){
		case 'small':
					$$('.'+title).setStyle('font-size','16px');
					$$('.'+content).setStyle('font-size','10px');
					break;
		case 'normal':
					$$('.'+title).setStyle('font-size','18px');
					$$('.'+content).setStyle('font-size','12px');
		break;
		case 'big':
					$$('.'+title).setStyle('font-size','20px');
					$$('.'+content).setStyle('font-size','14px');
		break;		
	}	
}
var ajaxGet = function(what, where, on){
	new Request.HTML({
		headers: {'If-Modified-Since': 'Thu, 1 Jan 1970 00:00:00 GMT','Content-type':'text/html; charset=utf-8'},
		url: what,
		method: 'get',
		onRequest: function(){$('da_spin').setStyle('display','block');},
		evalScripts: true,
		evalResponse: true,
		update: where,
		onComplete: function(on){
			$('da_spin').setStyle('display','none');
			eval(on);
		}
	}).send();
}
function ajaxGetData(what, params, where, on){
	new Request.HTML({
		headers: {'If-Modified-Since': 'Thu, 1 Jan 1970 00:00:00 GMT','Content-type':'text/html; charset=utf-8'},
		url: what,
		onRequest:function(){$(document.body).setStyle('cursor','progress');},
		method: 'get',
		evalScripts: true,
		evalResponse: true,
		update: where,
		onComplete : function(){on},
		onSuccess:function(){$(document.body).setStyle('cursor','auto');}
	}).send(params);
}
var ajaxPost = function(form,action,where,on){
	new Request.HTML({		
		url: action,
		onRequest:$('da_spin').setStyle('display','block'),
		evalScripts: true,
		evalResponse: true,
		update: where,
		onComplete: function(on){
			$('da_spin').setStyle('display', 'none');
			eval(on);
		}
	}).post(form);
}
var toggle_help=function(){
	var help = $('DBhelp');	
	var helpFx = new Fx.Morph(help,{wait:false})
	if(help.getStyle('opacity')=='0'){
		helpFx.start({'opacity':'1','width':'390px','height':'780px','border':'5px dashed #773B83','font-size':'12px'});
		setTimeout("new Fx.Morph($('DBhelp')).start({'opacity':'0','width':'0px','height':'0px','font-size':'0px'})", 30000);
	}else{
		helpFx.start({'opacity':'0','width':'0px','height':'0px','font-size':'0px'});
	}
	
}
var static_t;
var static_mouseoff;
var static_req=new Request();
var static_sok=function(sok){
	if (sok == '') {
		//$('sokdb').setStyle('display','none');
		//$('sokdb').fade('out');
		/*mouseoff=function(){
			setTimeout("$('sokdb').fade('out');", 3000);
		};
		document.onmousemove=mouseoff();*/
	}else {
		/*if ($('sokdb').getStyle('opacity') == 0) {
			$('sokdb').setStyle('display','block');
			$('sokdb').fade('in');
		}*/
		if (sok.length >= 2) {
			//alert(sok);
			static_req.cancel();
			static_req = new Request({
				method: 'get', 
				url: 'static_sok.php',
				data:'search='+sok+'&filter='+$('filter_db').value,
				onSuccess:function(responseText){
					$('activ').innerHTML=responseText;
				},
				evalScripts :true,
				evalResponse :false
			}).send();
		}
		//ajaxGet('sok.php?search=' + sok, $('sokdb'));
		//mouseoff=function(){};
	}	
}
var static_sok2=function(sok,p){
	if (sok == '') {
		//$('sokdb').setStyle('display','none');
		//$('sokdb').fade('out');
		/*mouseoff=function(){
			setTimeout("$('sokdb').fade('out');", 3000);
		};
		document.onmousemove=mouseoff();*/
	}else {
		/*if ($('sokdb').getStyle('opacity') == 0) {
			$('sokdb').setStyle('display','block');
			$('sokdb').fade('in');
		}*/
		if (sok.length >= 2) {
			//alert(sok);
			static_req.cancel();
			static_req = new Request({
				method: 'get', 
				url: 'static_sok.php',
				data:'search='+sok+'&p='+p+'&filter='+$('filter_db').value,
				onSuccess:function(responseText){
					$('activ').innerHTML=responseText;
				},
				evalScripts :true,
				evalResponse :false
			}).send();
		}
		//ajaxGet('sok.php?search=' + sok, $('sokdb'));
		//mouseoff=function(){};
	}	
}
var t;
var mouseoff;
var req=new Request();
var sok=function(sok){
	if (sok == '') {
		$('sokdb').setStyle('display','none');
		$('sokdb').fade('out');
		/*mouseoff=function(){
			setTimeout("$('sokdb').fade('out');", 3000);
		};
		document.onmousemove=mouseoff();*/
	}else {
		if ($('sokdb').getStyle('opacity') == 0) {
			$('sokdb').setStyle('display','block');
			$('sokdb').fade('in');
		}
		if (sok.length >= 2) {
			//alert(sok);
			req.cancel();
			req = new Request({
				method: 'get', 
				url: 'sok.php',
				data:'search='+sok+'&filter='+$('filter_db').value,
				onSuccess:function(responseText){
					$('sokdb').innerHTML=responseText;
				},
				evalScripts :true,
				evalResponse :false
			}).send();
		}
		//ajaxGet('sok.php?search=' + sok, $('sokdb'));
		//mouseoff=function(){};
	}	
}
var sok2 = function(sok,p){
	if ($('sokdb').getStyle('opacity') == 0) {
		$('sokdb').setStyle('display','block');
		$('sokdb').fade('in');
	}
	new Request({
		method: 'get', 
		url: 'sok.php',
		data:'search='+sok+'&p='+p+'&filter='+$('filter_db').value,
		onSuccess:function(responseText){
			$('sokdb').innerHTML=responseText;
		},
		evalScripts :true,
		evalResponse :false
	}).send();
}
var imgshifter=function(big, smalls){
	var images = big.concat(smalls);
	var bigImg = images[0];
	var smallImg = images[1];

	var bigImgX = bigImg.getStyle('left').toInt();
	var bigImgY = bigImg.getStyle('top').toInt();
	var bigImgWidth = bigImg.offsetWidth;
	var bigImgHeight = bigImg.offsetHeight;
	
	var smallImgX = smallImg.getLeft();
	var smallImgY = smallImg.getTop();
	var smallImgWidth = smallImg.offsetWidth;
	var smallImgHeight = smallImg.offsetHeight;
	
	var last=bigImg;
    var temp_left;
    var temp_top;    
	function makeBig(wich){
	    var fx_thumbs = new Fx.Morph(wich,{duration: 1200, wait:false, transition: Fx.Transitions.Quad.easeInOut});
	    fx_thumbs.start({
	            onStart: wich.setStyle('opacity','0.3'),
	            'height' : bigImgHeight,
	            'width' : bigImgWidth,
	            'top' : bigImgY,
	            'left' : bigImgX,
	            'opacity': 1
	     });
	}	
	function makeThumb(wich){
	    var fx_thumbs = new Fx.Morph(wich,{duration: 1200, wait:false, transition: Fx.Transitions.Quad.easeInOut});
	    fx_thumbs.start({
			onStart: wich.setStyle('opacity','0.3'),
	            'height' : smallImgHeight,
	            'width' : smallImgWidth,
	            'top' : temp_top,
	            'left' : temp_left,
	            'opacity': 1
	     });
	}	
	function action(wich){
	    if(wich.offsetHeight==smallImgHeight){ 
	        temp_left= wich.style.left;
	        temp_top= wich.style.top;
	        makeBig(wich);
	        makeThumb(last);
	        last=wich;
	     }	    
	}	
	images.each(function(x, i) {
		x.addEvent('click',function(){
			action(images[i]);
		})
	})
}
var tipsa=function(el){
	//alert(el.getPosition().y);
	var form_tipsa =$('form_tipsa');
	if(form_tipsa.getStyle('display')=='none'){
		form_tipsa.setStyles({'top':el.getPosition().y-30,'left':el.getPosition().x+150,'display':'block'});
		var txt = el.get('title').split('|');
		$('tipsacat').value=txt[0];
		$('tipsaid').value=txt[1];
	}else{
		form_tipsa.setStyles({'display':'none'});
		$('_form_tipsa').reset();
	}	
}
tipsa.sendd=function(){
	$('_form_tipsa').set('send', {url: 'tipsa.php', method: 'get', onComplete:function(){alert('Din meddelandet ar skickat')}});
	$('_form_tipsa').send();
	$('_form_tipsa').reset();
}
var print = function(el){
	var txt = el.get('title').split('|');
	window.open('print.php?cat='+txt[0]+'&id='+txt[1]);
}

var anmal = function(){
	$('prenumerera_form').set('send', {url: 'anmal.php', method: 'get', onComplete:function(){alert('Tack!')}});
	var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if(emailFilter.test($('anmal_email').value)){
		if($('anmal_namn').value=='NAMN :' || $('anmal_namn').value==''){
			alert('Alla fält behöver kompletteras!');
		}else{
			$('prenumerera_form').send();
		}
	}else{
		//the error ogiltig mailaddress
		alert('Ogiltig mailaddress.');
	}	
	$('prenumerera_form').reset();
	$('anmal_namn').value='NAMN :';
	$('anmal_email').value='E-POST :';
}
var enter = function(e, form){
	var eKey;
	if (window.event) { //ie
		eKey = e.keyCode;
	}else if(e.which) { // the (good) others
		eKey = e.which;
	}
	if (eKey == 13) {
		form.submit();
	}
}
var enterAjax = function(e, form, dest){
	var eKey;
	if (window.event) { //ie
		eKey = e.keyCode;
	}else if(e.which) { // the (good) others
		eKey = e.which;
	}
	if (eKey == 13) {
		ajaxPost(form, dest);
	}
}
var callGard=function(){
	ajaxGet('gard.php?module', $('garda'));
}
