var muted = false;
// Youtube API controls.
var ytplayer;
var currentSlide = 1;
var numberOfSlides = 5;

function hideAll(){
	$('div#news').hide();
	$('div#gigs').hide();
	$('div#bio').hide();
	$('div#photos').hide();
	$('div#audioVideo').hide();
	$('div#contact').hide();
	$('div#friends').hide();
	$('div#shop').hide();
	$('div#signup').hide();
}

// function nextSlide(currentSlide){
// 	if (currentSlide == numberOfSlides) {
// 		currentSlide = 1;
// 	} else{
// 		currentSlide++;
// 	}
// 	
// 	// Control the animation.
// 	$.preloadImages("_graphics/bg/" + currentSlide + ".jpg");
// 	$("#overlay").fadeOut("fast");
// 	setTimeout("changeSlide(" + currentSlide + ")", 10000);
// }
// 
// function changeSlide(currentSlide){
// 	// Called 
// 	// console.log(currentSlide);
// 	$("#overlay").fadeIn("fast", function(){
// 		$("#supersize").html('<span class="activeslide" ><img src="_graphics/bg/' + currentSlide + '.jpg" alt="bg"/></span>');
// 		nextSlide(currentSlide);
// 	});
// }

jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}


function relExternal(){
	//External links.
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
}


$(document).ready(function(){
	$("a[rel='example1']").colorbox({opacity:1});
	relExternal();
	// nextSlide(currentSlide);
	
	// $.fn.supersized.options = {  
	// 	startwidth: 1024,  
	// 	startheight: 768,
	// 	vertical_center: 1,
	// 	slideshow: 1,
	// 	navigation: 0,
	// 	transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
	// 	pause_hover: 0,
	// 	slide_counter: 1,
	// 	slide_captions: 1,
	// 	slide_interval: 200  
	// };
	//     $('#supersize').supersized();

	$(function(){
		$.fn.supersized.options = {  
			startwidth: 1200,  
			startheight: 800,
			minsize: .50,
			slideshow: 0,
			slideinterval: 5000  
		};
        $('#supersize').supersized(); 
    });

	// // Load the youtube player
	// var params = { allowScriptAccess: "always", bgcolor: "#ffffff" };
	// var atts = { id: "myytplayer" };
	// swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer","ytapiplayer", "494", "277", "8", null, null, params, atts);
	
	// hide the content...
	hideAll();
	
	$('ul#menu li.internal').click(function(){
		hideAll();
			var thisClass = $(this).attr('id');
			$('div.' + thisClass).show();
			resizeContent('div.' + thisClass,'div#contentBody',60);
			// Re bind the external links
			$('#menu').css('opacity','0.3');
			return false;
	});
	
	// close tabs
	$('a.tabClose').click(function(){ 
		$(this).parent().parent().hide();
		$('#ul_flickr').show();
		$('div#flickr div#mainPicHolder').hide();
		$('#menu').css('opacity','1.0');
		return false;
	});	
	
	$('.signupError').hide();
	
      $(".submit_btn").click(function() {
           $.post("signup_process.php",{subName:$("#subName").val(), subEmail:$("#subEmail").val(), subTown:$("#subTown").val()} ,function(data){
              if(data != 'yes'){
                  	$('.signupError').html('<p>' + data + '</p>').show('fast');
              }else{
				$('.signupError').hide('fast', function(){
						$('.signupError').html('<p>' + data + '</p>').show('fast');
					});
              		}
              });
      		return false;
      });
});

function resizeContent(element, contentElement, height){ 
	var winHeight = $(window).height();//window.innerHeight;
	//alert('height: '+height+', winHeight: '+ winHeight +', content height:'+ ((winHeight-headerHeight)-40) +', ul height: '+ ((winHeight-headerHeight)-height));
	
	var myPopoutSpace = (winHeight-220);	
	var myContentHeight = $(element).height();
	//alert(myContentHeight);
	
	if(myContentHeight > myPopoutSpace){
		$(element+' .tabClose').css('right','20px');
		$(element).css('height',myPopoutSpace+'px');
		$(element).css('bottom','50px');
		$(element).children('div.contentBody').css('height',myPopoutSpace+'px');		
	}
	
	//alert(contentElement +': '+ $(element).children('div.contentBody').children(contentElement).height());
	//alert($(element).height());
	return false;
}


	// Function to parse the URL - Rob - going to use it to get the videoString if its in the url.
	// function gup( name )
	// {
	//   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	//   var regexS = "[\\?&]"+name+"=([^&#]*)";
	//   var regex = new RegExp( regexS );
	//   var results = regex.exec( window.location.href );
	//   if( results == null )
	//     return "";
	//   else
	//     return results[1];
	// }
	// 	
	// function onYouTubePlayerReady(playerId) {
	//     ytplayer = document.getElementById('myytplayer');
	// 	if(ytplayer){
	// 		setInterval(updateytplayerInfo, 250);
	// 		updateytplayerInfo();
	// 		ytplayer.addEventListener('onStateChange', 'onytplayerStateChange');
	// 	}
	//  	// Load a video on player ready. If there is a video id in the url use that else load the default band vid.
	// 	
	// }
	// 
	// function onytplayerStateChange(newState) {
	//      setytplayerState(newState);
	// }
	// 
	// function updateytplayerInfo() {
	//     if (ytplayer) {
	//         updateTimebar();
	// 		updateBufferbar();
	//     }
	// }
	// 
	// function updateTimebar() {
	//     var all = ytplayer.getDuration();
	//     var part = ytplayer.getCurrentTime();
	//     var percent = getPercent(all, part);
	//     var timebarWidth = 325;
	//     document.getElementById('timebarIndicator').style.width = percent * (timebarWidth / 100) + "px";
	// }
	// 
	// function getPercent(all, part) {
	//    return (all > 0) ? (100 / all) * part : 0;
	// }
	// 
	// function updateBufferbar() {
	//     var all = ytplayer.getVideoBytesTotal();
	//     var part = ytplayer.getVideoBytesLoaded();
	//     var percent = getPercent(all, part);
	//     var bufferbarWidth = 325;
	//     document.getElementById('bufferbarIndicator').style.width = percent * (bufferbarWidth / 100) + "px";
	// }
	// 
	// function toggleMute() {
	// 	muted = !muted;
	// 	muted ?	bImg = 'mute_on' : bImg = 'mute_off';
	// 	muted ?	txt = 'Turn sound on' : txt = 'Turn sound off';
	// 	muteVideo(muted);
	// 	//$('a#soundControl').css('background-image',"url('../_graphics/" + bImg + ".png')");
	// 	$('a#soundControl').html(txt);
	// }
	// 
	// function muteVideo(mute){
	// 	swfobject.getObjectById("flash")._muteVideo(mute);
	// 	// return false;
	// }
	// 
	// function pauseVideo(pause){
	// 	if (!pause && ytplayer){
	// 		ytplayer.pauseVideo();
	// 		// swfobject.getObjectById("flash")._pauseVideo(pause);
	// 	}
	// 	// return false;
	// }
	// 
	// function playVideo(video,num){		
	// 	if (ytplayer){
	// 		ytplayer.loadVideoById(video,num);
	// 	}
	// }
	// 
	// function play(){
	// 	ytplayer.playVideo();
	// }



