$(document).ready( function() { //When the document is ready

/* -------------------- EXTERNAL LINKS - */
$('a[href^="http://"],a[href^="https://"]')
.attr({
	target: "_blank", 
	title: "Opens in a new window"
});

/* -------------------- SHOW & HIDE TEXT INPUT VALUES - */
$('input[type="text"], textarea').focus(function() {
	value=$(this).val();
	$(this).attr("value","");
});
$('input[type="text"], textarea').blur(function() {
	if($(this).val()=="") {
		$(this).val(value);
	}
});

/* -------------------- ACCORDION - */
$(".accordion").addClass('jsActive');
$(".accordion div .title").css({'cursor' : 'pointer'});
$(".accordion div .firstTitle").addClass('on');
$(".accordion div div").hide();
$(".accordion div div.firstContent").show();
$(".accordion .title").click( function(){	
	if($(this).parent('div').children('div').is(":hidden")){		
		$(this).parent('div').parent('.accordion').children('div').children('.title').removeClass('on');
		$(this).parent('div').parent('.accordion').children('div').children('div').slideUp('fast');
		$(this).addClass('on');
		$(this).parent('div').children('div').slideDown('fast');
	}
})

/* -------------------- ACCORDION (course page module list) - */
$("#moduleList").addClass('jsActive');
$("#moduleList dt").css({'cursor' : 'pointer'});
$("#moduleList dd").hide();
$("#moduleList dt").click( function(){
	if($(this).next('dd').is(":hidden")){
		$(this).addClass('on');
		$(this).next('dd').slideDown('fast');
	}else{
		$(this).removeClass('on');
		$(this).next('dd').slideUp('fast');
	}
})

/* -------------------- TABBED CONTENT (homepage) - */
$(".feature").hide();
$(".tab0Content").show();
$('#featureTabs li a').click( function(){
	$('#featureTabs li').removeClass("on");
	var tabNo = $(this).parent('li').attr('class');
	$(this).parent('li').addClass("on");
	$('.feature').hide();
	$("." + tabNo + "Content").show()
	return false;
});

/* -------------------- TABBED CONTENT (course page) - */

$('.overviewContent').addClass("hiddenTab");
$("#tabOverviewContent").removeClass("hiddenTab");
$('.overviewTabs li a').click( function(){
	$('.overviewTabs li').removeClass("on");
	var tabName = $(this).parent('li').attr('class');
	$(this).parent('li').addClass("on");
	$('.overviewContent').addClass("hiddenTab");
	$("#" + tabName + "Content").removeClass("hiddenTab");
	return false;
});

/* -------------------- SHOW & HIDE A TO Z INDEX - */
$('#atozIndex').prepend('<li><a class="on" href="#All">All</a></li>');
$('#atozIndex li a').click( function(){
	var letter = $(this).text();
	if (letter == "All"){
		$('#atozList li').show();
		$('#atozIndex li a').removeClass("on");
		$(this).addClass("on");
	}else{
		$('#atozIndex li a').removeClass("on");
		$(this).addClass("on");
		$('#atozList li').hide();
		$('li#' + letter).show();
		$('li#' + letter + ' li').show();
	}
	return false;
});

/* -------------------- GALLERIFFIC - */
var gallery = $('#gallery').galleriffic('#thumbs', {
	delay:                  3000, // in milliseconds
	numThumbs:              3, // The number of thumbnails to show page 
	preloadAhead:           40, // Set to -1 to preload all images
	enableTopPager:         false,
	enableBottomPager:      false,
	imageContainerSel:      '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
	controlsContainerSel:   '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
	captionContainerSel:    '#caption', // The CSS selector for the element within which the captions should be rendered
	loadingContainerSel:    '#loading', // The CSS selector for the element within which should be shown when an image is loading
	renderSSControls:       false, // Specifies whether the slideshow's Play and Pause links should be rendered
	renderNavControls:      true, // Specifies whether the slideshow's Next and Previous links should be rendered
	playLinkText:           'Play',
	pauseLinkText:          'Pause',
	prevLinkText:           '&lt;&lt; Previous',
	nextLinkText:           'Next &gt;&gt;',
	nextPageLinkText:       'Next &gt;&gt;',
	prevPageLinkText:       '&lt;&lt; Previous',
	enableHistory:          false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes 
	autoStart:              false, // Specifies whether the slideshow should be playing or paused when the page first loads 
	onChange:               undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
	onTransitionOut:        undefined, // accepts a delegate like such: function(callback) { ... }
	onTransitionIn:         undefined, // accepts a delegate like such: function() { ... }
	onPageTransitionOut:    undefined, // accepts a delegate like such: function(callback) { ... }
	onPageTransitionIn:     undefined  // accepts a delegate like such: function() { ... }
});			
$('#gallery').addClass('add-js-styles');
$('#gallery #pageBeforeThis').append('<a href="javascript: history.go(-1)">Back to previous page</a>');

}); //End When the document is ready
