window.addEvent('domready', function(){

	// we do nice tickers on home page.
	if ($('newsticker'))
	{
		var myTicker = new mooTickSlide($('newsticker'),{interval:5000, fadeSpeed: 500, pauseOnHover:true});
	}

 // externals
 // fuck ie. seriously. Just fuck it.
 // for some reason this kills ie6. there's absolutely no reason why it should. die in a fire IE6.
 if (!Browser.Engine.trident) {
   var httpLinks = $$('a').each(function(a){
     if (a.get('href') && a.get('href').contains('http') && (!a.get('href').contains('ideaservices.com.au'))){
        a.addClass('external');
     }
   });
 }
 
 // make search be rad
 $('m1SearchBox').addEvents({
   'focus': function(el){
     if ($('m1SearchBox').get('value') == 'Search...'){
       $('m1SearchBox').set('value', '');
     }
   },
   'blur': function(el){
     if ($('m1SearchBox').get('value') == ''){
       $('m1SearchBox').set('value', 'Search...');
     }
   }   
 });
 
 
 // CSS tips
 $$('.questionMark').each(function(el){
   el.addEvents({
     'mouseenter': function(e){
       el.getElement('span').setStyle('display', 'block');
       el.getElement('span').set('html', el.get('title'));
       el.set('title', '');
     },
     'mouseleave': function(e){
       el.getElement('span').setStyle('display', 'none');      
       el.set('title', el.getElement('span').get('html'));       
     }   
   });
 });

 // mailtos
 var mailtoLinks = $$('a[href^=email]').each(function(a){
   if (!a.get('href').contains('localhost')){
     a.addClass('mailto');
     var newEmail = a.get('href').replace('email','mailto') + "@ideaservices.com.au";
     a.set('href', newEmail);
     a.set('text', newEmail.replace('mailto:', ''));
   }
 });

  if (sb = $('ajaxSearchInput')) {
  
  	// the checking list function thing
   var checkTheList = function(){
     var found = false;
 
       if (sb.value == '') {
         $$('.ajaxListItem').each(function(el) {
           el.tween('height', '50px');
           found = true;
         });
         $('clearAjaxInputIcon').removeClass('active');     
       } else {
         $('clearAjaxInputIcon').addClass('active');     
         $$('.ajaxListItem').each(function(el) {
           if (el.innerHTML.test(sb.value, 'i'))
           {
             found = true;
             el.tween('height', '50px');
           } else {
             el.tween('height', '0px');
           }
         });
       }
       if (found == false){
           $('nothingFoundAlert').tween('height', '50px');
         } else {
           $('nothingFoundAlert').tween('height', '0px');      
       }  

    }
  
  	 // setup the rest
    sb.getParent('form').addEvent('submit', function(e) { e.stop(); });
    $('clearAjaxInputIcon').addEvent('click', function(e){
    	e.stop();
    	sb.set('value', '');
    	checkTheList();
    });
    $('nothingFoundAlert').setStyles({
     'height': '0px',
     'display': 'block'
    });
    $('quickSearchNoJs').setStyle('display', 'none');
    $('quickSearchForm').setStyle('display', 'block');
      
    sb.addEvents({
     'click': function(e) { this.value = ''; },
     'keyup':  checkTheList
    });
        
  }
});
