window.addEvent('domready',function(){
	// modal popup
	var rateLinks = $$('a.rate');
	if (!rateLinks) return false;
	rateLinks.each(function(link,i){
		link.addEvent('click',function(e){
			e.preventDefault();
			
			if (document.getElement('.StickyWinInstance')!=null){
				this.tempDoc = document.getElement('.StickyWinInstance').retrieve('StickyWin');
				this.tempDoc.destroy();
			}
			
			$E = document.getElement.bind(document);
			$E('html').setStyle('overflow-x','hidden');
			
			this.modalWinOverlay = new StickyWinFxModal.Ajax({
				url: this.href,
				position: 'center',
				fade: true,
				fadeDuration: 300,
				relativeTo: $$('BODY'),
				offset:{
					x: '55px',
					y: '0px'
				},
		
				modalOptions:{
					modalStyle:{
						opacity: .6,
						'background-color': '#dfd3bb',
						overflow:'hidden'
					}
				}
			});
			this.modalWinOverlay.update();
			return false;
		});
	});
	
	//Legal popups in footer
	var legalLinks = $$('a.legalPopup');
	if (!legalLinks) return false;
	legalLinks.each(function(link,i){
		link.addEvent('click',function(e){
			e.preventDefault();
			window.open(link.href,"legal_popup","toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=638,width=668");
			return false;
		});
	});
	
	//Global Nav Fly-out 
	// Originally('ul.flyout-main li#what','ul.flyout-main li#why') but IE9 issues / test
	$$('ul.flyout-main > li').each(function(li) {
        li.addEvent('mouseenter', function() {
            li.addClass('active');
         });    
        li.addEvent('mouseleave', function() {
            li.removeClass('active'); 
        });
    }); 
	
});
//class to clear all parent divs in collection
//note i'm cycling thru divs so if you must nest divs you'll need a different array thru which to loop
var clearance = new Class({
    Implements: [Options, Events],
    initialize: function(div){		
        $$('#'+div+' div').each(function(item,n){			
            item.setStyle('display','none');
			$$('div .stars').setStyle('display','block');
        });
    }
});

//class to do the cycling
var toggleMany = new Class({	
    Implements: [Options, Events],
	
	//pass in vars: max, id, div, speed
    initialize: function(max,id,div,speed){
        this.random = $random(0,eval(max-1));
        this.timed = {counter: this.random};
        var cleared = new clearance(div);
        if(this.random == 0)this.random=max;
        var divInit = (id + (eval(this.random)));		
        $(divInit).setStyle('display','block');
        var addCount = function(){
            this.counter++;
            cleared.initialize(div); 
			//this is already instantiated so re-initialize, don't create a new one
			
            var divOn = id + this.counter;
            if(this.counter == max)this.counter = 0;
            $(divOn).setStyle('display','block');
        };
        addCount.periodical(speed, this.timed); 		
    }
});

window.addEvent('domready',function(){

	if($('featureModContainer')){
	//	var moduleB = new toggleMany(2,'div','moduleBuC',40000); //init the class, passing in the amount of layers through which you want to cycle
		var moduleC = new toggleMany(4,'mod','moduleCuC',20000);
	}
});


function closeStickyInIframe() {
	var tempDoc = document.getElement('.StickyWinInstance').retrieve('StickyWin');
	tempDoc.hide();
	return false;
}



//Make the first letter in a str caps, and all the rest lower
function stCap(strObj){
	return(strObj.charAt(0).toUpperCase()+strObj.substr(1).toLowerCase());
};


