//shorten getElementByID
function gbID(elementID){ return document.getElementById(elementID);}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
  do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	return Array(curleft,curtop);
}
}

function hilightTo(element){
var coordinates=findPos(element);
var xCor= parseInt(coordinates[0],10)-1;
var yCor= parseInt(coordinates[1],10)+11;
//gbID('hilighter').style.left='0px';
gbID('hilighter').style.top=yCor+'px';

$("#hilighter").animate({ 
        left: xCor+'px'
      }, 100 );

}

//function hidelight(){
//gbID('hilighter').style.left='-500px';
//gbID('hilighter').style.top='-500px';
//}

function loadThumb(thumb,thumbChild){

href=thumb.href;
picSwapper.update(['href','type'],[href,'pic'],['', '', '', ''],'POST'); 
titleSwapper.update(['href','type'],[href,'title'],['', '', '', ''],'POST'); 
var elem = document.getElementById('thumbBlock').getElementsByTagName('img');
for(var i = 0; i < elem.length; i++){
elem[i].className='thumbnail';
}
thumbChild.className='thumbnailSelected';
return false;
}


function swapPic(responseText){ 
$('#bigPicture').fadeOut(300);
$('#bigPicture').queue(function () {
        gbID('blockFour').innerHTML=responseText;
        $('#bigPicture').dequeue();
      });
}
function swapTitle(responseText){ gbID('picDescription').innerHTML=responseText;}
//debug script for Ajax calls
function alertJAX(responseText, responseStatus) {  if (responseStatus==200) { alert(responseText); return false; } else {    alert(responseStatus +' -- Error Processing Request');  }}

// Best Ajax object to date, multiple concurrent calls with queue, function callback and notification handler
// based on The Ultimate Ajax Object
function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.update = function(passNames,passValues,notifierArray,postMethod) { 
    //notifier array is [notifier element ID, loading HTML, ok HTML, bad HTML]
    that.notifier='';
    if(notifierArray[0] != ''){
    that.notifier=gbID(notifierArray[0]);
    that.notifier.innerHTML=notifierArray[1];
    }
    
    that.sendString='';
    that.cleanValue=new Array();
    for(i in passNames){
      
      passValues[i]=String(passValues[i]).replace(/&/g, "%26").replace(/\+/g,"%2B");
      that.sendString+=passNames[i]+'='+passValues[i]+'&';
      
      }
    
    if (that.updating) { return false; }
    that.AJAX = null; 

    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest(); //non IE             
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP"); //IE
    }                                             
    if (that.AJAX==null) {                             
      return false;  //no ajax
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4 && that.AJAX.status == 200) {             
          that.notifier.innerHTML=notifierArray[2];                            
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                
          
        } else if(that.AJAX.readyState==4 && that.AJAX.status != 200){
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null; 
          that.notifier.innerHTML=notifierArray[3];
          }                                                     
      }                                                       
      if (/post/i.test(postMethod)) {
        var uri=urlCall;
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length",that.sendString);
        that.AJAX.send(that.sendString);
      } else {
        var uri=urlCall+'?'+that.sendString; 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

function validateInput(source,type){
text=source.value;
noteID=source.id+'Note';
var regArray = [];

regArray['email']='^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$';
regArray['name']='^[a-zA-Z \']+$';
regArray['phone']='^[0-9-\(\)]*$';
regArray['any']='^.+$';
fieldRegex=new RegExp(regArray[type]);
if(!fieldRegex.test(text)){
gbID(noteID).innerHTML="please correct this value";
return false;
} else {
gbID(noteID).innerHTML="";
return true;
}
}
