var exhibs = [];

function highlightmenu(which) {
    if (which) {
		var menu_item = $('menu_' + which);
		menu_item.setStyle({
			color: 'black',
			backgroundColor: '#C4C5C7',
			fontSize: '11px'
		});
	}
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if ( str.indexOf(" ") != -1 ) {
		return false
	}

	return true					
}

function maillist(formid) {
     if ( (!$('fm' + formid + '-name').value) || (!echeck($('fm' + formid + '-email').value)) ) {        
        alert('Please provide both your name and a valid email address');
        return;
     }
     var url = 'messenger.php';
     var pars = 'func=domail&' + $('fm-form' + formid).serialize();        
	 if (formid)
		pars += '&formid=' + formid;
     var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars,
            onComplete:function(request){
                $('mail_result' + formid).innerHTML = request.responseText;
				$('fm-form' + formid).reset();
             }
            });
}
 
  function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
      if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
	
function getExhibs() {  	
  pars = 'func=exhibs';
  url = 'artlook.php';
  var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete:function(request){    
				var resp = request.responseText;			        
				exhibs = eval( "(" + resp + ")" );                               
				doExhibs(3);
  }}); 
}			

function doExhibs(type) {
  var title, timing, maxPerLine, html, id, counter;
        html = '';
		counter = 0;
		for (var x = 0; x < exhibs.length; x++) {
			title = exhibs[x].name;
			id = exhibs[x].event_id;
			timing = exhibs[x].timing;
			maxPerLine = 4;
			if ( type == 3 || type == timing ) {						
				if (counter > 0) {				
					if (counter % maxPerLine == 0) { //clear display to next line 
						html +=  '<div class="clear mb20">&nbsp;</div>';
					}
				}		
				counter++;
				html += '<div class="thumb_div" style="margin-bottom: 25px; ">';
				html += '<div class="imageheightfix" style="height: 190px;">';
				html += '<a href="content/exhibition/';
				html += id;
				html += '.html"> <img src="images/events/';
				html += id;
				html += '.JPG" alt="';
				html += title;
				html += '" title="';
				html += title;
				html += '" class="img_border" /></a><br></div>';
				html += '<div class="thumb_div_text" style="width:165px; text-align:center; font-weight:bold;">';
				html += '<a href="content/exhibition/';
				html += id;
				html += '.html">';
				html += title;
				html += '</a></div></div>';
			}
		}
	    $('ex_content').innerHTML = html;
}

var min=8;
var max=18;
function increaseFontSize() {
 
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
 
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
 
         var s = 12;
      }
      if(s!=max) {
 
         s += 1;
      }
      p[i].style.fontSize = s+"px"
 
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
 
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
 
         var s = 12;
      }
      if(s!=min) {
 
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
 
   }
}

function scrollImages() {
		var thisCaption = 'caption' + i;
		Effect.Fade($('fade' + i), { duration:1, from:1.0, to:0.0, afterFinish: 
			function() {
				$(thisCaption).hide();
			} 		
		});		
		i++;
		if (i > imageLimit)
		  i=1;
        Effect.Appear($('fade' + i), { duration:1, from:0.0, to:1.0, afterFinish: 
			function() {
				Effect.Appear($('caption' + i), { duration:2, from:0.0, to:0.4});
			}
		});
    };

