function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=110,width=420,location=no,left=200,top=200,resizable=false,scrollbars=no,toolbar=no,status=yes');
	if (window.focus) {newwindow.focus()}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

sfHover = function() {
	var sfEls = document.getElementById("navul").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

function colorboxImages()
{
	// You can add class 'nocb' to any image to prevent colorbox wrapping
	$('#content img').not('.nocb').filter(function() { return !$(this).parent('a').length == 1 }).each(function()
	{
		var img = $(this).attr("src").replace("mids", "large");
		
		$(this).wrap($('<a href="'+img+'" class="colorbox" rel="contentimages" name="'+(($(this).attr('title') && $(this).attr('title').length) ? $(this).attr('title') : $(this).attr('alt'))+'"/>'));
	}); 
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

/* Functions for active alerts swapping on home page */
function details(id)
{
	thisDiv = document.getElementById(id);
	
	//close others first
	var i = 1;
	while (document.getElementById("alert"+i)) {
		if ("alert"+i != id) {
			if (document.getElementById("alert"+i).style.display != 'none') {
				changeMarker("alert"+i,'+','-');
				new Effect.SlideUp("alert"+i, {duration:0.15,queue:'front'});
			}
		}
		i++;
	}
	changeMarker(id,'+','-');
	new Effect.toggle(thisDiv,'slide',{duration:0.35});

}

/* used in map and home page */
function changeMarker(parentDiv,state1,state2)
{
	marker = document.getElementById(parentDiv+"Marker");
 	if (marker) {
 		if (marker.innerHTML == state1) {
 			marker.innerHTML = state2;
 		} else {
 			marker.innerHTML = state1;
 		}
 	}
}

var BrowserDetect = {
 init: function () {
  this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
  this.version = this.searchVersion(navigator.userAgent)
   || this.searchVersion(navigator.appVersion)
   || "an unknown version";
  this.OS = this.searchString(this.dataOS) || "an unknown OS";
 },
 searchString: function (data) {
  for (var i=0;i<data.length;i++) {
   var dataString = data[i].string;
   var dataProp = data[i].prop;
   this.versionSearchString = data[i].versionSearch || data[i].identity;
   if (dataString) {
    if (dataString.indexOf(data[i].subString) != -1)
     return data[i].identity;
   }
   else if (dataProp)
    return data[i].identity;
  }
 },
 searchVersion: function (dataString) {
  var index = dataString.indexOf(this.versionSearchString);
  if (index == -1) return;
  return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
 },
 dataBrowser: [
  {
   string: navigator.userAgent,
   subString: "Chrome",
   identity: "Chrome"
  },
  {  string: navigator.userAgent,
   subString: "OmniWeb",
   versionSearch: "OmniWeb/",
   identity: "OmniWeb"
  },
  {
   string: navigator.vendor,
   subString: "Apple",
   identity: "Safari",
   versionSearch: "Version"
  },
  {
   prop: window.opera,
   identity: "Opera"
  },
  {
   string: navigator.vendor,
   subString: "iCab",
   identity: "iCab"
  },
  {
   string: navigator.vendor,
   subString: "KDE",
   identity: "Konqueror"
  },
  {
   string: navigator.userAgent,
   subString: "Firefox",
   identity: "Firefox"
  },
  {
   string: navigator.vendor,
   subString: "Camino",
   identity: "Camino"
  },
  {  // for newer Netscapes (6+)
   string: navigator.userAgent,
   subString: "Netscape",
   identity: "Netscape"
  },
  {
   string: navigator.userAgent,
   subString: "MSIE",
   identity: "Explorer",
   versionSearch: "MSIE"
  },
  {
   string: navigator.userAgent,
   subString: "Gecko",
   identity: "Mozilla",
   versionSearch: "rv"
  },
  {   // for older Netscapes (4-)
   string: navigator.userAgent,
   subString: "Mozilla",
   identity: "Netscape",
   versionSearch: "Mozilla"
  }
 ],
 dataOS : [
  {
   string: navigator.platform,
   subString: "Win",
   identity: "Windows"
  },
  {
   string: navigator.platform,
   subString: "Mac",
   identity: "Mac"
  },
  {
      string: navigator.userAgent,
      subString: "iPhone",
      identity: "iPhone/iPod"
     },
  {
   string: navigator.platform,
   subString: "Linux",
   identity: "Linux"
  }
 ]

};
BrowserDetect.init();


$(window).load(function(){
  $("#contentDescription img, #contentDescription img, .catDesc img").each(function(){
   if ($(this).attr("alt")) {
    

    var caption = $(this).attr("alt");
    var chars = 40;
    if (caption.length > chars) {
    	// caption = caption.substr(0,chars)+' ...';
    }
    $(this).wrap("<div class='photo-w-caption'/>");
    $(this).after("<span class='photo-caption clearfix'>"+caption+"</span>");
    
    if (BrowserDetect.browser == "Explorer") { var width = parseInt($(this).width());}
    else { var width = parseInt($(this).css("width"));}
    
    $(this).parent(".photo-w-caption").css("width",width).find(".photo-caption").css("width",width);
    $(this).parent(".photo-w-caption").find(".photo-caption").find('.photo-caption-right').css("width",width);
    if ($(this).hasClass("right")) {
    
     $(this).parent().find(".photo-caption").css("float","right").addClass("right").parent().addClass("right");
     
    }
    if ($(this).hasClass("left")) {
     $(this).parent().find(".photo-caption").css("float","left").addClass("left").parent().addClass("left");
     var align = "left";
    }
   
   }   
  });
 });
 
$(function(){
	// Colorbox initialize
	colorboxImages();
	
	// Colorbox settings
	if($.colorbox){
	    $('a.colorbox').colorbox({
	        transition: 'elastic',
	        maxHeight: '90%',
	        maxWidth: '90%',
	        opacity: 0.5,
	        fixed: true,
	        title: function(){
	        	$('#cboxClose').addClass('sixty');
	        	var title = ($(this).data('title') && $(this).data('title').length) ? '<h2 class="sixty">'+$(this).data('title')+'</h2>' : '';
	        	var caption = ($(this).data('caption') && $(this).data('caption').length) ? '<p class="forty">'+$(this).data('caption')+'<span class="after"></span></p>' : '';	        	
	            return title+caption;
	        },
	        onComplete: function(){
	        	if(!$('#cboxTitle').text().length){
	        		$('#cboxTitle').hide();
	        	}
	        }
	    });

        $('a.colorbox-video').colorbox({
	        transition: 'elastic',
		    iframe: true,
	        height: 580,
	        width: 900,
	        opacity: 0.5,
	        fixed: true,
	        title: function(){
	        	$('#cboxClose').addClass('sixty');
	        	var title = ($(this).data('title') && $(this).data('title').length) ? '<h2 class="sixty">'+$(this).data('title')+'</h2>' : '';
	        	var caption = ($(this).data('caption') && $(this).data('caption').length) ? '<p class="forty">'+$(this).data('caption')+'<span class="after"></span></p>' : '';	        	
	            return title+caption;
	        },
	        onComplete: function(){
	        	if(!$('#cboxTitle').text().length){
	        		$('#cboxTitle').hide();
	        	}
	        }
	    });
	    
	    $('#tourdateslink').colorbox({
	        transition:    'elastic',
	        iframe:        true,
	        fastIframe:    false,
	        height:        600,
	        width:         440,
	        opacity:       0.6,
	        fixed:         true,
	        title:         '<h2>Upcoming Shows</h2>'
	    });
	    
    }
     
    $('input[type="text"], input[type="email"], input[type="password"], textarea').focus(function(){
    	if($(this).val() == $(this).attr('title')) $(this).val('').addClass('active');
    });
    
    $('input[type="text"], input[type="email"], input[type="password"], textarea').blur(function(){
    	if($(this).val() == '') $(this).val($(this).attr('title')).removeClass('active');
    }); 	

	// $('.missiontext').css({ marginTop: -(0.5 * $('.missiontext').height()) });
	
	$('#playerlink').click(function(e){
        e.preventDefault();
        window.open( $(this).attr('href'), '_blank', 'width=500, height=378' );
    }); 

});

$(window).load(function(){
    
    $('#header').css({ height: 1 });
    
    var centerThumb = function(){
        if($.fn.cycle){
            $('#slideshow')
                .cycle('destroy')
                .css({ height: $(window).height() - 45 - 288})
                .children().show();
        }
        
        $('#mission').hover(function(){
            $('.slideshow-arrow').stop(true, true).fadeIn();
        }, function(){
            $('.slideshow-arrow').stop(true, true).fadeOut();
        })
        
        var centerImages = function(){
            $('.missionimage img').each(function(i, el){
                $(el).css({ marginTop: -($(el).height() / 2) });
            });
        }
        
        $.when( centerImages() ).then(function(){
            
            var start = ($('.currentSlide').index() > 0) ? $('.currentSlide').index() : 0;
            
            if($.fn.cycle){
                $('#slideshow')
                    .cycle('destroy')
                    .cycle({ 
                        fx:     'fade', 
                        speed:   750, 
                        timeout: 10000, 
                        pause:   1,
                        startingSlide: start,
                        next:   $('#slideshow-next'),
                        prev:   $('#slideshow-prev'),
                        after: function(){
                            $(this).addClass('currentSlide').siblings().removeClass('currentSlide');
                        }
                    });
            }
            
        });
        
        $('#pagethumb img').css({ marginTop: -(0.5 * $('#pagethumb img').height()) });
    }
    
    var reveal = function(){
        $('.missiontext').fadeIn(1000, function(){
            $('.missionimage img').delay(250).fadeIn(1500); 
        });
        
        $('#pagethumb img').delay(500).fadeIn(2000);
    }
    
    centerThumb();
        
    $('#slideshow').fadeIn(2000);
    
   	reveal();
   	
	$(window).resize(centerThumb);
    
	// $tt = $('#gallery-tooltip');
	
	// $('div.gallery-frame').hover(function(e){
		// $href = $(this).find('a.colorbox');
		// $('p', $tt).html($href.data('title'));
		// $tt.show();
	// }, function(){
		// $tt.hide();
	// }).mousemove(function(e){
		// $tt.css({ left: e.clientX + 20, top: e.clientY - 54 });
	// });
		
});


