function setAutoOrNot() {
    var windowWidth = $(window).width();
    if (windowWidth > 1076) {
        $('#header').css('width','100%');
        $('#stayInformed,#banner,#footer,#content').css('width','100%');
    }   else {
        $('#header').css('width','auto');
        $('#stayInformed,#banner,#footer,#content').css('width',1076);
    }
}

function fixGalleryGlitch(){
    $('body.home div.slideshow').show();
}

$(document).ready(function() {
    setAutoOrNot();
    fixGalleryGlitch();
    
	$('body.home #content .featuredVideos li:first').addClass('first');
	
	$('body.home .choose_options select').change(function() {
	    if ( $(this).val() != ''  ) {
	        window.location = $(this).val();
	    }
	    
	});
	
	
	var searchVal = $('#searchform #s').attr('value');
	$('#searchform #s').attr('rel',searchVal)
	                   .focus(function() {
	                       $(this).attr('value','');
	                   })
	                   .blur(function() {
	                       if ( $(this).attr('value')=='' ) {
	                           $(this).attr('value',$(this).attr('rel'));
	                       }
	                   });
	                   
	var fullNameVal = $('#stayInformed form p.fullName input').attr('value');
    $('#stayInformed form p.fullName input').attr('rel',fullNameVal)
                   	                   .focus(function() {
                   	                       $(this).attr('value','');
                   	                   })
                   	                   .blur(function() {
                   	                       if ( $(this).attr('value')=='' ) {
                   	                           $(this).attr('value',$(this).attr('rel'));
                   	                       }
                   	                   });
                   	                   
    var emailVal = $('#stayInformed form p.email input').attr('value');
    $('#stayInformed form p.email input').attr('rel',emailVal)
                  	                   .focus(function() {
                  	                       $(this).attr('value','');
                  	                   })
                  	                   .blur(function() {
                  	                       if ( $(this).attr('value')=='' ) {
                  	                           $(this).attr('value',$(this).attr('rel'));
                  	                       }
                  	                   });               	                   

	/*if ($('body.home .testimonials .entry').size() > 1) {
	    //animateTestimonials();
	}*/
	
	$('body.home div.testimonials div.entry>p').prepend('<img src="' + theme_dir + '/images/quotes-open.gif" class="open" />')
                                     .append('<img src="' + theme_dir + '/images/quotes-close.gif" class="close" />');
	
	$('li').hover(function(){ 
		$(this).addClass('hover'); 
	},function(){ 
		$(this).removeClass('hover'); 
	});
	
	$('#header ul').superfish({ 
    	hoverClass:  'hover',  
		delay:       1000,                            // one second delay on mouseout 
        animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
        speed:       'fast',                          // faster animation speed 
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows 
    });

	$('a[rel="nofollow"]').css('cursor','default').click(function() {
		return(false);
	});
	
	$('.ngg-gallery-thumbnail a').attr({ rel: 'gallery' });
	
	$('.ngg-gallery-thumbnail a img').each(function(i){ 
	  	var x = $(this).attr('title');
		$(this).parent('a').attr('title',x);
	});
	
	
	$('a[rel="gallery"]').colorbox({
	    transition:"elastic",
	    opacity : .7 });
	/*$('div.ngg-gallery-thumbnail a').fancybox({
    		'speedIn'		:	600, 
    		'speedOut'		:	200, 
    		'overlayShow'	:	false
    	});*/
    
	
	
	//image cycle effects for home gallery
	$('.home-hockey').cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 3250
	});
	$('.home-soccer').cycle({
		fx: 'fade'
	});
	$('.home-gaga').cycle({
		fx: 'fade'
	});
	$('.home-motorcross').cycle({
		fx: 'fade'
	});
	$('.home-residential').cycle({
		fx: 'fade'
	});
	
	//add click function for home gallery to show and hide gallerys
	$('body.home #banner .gallery ul li a').click(function() {
		var thisGallery = $(this).parent('li').attr('class');
		thisGallery = thisGallery.replace(/ hover/, '');
		thisGallery = thisGallery.replace(/ selected/, '');
		$('body.home #banner .gallery-container div').hide();
		$('body.home #banner .gallery .home-'+thisGallery).show();
		$('body.home #banner .gallery ul li').removeClass('selected');
		$(this).parent('li').addClass('selected');
		return(false);
	});
	
	
	var whichGallery = 'hockey';
	if ($.getURLParam("gallery")) {
		whichGallery = ($.getURLParam("gallery"));
	}
	
	$('body.home #banner .gallery-container div').hide();
	$('body.home #banner .gallery .home-'+whichGallery).show();
	$('body.home #banner .gallery ul li').removeClass('selected');
	$('body.home #banner .gallery ul li.'+whichGallery).addClass('selected');

	$('#header ul:first>li>a').each(function() {
        this.innerHTML = '<span><span>' + this.innerHTML + '</span></span>';
    });
    
    // if IE & greater than version 7 or not IE do fancybox
    if ($.browser.msie) {
        if ($.browser.version >= 7) {
            $('div.video a,div.featuredVideos a').fancybox({
            		'overlayShow' : true
            	});
        }
     } else {
         $('div.video a,div.featuredVideos a').fancybox({
         		'overlayShow' : true
         	});
     }
    
	
});

$(window).resize(function() {
    setAutoOrNot();
});

$(window).load(function() {
    fixGalleryGlitch();
});
