// JavaScript Document

function showComment(nid){
	var currentTime = new Date();
		
	$.ajax({
	  url: '/node/'+nid+'/t='+currentTime,
	  success: function(data) {
		 
		$("#contentc").html($(data).find('#contentc').html());
		
	  }
	});
	//$("#content-area").html();
}
// Find out the Flash Player version installed
function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
  
}

// Display upgrade Flash message instead of video
function upgradeFlashMessage(version, minVersion){
  // get stillImage
  var stillImage = $("div#flashplayer img").attr("src");
	
  var upgradeHtml = '<img src="' + stillImage + '" width="480" height="270" alt="" />';
  upgradeHtml += '<p id="flashMessage1">To view this video you need to install the latest version of <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe Flash Player</a></p>';
  if(version > 1) {
  	upgradeHtml += '<p id="flashMessage2">You have Flash Player ' + version + '. You need Flash Player ' + minVersion + ' or above.</p>';
  } else {
  	upgradeHtml += '<p id="flashMessage2">You don\'t have Flash Player installed. You need Flash Player ' + minVersion + ' or above.</p>';  
  }
  $("div#flashplayer").empty();
  $("div#flashplayer").append(upgradeHtml);
}

// test which Flash version
function testFlashVersion(minVersion) {
	var version = getFlashVersion().split(',').shift(); 
	if(version < minVersion){ 
  		upgradeFlashMessage(version, minVersion);
	}
}



// Adjust the length of Timeline for a snug fit
function timeLineLength() {
	$timelineEntries = $("#content li").length;
	$newtimeLineWidth = ($timelineEntries * 261 + 10) + "px";
	$(".view-content-timeline ul").css("width", $newtimeLineWidth);
	
}


$(document).ready(function(){
	// Adjust the length of Timeline for a snug fit
	timeLineLength();
	
	// Link the latest photos images to the image gallery
	$(".view-content-latestphotos img").wrap('<a href="/image"></a>');
	
	// Link the random sponsor to the sponsors page
	$(".view-content-sponsor-random").wrap('<a href="/supporters""></a>');
	
	
	if($("#flashplayer").length > 0) {
		 testFlashVersion(8); // Minimum flash version required
	}
	
//	if($("#block-views-slideshow").length > 0) {
//		 readySlideshow();
//	}
		
	
});



/********** Slideshow ****************/
var currentSlide = 0;
var totalSlides = 0;

function readySlideshow(){
	addOrderIds();
	slideShortcuts()						   
	$('#block-views-slideshow .item-list li').hide();
	
	currentSlide = 0;
	totalSlides = $('#block-views-slideshow .item-list li').size();

	runSlideShow();
	
	

}

function addOrderIds() {
	var count = 0;
	$('#block-views-slideshow .item-list li').each(function() {
		count++;
		$(this).addClass('slide' + count);
	});
}


function slideShortcuts() {
	var count = 0;
	var output = '<div id="slideshow-controls"><div class="pause"><a href="#">Pause</a></div><ul>';
	
	$('#block-views-slideshow .item-list li').each(function() {
		count++;
		output += "<li>" + count + "</li>";
	});
	output += "</ul></div>";
	
	$('#block-views-slideshow .view-content').after(output);
	
	
	$('#slideshow-controls li').click( function() {
		clearInterval(slideInterval);
		$('#slideshow-controls .pause a').text('Play');
		$('#slideshow-controls .pause').addClass('play');
		
		currentSlide = $(this).text();
		$('#block-views-slideshow .item-list li').hide();
		$('.slide' + currentSlide).show();
		
		activeShortcut();
												
	});
	
	
	// Play and pause button
	// variable is tested and breaks the loop
	$('#slideshow-controls .pause a').click(function() {
		if($(this).text() == 'Pause') {
			clearInterval(slideInterval);
			$(this).text('Play');
			$('#slideshow-controls .pause').addClass('play');
		} else {
			runSlideShow();
			$(this).text('Pause');
			$('#slideshow-controls .pause').removeClass('play');
		}
		$(this).blur();
		return false;
	});
	
	$('#slideshow-controls').hide();
	
/*	$('#block-views-slideshow .view-content, #slideshow-controls, #slideshow-controls div, #slideshow-controls ul, #slideshow-controls a, #slideshow-controls li').hover(
      function () {
        $('#slideshow-controls').show();
      }, 
      function () {
        $('#slideshow-controls').hide();
      }
    );
*/
	$('#block-views-slideshow .view-content, #slideshow-controls, #slideshow-controls div, #slideshow-controls ul, #slideshow-controls a, #slideshow-controls li').mouseover(function() {
		$('#slideshow-controls').show();
	});
	$('#block-views-slideshow .view-content').mouseout(function() {
		$('#slideshow-controls').hide();
	});

}


function runSlideShow() {
  nextSlide();
  slideInterval = setInterval(nextSlide, 5000);	
}


function nextSlide() {
	
	currentSlide++;
	
	activeShortcut();
	
	// if no more slides go to first else goto next
	if(currentSlide > totalSlides) {
	  currentSlide = 1;
	  activeShortcut()
	  $('#block-views-slideshow .item-list li').hide();
	  $('.slide1').show();
	  $('.slide' + totalSlides).show().fadeOut(3000);
	} else {
	  $(".slide"  + currentSlide).fadeIn(3000);
 
	}
}


function activeShortcut() {
	$("#slideshow-controls li").removeClass('active');
	$("#slideshow-controls li:contains('" + currentSlide + "')").addClass('active');
}

<!--
var formPass = true;

function displayOptions(divId)
{
	if(document.getElementById(divId).style.display == 'none'){
		document.getElementById(divId).style.display = 'block';
	}else{
		document.getElementById(divId).style.display = 'none';
	}
}


function checkForm() {

	formPass = true;

	if(document.email.message.value.length < 2) {
		document.email.message.className ="highlight";
		formPass = false;
	}
	if(document.email.yourName.value.length < 2) {
		document.email.yourName.className ="highlight";
		formPass = false;
	}
	if(document.email.yourEmail.value.length < 5 || document.email.yourEmail.value.indexOf('@') == '-1') {
		document.email.yourEmail.className ="highlight";
		formPass = false;
	}
	return formPass;

}


