function writeFlash(url,w,h,id,bg,trans) {
var html = "";
html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + w + '" height="' + h + '" id="'+ id + '">\n';
html += '<param name="movie" value="' + url + '" />\n';
html += '<param name="quality" value="high" />\n';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="scale" value="noscale" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += '<!--[if !IE]> <-->\n';
html += '<object data="' + url + '" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" name="'+ id + '">\n';
html += '<param name="quality" value="high" />\n';
html += '<param name="scale" value="noscale" />\n';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += ' FAIL (the browser should render some flash content, not this).\n';
html += ' </object>\n';
html += '<!--> <![endif]-->\n';
html += '</object>\n';
document.write(html);
}
function visit(newURL) {
	var site = window.open(newURL, 'website','scrollbars=1, resizable=1, location=1, menubar=1, status=1, toolbar=1, height=768, width=1024');
	site.window.focus();
}
function popup(newURL) {
	var p = window.open(newURL, 'popup','scrollbars=0, resizeable=0, width=425, height=550');
	p.window.focus();
}
function popupPic(sPicURL) {
	var pp = window.open( "popup.html?"+sPicURL, "popupPic", "scrollbars=0, resizeable=1, width=425, height=550");
	pp.window.focus();
}
function rand(min,max){
	var $min,$max,random_num;
	$min = min;
	$max = max + 1;
	random_num = Math.floor($min + ($max-$min)*Math.random());
	return random_num;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
};
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
};
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

function verticalCenter(target){
	var wH = $(window).height();
	var oH = $(target).height();
	if ( wH <= oH ){
		$(target).css({
			top: "10px",
			marginTop: "0px"
		});
	}
	else{
		$(target).css({
			top: "50%",
			marginTop: "-350px"
		});
	}
}
function showPage(n){
	$(".page").css("display","none");
	$("#page-"+n).css("display","block");
}
function showLyrics(n){
	$(".lpage").css("display","none");
	$("#lpage-"+n).css("display","block");
}
function sendEmail(){

	var sendData = {
		email_address: $("#email_address").val(),
		name: $("#email_name").val()
	};
	
	$.ajax({
	  type: "POST",
	  url: "/_scripts/submit_form.php",
	  data: sendData,
	  dataType: "text",
	  error: function(){
	      alert('Our site is experiencing difficulties, please check back later.');
	  },
	  complete: function(data) {
		
		$("#fanlist").css("background","url(/_images/fanlist-thx-bkd.jpg) transparent no-repeat 0px 0px;").html("<div id='thanks'>Thanks for your interest, we will add you to our mailing list.</div>");
	  }
	});
}

$(document).ready(function(){
	//background rollovers setup
	$("#mainmenu a").hover(
		function () {
			$(this).css("background-position","right -19px");
		},
		function () {
			$("#mainmenu a:not(.current)").css("background-position","right 11px");
		}
	).click(function(){
		$("#mainmenu a").removeClass("current");
		$(this).addClass("current");
		$("#mainmenu a:not(.current)").css("background-position","right 11px");
	});
	//lyrics rollover setup
	$("#page-5 > .left > ul > li > a").click(function(){
		$("#page-5 > .left > ul > li").removeClass("current");
		$(this).parent().addClass("current");
	});
	
	//external link setup
	$("a[href^='http://']").each(function(){
		$(this).attr({
			href: "javascript:visit('" + $(this).attr('href') + "')"
		});
	});
	//mailto setup
	$(".mailto").each(function(){
		var name = $(this).attr("title");
		var html = "<a href='mailto:" + name + "@musician.org'>" + name + "@musician.org</a>";
		$(this).html(html);
	});
	//banner setup
	$('#rotate').innerfade({ 
		animationtype: 'fade', 
		speed: 'slow', 
		timeout: '6000', 
		type: 'random_start',
		containerheight: '100px'
	});
	//page setup
	$("#page-1").css("display","block");
	
	//gallery lightbox
	var gT = 21;
	for (var x = 1; x <= gT; x++){
		$("#gallery").append("<a href=\"/gallery/gallery-"+x+".jpg\"><img src=\"/gallery/gallery-"+x+"-t.jpg\" alt=\"\" /></a>");
	}
	$("#gallery a").attr("rel","gw").addClass("lightbox");
	$(".lightbox").lightbox();
	
	//news dates table
	$("#news > .dates > tbody > tr").each(function(){
		$(this).contents("td:eq(0)").addClass("date");
		$(this).contents("td:eq(1)").addClass("loc");
		$(this).contents("td:eq(2)").addClass("venue");
	});
});