function activatePlaceholders() {
if(Browser.ie) {
var detect = navigator.userAgent.toLowerCase(); 
if (detect.indexOf("safari") > 0) return false;
var inputs = document.getElementsByTagName("input");
for (var i=0;i<inputs.length;i++) {
  if (inputs[i].getAttribute("type") == "text") {
   if (inputs[i].getAttribute("placeholder") && inputs[i].getAttribute("placeholder").length > 0) {
    inputs[i].value = inputs[i].getAttribute("placeholder");
    inputs[i].onclick = function() {
     if (this.value == this.getAttribute("placeholder")) {
      this.value = "";
     }
     return false;
    }
    inputs[i].onblur = function() {
     if (this.value.length < 1) {
      this.value = this.getAttribute("placeholder");
     }
    }
   }
  }
}
}
}

window.addEvent('load', function(){
	$(document.body).setStyle('visibility','visible');
});

window.addEvent('domready', function(){
$(document.body).setStyle('visibility', 'hidden');
activatePlaceholders();
if (root = $('container')){

    root.getElements('img').each(function(i){
    
        if (i.getProperty('alt') && !i.getProperty('title')){
            i.setProperty('title', i.getProperty('alt'));
        }
    
    });
    
   	// homepage scroller
	
	if ($('scroller')){
	
		$('scroller').getElements('li').setStyle('opacity', 0).set('tween', { duration: 200 });
	
		var next = function(){
		
			var sel = $('scroller').getElement('.selected').removeClass('selected').tween('opacity', 0);
			if (sel.getNext('li')){
				sel = sel.getNext('li');
			} else {
				sel = $('scroller').getElement('li');
			}
			sel.addClass('selected').tween('opacity', 1);
						
			root.getElements('ul.media_controller li.selected').removeClass('selected');
			root.getElements('ul.media_controller li')[sel.getAllPrevious('li').length].addClass('selected');
			
		};
		
		$('scroller').getElement('li').setStyle('opacity', 1).addClass('selected');
		var moveiton = next.periodical(6000);
		
		// deal with what happens when someone clicks on one of the buttons
		root.getElements('ul.media_controller li').addEvent('click', function(c){
			// stop click throughs
			c.stop();
			
			// clear timer so it doesn't move on
			clearInterval(moveiton);
			
			// remove currently selected class
			root.getElements('ul.media_controller li.selected').removeClass('selected');
						
			// add class to chosen one
			root.getElements('ul.media_controller li')[this.getAllPrevious('li').length].addClass('selected');
			$('scroller').getElement('.selected').removeClass('selected').tween('opacity', 0);
			$('scroller').getElements('li')[this.getAllPrevious('li').length].addClass('selected').tween('opacity', 1);
		});
		
	}
	    


    if (accordions = root.getElements('.accordion')) {
                
        accordions.each(function(acc){
		
					accnode = new Fx.Accordion(
						acc.getElements('h2,h3'), 
						acc.getElements('div'),
						{
							display: (acc.getProperty('data-displayid')) ? acc.getProperty('data-displayid') : -1,
							alwaysHide: true
						}
					)
					.addEvent('active', function(t, e){
						t.addClass('open');
					})
					.addEvent('background', function(t, e){
						t.removeClass('open');
					});
					
					acc['accnode'] = accnode;
		        
	      });
        
    }


    if (people = root.getElement('.facewall')) {
   
        var relations = new Array();
        
        if (people_chooser = root.getElement('.right-personnav')) {
            people_choosers = people_chooser.getChildren('li');
            
            people_choosers.each (function(pc) {
            
                // add this person type to the list and associate with LIs in the .facewall
                inode = pc.getElement('h3 a').getProperty('data-nodeid');
                anode = pc.getElement('h3 a').getProperty('data-nodename');
                
                relations[inode]=anode;
     
                // add click events to 'open' and 'close' the .facewall
                // respect the accordion too.
                pc.getElement('h3 a').addEvent('click', function(ev) {

//                     if (ev) ev.stop(); // does this respect accordion? 
/*                     console.log('firing '+pc.getElement('h3 a').getProperty('data-nodeid')); */
                    people.fireEvent('openfacewall', pc.getElement('h3 a').getProperty('data-nodeid'));
                    
                });
            });
            
        }
        
        people.addEvent('openfacewall', function(nodeid, event) {

            relations.each(function(v,k){
                people.removeClass('pg'+k);
            });
            people.addClass('pg'+nodeid);
            
            people.getChildren('li').each(function(c){
                if (c.hasClass('pg'+nodeid)) {
                    c.setStyle('display', 'block');
                } else {
                    c.setStyle('display', 'none');
                }
            }); 
            
            if (nodeid==1) {
                root.getElement('.bird').setStyle('display', 'block');
            } else {
                root.getElement('.bird').setStyle('display', 'none');
            }
        });
        
        if (location.hash) {
            people.fireEvent('openfacewall', relations.indexOf(location.hash.replace('#', '')));
            root.getElements('.accordion')[0].getElements('li h3 a').each(function(el){
                if (el.getProperty('data-nodename')==location.hash.replace('#', '')) el.getParent('h3').fireEvent('click').addClass('open');
            });
        } else {
            people.fireEvent('openfacewall', 1);
            root.getElements('.accordion')[0].getElements('li h3 a').each(function(el){
                if (el.getProperty('data-nodeid')==1) el.getParent('h3').fireEvent('click').addClass('open');
            });
        }
        
    }
    
    
    if (side_results = root.getElement('#side_results')) {
    
    		// console.log('bout ye');
    		var current_result = 0;
    		var next_id = function() {
    			current_result = ++current_result%side_results.getElements('li').length
    			return current_result
    		}
    		var next_result = function() {
    				side_results.getElements('li')[current_result].setStyle('display', 'none');
    				side_results.getElements('li')[next_id()].setStyle('display', 'block');
    		};
    		
    		
				var rotate_result = next_result.periodical(3500);

    }

    
      
    if (resizeTarget = $('main_column')) {
        resizeObject = root.getElement('.grid');
        resizeTimeoutForPerformance = t = new Date().getTime();
        minimumHeight = 650;
        window.addEvent('resize', function(ev) {

            if (window.getScrollSize().y <= (resizeTarget.getSize().y+210) && window.size().height > minimumHeight){
                resizeObject.addClass('pagegoeslowerthanthebrowserwindow');
            } else {
                resizeObject.removeClass('pagegoeslowerthanthebrowserwindow');
            }
            

        }); 
        window.fireEvent('resize');
    }    
    
}});



window.size = function()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}
