if(typeof(sIFR) == 'object'){
	var rockwell = {
		src: '/swf/rockwell.swf'
	};
	
	sIFR.activate(rockwell);
	sIFR.replace(rockwell, {
		selector: 'h1'
		,wmode: 'transparent'
		,css: [
		  '.sIFR-root { color:#ffffff; text-transform:uppercase; text-align:center; letter-spacing:0; text-decoration:none; }'
 		 ,'a { color:#ffffff; text-decoration: none; }'
		 ,'a:link { color: #ffffff }'
		 ,'a:hover { color: #ffffff }'
		]
		,filters: {
		  GlowFilter: {
			strength:20,
			blurY:1.3,
			blurX:1.3,
			quality:10,
			//color:'#927B5F'
			color:'#333333'
		  }
		}
	});
}

var Site = {	
	prep: function(){
		new SmoothScroll();
		
		if($('feb29')){
			var count = 0;
			$$('table tr').each(function(el) {
				el.addClass(count++ % 2 == 0 ? 'odd' : 'even');
			});	
		}
		/*
		$$('#topNav div ul li a').each(function(el){
			var fx = new Fx.Styles(el, {duration: 1000, transition: Fx.Transitions.linear});
			el.addEvents({
				'mouseenter':function(){
					fx.start({
						'color':'#1b75bc'
					});
				},
				'mouseleave':function(){
					fx.start({
						'color':'#ffffff'
					});
				}
			});
		});
		*/
		
		if($('ourSponsorsBody')){
			var calendar = new CrossFade('ourSponsorsBody','sponsor', { delay:5000 });
		}
		
		if($('countdownTimer')){
			var timer = function(){
				var now = new Date();
				
				//Note that months starts at 0. Ex. January = 0.
				var date = new Date(2010,1,26,14,00,00);
				var nowTime = now.getTime();
				var targetTime = date.getTime();
				var timeLeft = targetTime - nowTime;
				
				if(timeLeft > 0){
					var seconds = 1000;
					var minutes = seconds*60;
					var hours = minutes*60;
					var days = hours*24;
					
					var d = Math.floor(timeLeft/days);
					var h = Math.floor((timeLeft - (days * d))/hours);
					var m = Math.floor((timeLeft - (days * d) - (hours * h))/minutes);
					var s = Math.floor((timeLeft - (days * d) - (hours * h) - (minutes * m))/seconds);
					
					if(d < 10) d = '0' + d;
					if(h < 10) h = '0' + h;
					if(m < 10) m = '0' + m;
					if(s < 10) s = '0' + s;
					
					$('countdownTimer').setHTML(d+':'+h+':'+m+':'+s);
				}else{
					$clear(countdown);
					$('countdownTimer').setHTML('FIESTA!');
				}
			}
			timer();
			var countdown = timer.periodical(1000);
		}
		
		if($('searchInput')){
			$('searchInput').addEvents({
				'click': function(){
					if(this.value == 'SEARCH SITE...'){
						this.value = '';
					}
				},
				'blur': function(){
					if(this.value == ''){
						this.value = 'SEARCH SITE...';
					}
				}
			});
		}
	},
	
	init: function(){
		
	},
	
	ifLoaded: function(file,action){
		var loaded = false;
		var scripts = $$('script');
		scripts.each(function(script){
			if(script.getProperty('src').indexOf(file) != -1){
				loaded = true;	
			}
		});
		
		if(loaded == false){
			var fileCheck = new Request({
				method: 'get', 
				url: file, 
				onSuccess: function(responseText){
					var assets = new Asset.javascripts([file],{
						onComplete: function(){
							action();
						}
					});
				}
			}).send('f=' + file);
		}else{
			action();
		}	
	}
}

var CrossFade = new Class({
 
	options: {
		startElem: 0,
		delay: 5000,
		speed: 800
	},
 
	initialize: function(wrapper,class_name,options){
		this.setOptions(options);
		this.wrapper = wrapper;
		this.class_name = class_name;
		this.elems = $$('*').filterByClass(class_name);
		this.i = this.options.startElem;
		this.firstItem = true;
		this.fadeAgain = false;
		this.moving = false;
		this.crossfade = '';
		this.events(this);
		this.fade();
	},
	
	fade: function(){
		
		if(this.moving == false){
			if(this.firstItem == true){
				this.elems[this.i].setOpacity(0);
				this.elems[this.i].setStyles({
					'display' : 'block',
					'visibility' : 'visible'
				});	
				
				this.fadeEffect(0,1,this);
				
				this.firstItem = false;
				this.crossfade = this.fade.periodical(this.options.delay, this);
			}else {
				
				this.fadeEffect(1,0,this);
				
				this.i++;
				if (this.i == (this.elems.length)) this.i = 0;
				this.elems[this.i].setOpacity(0);
				this.elems[this.i].setStyles({
					'display' : 'block',
					'visibility' : 'visible'
				});	
				
				this.fadeEffect(0,1,this);
			}
		}
				
		if(this.fadeAgain == true){
			this.crossfade = this.fade.periodical(this.options.delay, this);
			this.fadeAgain = false;
		}
	},
	
	fadeEffect: function(start,end,obj){
		
		obj.moving = true;
		
		fadeFx = new Fx.Style(this.elems[this.i], 'opacity', {
			duration: this.options.speed, 
			transition: Fx.Transitions.Quart.easeInOut,
			onComplete: function(){
				obj.moving = false;	
			}
		});
		
		fadeFx.start(start,end);
	},
	
	events: function(obj){
		$(obj.wrapper).addEvents({
			'mouseenter' : function(){
				$clear(obj.crossfade);
			},
			
			'mouseleave' : function(){
				obj.fadeAgain = true;
				obj.fade();
			}
		});
	}
		
});
CrossFade.implement(new Options, new Events);

window.addEvents({
	'domready': function(){
		Site.prep();
	},
	'load': function(){
		Site.init();	
	}
});