// Sitewide scripts using jquery
$(document).ready(function() { 	
//superfish plugin for navigation
	$("ul.sf-menu").superfish({ 
		animation:   {height:'show'},  			// slide-down animation - use opacity:'show' to fade in
		speed:       'fast',                    // faster animation speed 
		autoArrows:  false                      // disable generation of arrow mark-up 
	}).find('ul').bgIframe({opacity:false}); 
//create rollover images and prelode by passing "true"
	$('img.rollover').rollover(true);
	
//activate png transparency fix
	$(document).pngFix();
	
//set the minimum height for mainContent div 
	var div = "#content";
	var height = 450; //minimum height
	var exceptions = "#ssp_cruise, #ssp_90th, #ssp_80th"; //exceptions to not apply height to
	
	var div_height = $(div).height(); 
	if (div_height < height) { 
		$(div+":not(:has("+ exceptions +"))").css('height', height+'px'); 
	}
	
//back in history button
	$('a.btn_back').click(function() {
		history.go(-1);
		return false;
	});
	
//open larger map
	$('a.popup').click(function() {
		window.open($(this).attr("href"), "popup", "resizable=1, scrollbars=1, status=0, toolbar=0, width=650px");
		return false;
	});
	
// Add target="_blank" to external links
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr("target", "_blank");
	
//remove the outline of a link when clicked
	$("a").click(function() {
		this.blur();
	});
	
//disable navigation link
	$("#n_history, #n_media, #n_events").click(function() {return false;});

//media for video player (commercials)	
	$(".audio").media( { 
		autoplay: false, 
		width: 200, 
		height:50,
		bgColor: '#f1d9bf'
	});
	$(".video").media( { 
		autoplay: false, 
		width: 400, 
		height: 300,
		bgColor: '#f1d9bf'
	});
	
// slideshowpro galleries
	$("#ssp_cruise").flash(
        { src: "ssp_cruise.swf",
          width: 500,
          height: 410,
		  allowFullScreen: true,
		  wmode: "transparent" },
        { version: 9 }
    );
	$("#ssp_90th").flash(
        { src: "ssp_90th.swf",
          width: 500,
          height: 410,
		  allowFullScreen: true,
		  wmode: "transparent" },
        { version: 9 }
    );
	$("#ssp_80th").flash(
        { src: "ssp_80th.swf",
          width: 500,
          height: 410,
		  allowFullScreen: true,
		  wmode: "transparent" },
        { version: 9 }
    );
	$("#celebration_thurs").flash(
        { src: "thurs_celeb.swf",
          width: 500,
          height: 410,
		  allowFullScreen: true,
		  wmode: "transparent" },
        { version: 9 }
    );
// validate form on keyup and submit
 	$("#form_bear").validate({
		rules: {
			Message: "required",
			First_Name: "required",
			e_mail: {
				required: true,
				email: true
			}
		},
		messages: {
			Message: "<br>Please enter your message to Root Beer Bear",
			First_Name: "<br>Please enter your First Name",
			e_mail: "<br>Please enter a valid email address"
		}
	});
	//Function to hide email addresses
	$('span.mailme').each(function(){
		var spt = "#" + $(this).attr("id");
		var at = / at /;
		var dot = / dot /g;
		var addr = $(spt).text().replace(at,"@").replace(dot,".");
		$(spt).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
		.hover(function(){window.status="Send a letter!";}, function(){window.status="";});
		$(spt).remove();
	});
});