// set up array.push() function for older browsers
function Array_push() {
  var A_p = 0
  for (A_p = 0; A_p < arguments.length; A_p++) {
   this[this.length] = arguments[A_p]
   }
  return this.length
}
	
if (typeof Array.prototype.push == "undefined") {
 Array.prototype.push = Array_push
 }
// ######################################
	Array.prototype.inArray = function (value)
		// Returns true if the passed value is found in the
		// array.  Returns false if it is not.
		{
			var i;
			for (i=0; i < this.length; i++) {
				// Matches identical (===), not just similar (==).
				if (this[i] === value) {
					return true;
				}
			}
			return false;
		};
function showGal(){
	 $('thumbnailCol').style.display="block";
	 }
function embedObject(filename, flashName, width, height, variableNames, variableValues, color) {
	if (!color){
		color="#FFFFFF";
	}
	document.write('<object style="vertical-align: bottom" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+flashName+'Flash" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+filename+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="bgcolor" value="'+color+'" />\n');

	var flashVars = '';

	if (variableNames && variableNames != ''){
		var varNamesArr  = variableNames.split("|");
		var varValuesArr = variableValues.split("|");
		for (var i=0; i<varNamesArr.length; i++){
			if (varNamesArr[i] != ''){
				flashVars += varNamesArr[i]+"="+varValuesArr[i]+"&";
			}
		}
	}
	if (flashVars != '')	{
		document.write('<param name="flashVars" value="'+flashVars+'" />');
		document.write('<embed src="'+filename+'" flashVars="'+flashVars+'" quality="high" bgcolor="'+color+'" width="'+width+'" height="'+height+'" name="'+flashName+'Flash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	} else {
		document.write('<embed src="'+filename+'" quality="high" bgcolor="'+color+'" width="'+width+'" height="'+height+'" name="'+flashName+'Flash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	}
	document.write('</object>\n');
}


// FORM VALIDATION
function validate(formName, validationArr){
	//alert(validationArr);
	errors = new Array();
	if (validationArr!=null){
		for (i=0; i<validationArr.length; i++){
			var myParts = validationArr[i].split("|");
			//alert(myParts);
		
			type = myParts[0];
			field = myParts[1];
			msgStr = myParts[2];
		
			
			switch (type){
				
				case "email":
				if (!isValidEmail($F(field))){
					errors.push("A Valid Email Address");
				}
				break;
				// -------------
				case "empty":
				if (!emptyFieldCheck($F(field))){
					errors.push(msgStr);
				}
				break;
				// -------------
				case "time":
				 if (document.forms[0].eventTime){
				 	if (!isValidTime(document.forms[0].eventTime.value)){
						errors.push("A Valid time, use HH:MM");
					}
				}
				break;
				// -------------
				case "date":
				if (document.forms[0].dc){
					if (!isDate(document.forms[0].dc.value)){
						errors.push("A Valid Date, use DD/MM/YYYY");	
					}
				}
				break;
				// -------------
				case "title":
				if (!emptyFieldCheck('detail', 'title')){
						errors.push("Title is required");
					}
				break;
				// -------------
		
			}
		}
	}

	if (errors.length > 0){
		alertMsg = "The following required fields were incomplete:\n\n";
		for (i=0; i<errors.length; i++){
			alertMsg += "  - "+errors[i]+"\n";
		}
		alertMsg += "\nPlease correct and try again."
		alert (alertMsg);
		return false;
	} else {
		//MM_showHideLayers('loadingMsg','','show');
		//document.detail.Button.disabled=true;
		return true;
		//$(formName).submit();
	}
}
	
function isValidEmail(email){
	//var email = document.forms[0].email.value; 

	var objRegExp  = /(^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$)/i;

	  if(objRegExp.test(email)){
		return true;
	  } else {
		//alert("Please enter a valid email address.");
		return false;
	  }

}
function emptyFieldCheck(val){
	if(val == '' || val == ' ' || val == null){ 
		return false;
	} else {
		return true;
	}
}	

	
	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_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_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];}
	}
// ==============================
var currentInd=0;
var currentThumb;
function showGalleryImg(ind){
	$('mainImg').src = imgDir + imgArr[ind];
	$('thumb_'+ind).className = "thumb active";
	
	if (currentThumb){
		$(currentThumb).className = "thumb";
	}
	
	currentThumb = 'thumb_'+ind;
	currentInd = parseInt(ind);
	
}

function nextImage(){
	currentInd++;
	if (currentInd>=imgArr.length){
		currentInd = 0;
	}
	showGalleryImg(currentInd);
}

function iniGallery(menuID){
	$(menuID).className += ' active';
	showGalleryImg(currentInd);
}