Event.observe(window,'load',jsLaunch);
function jsLaunch(){
  var links = $A($('content').getElementsByTagName('A'));
  links.each(function(el){
    //if(el.href.indexOf('mailto')!=-1) el.href = el.href + 'chaletangels.co.uk';
  });
  if($('quick_contact')){ 
	var el = $('quick_contact');
	fadeDown(el,1,.7);
    el.observe('mouseover',function(){
		if(!el.isup) fadeUp(el,.7,1);
		el.isup = true;
	  });
	fadeDown($('qc_response'),0,0);
	$('qc_submit').observe('click', qcSubmit);
  }
  var types = $('content').getElementsByClassName('type');
  if(types.length>0){
	types.each(function(el){
	  el.observe('mouseover',function(){this.style.cursor="pointer";});
	  el.observe('click',showTypeInfo);
	});  
  }
}
function showContact(){
  $('contact').show();
  if(navigator.userAgent.indexOf("MSIE")!=-1) $('contact').style.filter = "alpha(opacity:100)";
}
function showTypeInfo(e){
  var el = Event.element(e).parentNode.down(1);

  if(el.className.indexOf('show')!=-1){
    el.removeClassName('show');
  } else {
    el.addClassName('show');
  }
}
function fadeUp(el,from,to){
  var s = el.style, start = from*100, finish = (to*100)+1;
  if(s.display!='block') s.display = 'block';
  for(var i=start;i<finish;i++){
	setTimeout("var el=$('"+el.id+"');el.style.opacity="+i/100+";el.style.filter='alpha(opacity:"+i+")'; ",i*5);
  }
}
function fadeDown(el,from,to){
  if(from==0){
    el.style.opacity=0;el.style.filter='alpha(opacity:0)';return;
  }
  var s = el.style, start = from*100, finish = (to*100)-1;
  if(s.display!='block') s.display = 'block';
  for(var i=start;i>finish;i--){
	setTimeout("var el=$('"+el.id+"');el.style.opacity="+i/100+";el.style.filter='alpha(opacity:"+i+")'; ",(100-i)*5);
  }
}
function contact(){
  alert( 'contact form here' );
}
function qcSubmit(){
  var email = $('qc_email').value, url = "qc.php";
  if(email.indexOf('@')==-1){
    alert('Please enter a valid email address');
	return;
  }
  p = "email="+email;
  new Ajax.Request(url,{method:'post',parameters:p,onSuccess:showReceived});
}
function sendEnquiry(){
  var email = $('c_email').value, url = "c.php";
  if(email.indexOf('@')==-1){
    alert('Please enter a valid email address');
	return;
  }
  p = "email="+email;
  p += "&name="+$('c_name').value;
  p += "&phone="+$('c_phone').value;
  p += "&enquiry="+$('c_enquiry').value;
  new Ajax.Request(url,{method:'post',parameters:p,onSuccess:showEnquirySent});
}
function cancelEnquiry(){
  $('contact').hide();	
}
function showEnquirySent(o){
  var el = $('c_response');
  $('contact').hide();	
  el.innerHTML = o.responseText;
  fadeUp(el,0,1);
  setTimeout("var el = $('c_response');fadeDown(el,1,0);",3000);
  setTimeout("$('c_response').style.display='none';",5000);
}
function showReceived(o){
  var el = $('qc_response');
  el.innerHTML = o.responseText;
  fadeUp(el,0,1);
  setTimeout("var el = $('qc_response');fadeDown(el,1,0);",3000);
  setTimeout("$('qc_response').style.display='none';",5000);
}