//***************************************************************************************************	
//Sub-nav drop down
function startList() {
if ($('sub-nav')) {
	$$('li a[href=#]').addEvent('click', function(e){
		//Switch the class
	var daddy = this.getParent();    
		daddy.toggleClass('on').toggleClass('off');
		e.stop();    
	});
 }
}
////***************************************************************************************************
////Font resize
//function smallText() {
//    document.body.tween('font-size', '13px');
//	Cookie.write('fontsize','13');//set the cookie
//}
//function bigText() {
//    document.body.tween('font-size', '16px');
//	Cookie.write('fontsize', '16');//set the cookie
//} 


//**************************************************************
//Scroll
var horizontal;
var vertical;
//**************************************************************




window.addEvent('domready', function(){



//***************************************************************************************************
//Tool tips
var myTips = new Tips('.questions',{
	className: 'outer3',
	offset: {'x': -30, 'y': 35}

});
myTips.addEvent('show', function(tip){
    tip.fade('in');
});
myTips.addEvent('hide', function(tip){
    tip.fade('out');
});


//***************************************************************************************************
//External links to open in new window
if($$('a[rel="external"]')) {
    
    var anchors = $$('a[rel="external"]');
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
           anchor.getAttribute("rel") == "external")
           anchor.target = "_blank";        
        }
    
}


/*
if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }*/
//***************************************************************************************************
// Mootools jump menu
if($('ddState')) {
    $('ddState').addEvent('change', function(){
        var jumpUrl = this.getElement(':selected').value;
        if(jumpUrl != '') {
            window.location = jumpUrl;
            //alert(jumpUrl);
        }
    })
}
//***************************************************************************************************	
//OverText for forms
if($('login-username')!= null) {
new OverText('login-username',{ //there are many more options available!!
		wrap: true,
		positionOptions: {
			offset: {
				x: 8,
				y: 2
			}
		}
	});
}

if($('login-password')!= null) {
new OverText('login-password',{ //there are many more options available!!
		wrap: true,
		positionOptions: {
			offset: {
				x: 8,
				y: 2
			}
		}
	});
}

if($('search-term')!= null) {
new OverText('search-term',{ //there are many more options available!!
		wrap: true,
		positionOptions: {
			offset: {
				x: 8,
				y: 2
			}
		}
	});
}

									 
//***************************************************************************************************	
//Sub-nav drop down
startList();
//***************************************************************************************************	
//    //Font resize
//	var smallcolor = $('small-text');
//	smallcolor.setStyle.apply(smallcolor, (Cookie.read('fontsize') == '13') ? ['color','#CCC'] : ['color','#44742f']);
//	$('small-text').addEvent('click', function(){
//    	smallText();		
//		bigcolor.setStyle('color','#44742f');
//		this.setStyle('color','#CCC');
//		return false;
//	});
//	var bigcolor = $('big-text');
//	bigcolor.setStyle.apply(bigcolor, (Cookie.read('fontsize') == '16') ? ['color','#CCC'] : ['color','#44742f']);
//    $('big-text').addEvent('click', function(){
//    	bigText();		
//		smallcolor.setStyle('color','#44742f');
//		this.setStyle('color','#CCC');
//		return false;
//	});
//	//load the font-size cookie if it exists and change body font
//	var start = Cookie.read('fontsize') || '16';
//	document.body.setStyle('font-size',start + 'px');
//	//$('font-label').set('text','Font: ' + start);

//**************************************************************
//Scroll
if ($('horizontal')!= null) {

    horizontal = new Fx.Scroll.Carousel('horizontal',{
        mode: 'horizontal',
        childSelector: 'div',
        loopOnScrollEnd: false,
        onStart: function(){
            horizontal.getCurrent().tween('border-color','#000');
        },
        onComplete: function(){
            horizontal.getCurrent().tween('border-color','#CCC');
        }
    });
    
     (function(){horizontal.toNext();}).periodical(10000);
   
   $('next').addEvent('click', function(){
        horizontal.toNext();
        //vertical.toNext();
    });
    
    $('previous').addEvent('click', function(){
        horizontal.toPrevious();
        //vertical.toPrevious();
    });
	
}
//**************************************************************



//**************************************************************
//Accordion
if ($('accordion')!= null) {
var myAccordion = new Fx.Accordion($$('h1.toggler'), $$('.element'), {
		opacity: true
		//alwaysHide: true,
		//fixedHeight: 220,
		/*onActive: function(toggler, element){
			toggler.set('tween', {unit: 'em'});
			toggler.tween('background-position', '10em .5em');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('background-position', '11em .5em');			
			//toggler.tween('background-position', '210px 13px');
		}*/
});
}

//**************************************************************
//Table Highlighter
/*
Modify the row-hover, column-hover, row-on, and cell-hover classes in the CSS
*/



if ($('tblhghlt')!= null) {
var table = $('tblhghlt');
var rows = table.getElements('tr');

//for every row...
rows.each(function(tr,trCount){
    //we don't want the header
    if(tr.getParent().get('tag') == 'thead') { return false; }
    //add the row class to the row
    tr.addClass('row-' + trCount);
    //add the row listener
    tr.addEvents({
        'mouseenter': function(){
            tr.addClass('row-hover');
        },
        'click': function(){
            tr.toggleClass('row-on');
        },
         'mouseleave': function(){
            tr.removeClass('row-hover');
        }
    });
    //for every cell...
    tr.getElements('td').each(function(td,tdCount) {
        //remember column and column items
        var column = 'col-' + tdCount;
        var friends = 'td.' + column;
        //add td's column class
        td.addClass(column);
        //add the cell and column event listeners
        td.addEvents({
            'mouseenter': function(){
                $$(friends).erase(td).addClass('column-hover');
                td.addClass('cell-hover');
            },
            'mouseleave': function() {
                $$(friends).erase(td).removeClass('column-hover');
                td.removeClass('cell-hover');
            }
        });
    });
});

}
//**************************************************************


});


