$(function() {
	if(detectBrowser['saf']) {
		if($('.formButton input').length > 0) {
			$('.formButton input,.formButton .linkButton').css('padding','5px 10px');
		}
	}
   $('.jQueryRounded').corners("20px");
   $('.jQueryRounded8').corners("8px");
   $('.jQueryRounded4').corners("4px");

   // Scroll to containers
   if($('.scrollToContainer').length > 0) {
      $('.scrollToContainer').scrollTo(0); // Reset all scrollable panes to (0,0)
      $.scrollTo(0); // Reset the screen to (0,0)
      
      paneTarget = $('.scrollToContainer');
      
      $('.scrollToHeader').click(function() {
         paneTarget.scrollTo($('div #scroll'+$(this).attr('rel')),800);
         $(this).addClass('selected').siblings('h3.scrollToHeader').removeClass('selected');
      }).css('cursor','pointer');
   }
   
   // Accordion containers
   if($('.accordion').length > 0) {
      $('.accordion').accordion({ 
          /* autoheight: false, */
          header: '.accordionHeader'
      }).find('h3.accordionHeader').css('cursor','pointer');
      
      $('.accordion h3').click(function() {
         $('#featureImage').attr('src','/images/temporary/' + $(this).attr('rel'));
      });
   }
   
   //Homepage scroller setup
   //The following line gets the scrollTo script and loads it dynamically.
   //We also have a callback so the code inside gets executed AFTER the script is loaded properly
   $.getScript('http://www.tailgatehaven.com/scripts/jquery.scrollTo.js', function(){
   	var slideshowCounter = 1; //Initialize the slideshow counter variable
   	var slideshowLength = $.makeArray($('div#homeSlideshowContainer div.homeSlide')); //Get an array of slides
   	slideshowLength = slideshowLength.length; //Set the length array to the number of slides
   	
   	$('.homeSlideshowNext').click(function(){ //When the next button is clicked...
   		slideshowCounter++;
			if (slideshowCounter>slideshowLength) slideshowCounter = 1;
			$('#homeSlideshowContainer').scrollTo($('#homeSlide' + slideshowCounter), 500, {axis:'x'});
   	});
   	
   	$('.homeSlideshowPrev').click(function(){ //When the previous button is clicked
   		slideshowCounter--;
			if (slideshowCounter<1) slideshowCounter = slideshowLength;
			$('#homeSlideshowContainer').scrollTo($('#homeSlide' + slideshowCounter), 500, {axis:'x'});
   	});
   	
   	//We also set up a timer to slide the slides
   	setInterval(function(){
   		slideshowCounter++;
			if (slideshowCounter>slideshowLength) slideshowCounter = 1;
			$('#homeSlideshowContainer').scrollTo($('#homeSlide' + slideshowCounter), 500, {axis:'x'});
   	}, 20000);
   	
   	//Init scoreboard scroller
   	var scoreboardScrollerCounter = 1;
   	var scoreboardScrollerLength = $.makeArray($('div#scoreboardScrollerContainer div.scoreboardScroller'));
   	scoreboardScrollerLength = scoreboardScrollerLength.length;
   	setInterval(function(){
   		scoreboardScrollerCounter++;
   		if (scoreboardScrollerCounter>scoreboardScrollerLength) scoreboardScrollerCounter = 1;
   		$('div#scoreboardScrollerContainer').scrollTo($('div#scoreboardScroller' + scoreboardScrollerCounter), 500, {axis:'y'});
   	}, 4000);
   });
   initClasses();
});
function directAndSubmit( formBtn, act ) {
	$('#eventFieldId').val(act);
	formBtn.form.submit();
}

//The below function will check for certain classes and
//apply certain attributes based on the class
function initClasses(){
	//If the externalLink class is found we add the target blank attribute.
	//This allows the link to open in a new window without breaking xhtml 1.0 strict rules
	$('.externalLink').attr('target', '_blank');
}
