$(document).ready(function() {

// alter the attribute on all external links
$('a.external').attr("target","_blank");

// members a-z list

$('#q').liveUpdate('members_list').focus();

// initialise news list

$('#static_spotlight_list').css({ display: 'none'});
$('#news').css({ display: 'block'});

// initialise cycling logos

// hide static
$('#single_gold_member_logo').css({ display: 'none'});
$('#single_platinum_member_logo').css({ display: 'none'});

        
$('#gold_members_logos').css({ display: 'block',overflow:'hidden'});
$('#platinum_members_logos').css({ display: 'block',overflow:'hidden'});
//$('#gold_members_logos img').css({ display: 'none'});
//$('#platinum_members_logos img').css({ display: 'none'});
//$('#gold_members_logos img').css({ display: 'inline'});
//$('#platinum_members_logos img').css({ display: 'inline'});



$('#gold_members_logos img').each(function() {
                if (($(this).width())!=0)
                	$(this).css({marginLeft: ((218-$(this).width())/2)});
                else
			$(this).css({marginLeft: 10});
                if (($(this).height())!=0)
			$(this).css({marginTop: (120-$(this).height())/2});
		else 
			$(this).css({marginTop: 10});
        });

$('#platinum_members_logos img').each(function() {

                if (($(this).width())!=0)
                	$(this).css({marginLeft: ((218-$(this).width())/2)});
                else
			$(this).css({marginLeft: 10});
                if (($(this).height())!=0)
			$(this).css({marginTop: (120-$(this).height())/2});
		else 
			$(this).css({marginTop: 10});
        }); 
 
  

$('#gold_members_logos').cycle({ 
    fx:    'fade', 
    speed:  2500,
    random: 1
 });

$('#platinum_members_logos').cycle({ 
    fx:    'fade', 
    speed:  2500,
    random: 1
 });   
       

				 
$("table.data_table  tr:nth-child(even)").addClass("odd");
$("ul.events-list  li:nth-child(even)").addClass("odd");

$('.clickable').fitted();
$('.clickable').css("cursor","pointer");


});			  
			


function addEventX(element, eventType, lamdaFunction, useCapture) {
 if (element.addEventListener) {
 element.addEventListener(eventType, lamdaFunction, useCapture);
 return true;
 } else if (element.attachEvent) {
 var r = element.attachEvent('on' + eventType, lamdaFunction);
 return r;
 } else {
 return false;
 }
}

addEventX(window, 'load', clearFormFields, false);	
	
function clearFormFields() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEventX(theInput, 'focus', clearDefaultText, false);
            addEventX(theInput, 'blur', replaceDefaultText, false);
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}


function initOverLabels () {
  if (!document.getElementById) return;      

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // labels with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {

    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute ('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      } 

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to label elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i]. getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-5000px' : '0px';
      return true;
    }
  }
}


function memberSubmitButton(){
	if(!document.getElementById("member_login")) {return false;}
	
members_btn = document.getElementById("member_login");
members_btn.onclick= function(){
changeSubmit(this, 'Logging in...')	
}
}

/*
function bookingSubmitButton(){

if(!document.getElementById("submit_btn")) {return false;}
	
submit_btn = document.getElementById("submit_btn");
submit_btn.onclick= function(){
changeSubmit(this, 'Registering...')
}
}

*/

function changeSubmit(element, inputvalue){
element.setAttribute('originalValue', element.value);
element.disabled=true;
element.value=inputvalue;
result = (element.form.onsubmit ? (element.form.onsubmit() ? element.form.submit() : false) : element.form.submit());
if (result == false) { element.value = element.getAttribute('originalValue'); element.disabled = false };
element.disabled=false;
return result;
}




/*
 DOMnews 1.0
 homepage: http://www.onlinetools.org/tools/domnews/
 released 11.07.05
*/
 
/* Variables, go nuts changing those! */
 // initial position
 var dn_startpos=200;    
 // end position
 var dn_endpos=-540;    
 // Speed of scroller higher number = slower scroller
 var dn_speed=20;    
 // ID of the news box
 var dn_newsID='news';   
 // class to add when JS is available
 var dn_classAdd='hasJS';  
 


 
/*
 This is the functional bit, do not press any buttons or flick any switches
 without knowing what you are doing!
*/
 
 var dn_scrollpos=dn_startpos;
 /* Initialise scroller */
 function initDOMnews()
 {
  var n=document.getElementById(dn_newsID);
  if(!n){return;}
  n.className=dn_classAdd;
  dn_interval=setInterval('scrollDOMnews()',dn_speed);
  //var newa=document.createElement('a');
  //var newp=document.createElement('p');
  //newa.href='#';
  //newa.onclick=stopDOMnews;
  //newp.appendChild(newa);
  //n.parentNode.insertBefore(newp,n.nextSibling);
  n.onmouseover=function()
  {  
   clearInterval(dn_interval);
  }
  n.onmouseout=function()
  {
   dn_interval=setInterval('scrollDOMnews()',dn_speed);
  }
 }
 
 function stopDOMnews()
 {
  clearInterval(dn_interval);
  var n=document.getElementById('news');
  n.className='';
  n.parentNode.removeChild(n.nextSibling);
  return false;
 }
 function scrollDOMnews()
 {
  var n=document.getElementById(dn_newsID).getElementsByTagName('ul')[0];
  n.style.top=dn_scrollpos+'px'; 
  if(dn_scrollpos==dn_endpos){dn_scrollpos=dn_startpos;}
  dn_scrollpos--; 
 }




window.onload = function () {
  setTimeout(initOverLabels, 100);
};

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}}}
		
addLoadEvent(memberSubmitButton);
//addLoadEvent(bookingSubmitButton);
addLoadEvent(initDOMnews);

