// JavaScript Document
//load js files
function scriptLoad(url){
	document.write( '<script type="text/javascript" src="', url, '">', '<\/script>' ); 			   
}

scriptLoad("js/jquery.cycle.all.min.js");
scriptLoad("js/jquery.easing.1.3.js");
//external links
$(function(){ 
	$("a[rel='external']").attr("target","_blank");
});
//change background png to gif for IE6
$(function(){
	var br = navigator.appName;
	if (typeof document.body.style.maxHeight == "undefined" && br == "Microsoft Internet Explorer") {
		var imSrc, newImg;
		$.each($("img"), function(){
			imSrc = $(this).attr("src");
			if(imSrc.substr(imSrc.length-4,4) == ".png"){
				newImg = imSrc.replace(".png",".gif");
				$(this).attr("src", newImg);
			}
		});
		var bImUrl, newBIm;
		$.each($("a, div, body, li, h1, h2, h3, html"), function(){
			bImUrl = $(this).css("background-image");
			if(bImUrl.substr(bImUrl.length-6,4) == ".png"){
				newBIm = bImUrl.replace(".png",".gif");
				$(this).css("background-image", newBIm);
			}
		});
	}
});

$(function (){
	var menu;
	switch($("#content").attr('class')){
		case "home2010":
			menu = "Home";
		break;
		case "acknowledgements":
			menu = "Acknowledgements";	
		break;
		case "contactus":
			menu = "Contact Us";
		break;
		case "events":
			menu = "Events";
		break;
		case "location":
			menu = "Location Info";
		break;
		case "refreshments":
			menu = "Refreshments";
		break;
		case "reviews":
			menu = "Concert Reviews";
		break;
		case "tickets":
			menu = "Tickets";
		break;
		case "venue":
			menu = "Venue";
		break;
	}
	
	$("#navMain li").each(function(){
		if(menu == $(this).find("a").html()){
			$(this).find("a").attr("class", "cur");
		}else{
			$(this).find("a").attr("class", "");
		}
	});
});
//refresh captcha
$(function (){
	$("#captchaImg img").click(function(){
		var d = new Date();
		$(this).attr('src', "img/captcha.php?"+d.getTime());
	});
});
//BP Video
$(function(){
	var fc = "<object type='application/x-shockwave-flash' data='/bp-tvc.swf' width='328' height='300' id='NTHeader'>\n";
	fc += "<param name='movie' value='/bp-tvc.swf' />\n";
	fc += "<param name='allowScriptAcess' value='sameDomain' />\n";
	fc += "<param name='quality' value='best' />\n";
	fc += "<param name='play' value='false' />\n";
	fc += "<param name='salign' value='TL' />\n";
	//fc += "<param name='wmode' value='transparent' />\n";
	fc += "</object>";
	$("#bpTvc").html(fc);
});

//slideshow
//To add more images, resize image to height:250px, rename to MMM_n.jpg where n = slide number and save to img/slideshow folder.
//Change totalSlideCount var (below) to match total number of slides

var totalSlideCount = 70;
$(function(){
	var randImg;
	randImg=Math.floor(Math.random()*(totalSlideCount+1));
	$("#ssPics").html('<img src="img/slideshow/MMM_'+(randImg)+'.jpg" />')
	randImg=Math.floor(Math.random()*(totalSlideCount+1));
	$("#ssPics").append('<img src="img/slideshow/MMM_'+(randImg)+'.jpg" />')
	$("#ssPics").cycle({
    	fx: 'fade', 
		pause:1,
		speed:1000,
		timeout:6000,
		before:onBefore
	});		   
});
var randomNumber;
function onBefore(curr, next, opts) { 
        // on the first pass, addSlide is undefined (plugin hasn't yet created the fn); 
        // when we're finshed adding slides we'll null it out again 
        if (!opts.addSlide) 
            return; 
 
        // on Before arguments: 
        //  curr == DOM element for the slide that is currently being displayed 
        //  next == DOM element for the slide that is about to be displayed 
        //  opts == slideshow options 
             
        /*var currentImageNum = parseInt(next.src.match(/MMM_(\d)/)[1]); 
             
        if (currentImageNum == totalSlideCount) { 
            // final slide in our slide slideshow is about to be displayed 
            // so there are no more to fetch 
            opts.addSlide = null; 
            return; 
        } */
        randomNumber=Math.floor(Math.random()*(totalSlideCount+1));
        // add our next slide 
        //opts.addSlide('<img src="img/slideshow/MMM_'+(currentImageNum+1)+'.jpg" />'); 
        opts.addSlide('<img src="img/slideshow/MMM_'+(randomNumber)+'.jpg" />'); 
    };