/* Tells jQuery to do all the following code once the body has loaded */
$(document).ready(function(){

		
	
	/* ***************************************
	OPEN LINKS IN NEW WINDOW	
	1. Looks for all links with rel="external" and opens them in a new window
	2. Adds custom title attribute based on file type
	*************************************** */	
	/* General Links */
	$('#content-main a[rel="external"], #content-main .boxer_link, #footer a[rel="external"]').attr('title','External link - Opens in a new window').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
	
	/* Transcripts Media Links */
	$('#content-main .boxer_link').attr('title','Related link - Opens in a new window')
	
	
	
	/* ***************************************
	FANCYBOX LIGHTBOX PLUGIN
	*************************************** */
	/* Image Gallery */
	$(".fancybox").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });
	
	/* Image pop-ups in transcripts */
	$(".boxer_image").fancybox({ 
		'hideOnContentClick': false, 
		'overlayOpacity': 0
	}); 
	
	/* Audio pop-ups in transcripts */
	$(".boxer_audio").fancybox({ 
		'hideOnContentClick': false, 
		'overlayOpacity': 0,
		'frameWidth': 300, //Need to look at width on this any less and we get scroll bars..
		'frameHeight': 24, 
		'hideOnOverlayClick': false, 
		'overlayShow': false
	});
						   
						   
						   
	/* ***************************************
	TABS/PAGINATION	
	*************************************** */
	$(function() {
		var $tabs = $('#tabs').tabs();
		$(".ui-tabs-panel").append('<ul class="pagination-links"></ul>');
		$(".ui-tabs-panel .pagination-links").each(function(i){
			var totalSize = $(".ui-tabs-panel").size() - 1;
			if (i != totalSize) {
				next = i + 2;
				$(this).append("<li><a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a></li>");
			}
			if (i != 0) {
				prev = i;
   		  		$(this).append("<li><a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a></li>");
	  		}
		});
	$('.next-tab, .prev-tab').click(function() {
		$tabs.tabs('select', $(this).attr("rel")), scroll(0,0);
        return false;
       });

	});
						   
		
		
	/* ***************************************
	PRINT ICON	
	*************************************** */
	var domain = location.hostname; 
	if (domain == "192.168.2.17") { 
		var baseUrl = 'http://192.168.2.17/siobhandavies/conversations/'; 
	}
	else if (domain == "bulletclip.com") { 
		var baseUrl = 'http://bulletclip.com/development/siobhandaviesconversations/website/'; 
	}
	else { 
		var baseUrl = 'http://www.siobhandavies.com/conversations/'; 
	};
	
	$('#content-main').prepend('<ul id="tools"><li id="print"><a href="#print"><img src="'+baseUrl+'media/ui/icon-print.png" width="14" height="14" alt="Print this page" /></a></li></ul>');
		$('#tools #print a').click(function() {
			window.print();
			return false;
		});
	
	
	/* ***************************************
	CYCLE LITE SLIDESHOW	
	*************************************** */
	
		// Events - Paul Clark & Katie Mitchell
		$('.km-pc #event-images div').after('<div><img src="../media/events/mitchell-clark2.jpg" width="252" height="189" alt="" /><p>Paul Clark and Katie Mitchell in conversation</p></div> <div><img src="../media/events/mitchell-clark3.jpg" width="252" height="336" alt="" /><p>Paul Clark and Katie Mitchell in conversation</p></div> <div><img src="../media/events/mitchell-clark4.jpg" width="252" height="336" alt="" /><p>Paul Clark and Katie Mitchell in conversation</p></div> <div><img src="../media/events/mitchell-clark5.jpg" width="252" height="336" alt="" /><p>Paul Clark and Katie Mitchell in conversation</p></div>');
		
		// Events - Heather Ackroyd & Leslie Forbes
		$('.ha-lf #event-images div').after('<div><img src="../media/events/ackroyd-forbes2.jpg" width="252" height="336" alt="" /><p>Heather Ackroyd and Leslie Forbes in conversation</p></div>');
		
		// Events - Edmund de Waal & A S Byatt
		$('.ew-ab #event-images div').after('<div><img src="../media/events/dewaal-byatt2.jpg" width="252" height="336" alt="" /><p>Edmund de Waal and A S Byatt in conversation</p></div>');
		
		// Events - Tim Crouch & Karl James
		$('.tc-kj #event-images div').after('<div><img src="../media/events/crouch-james2.jpg" width="252" height="189" alt="" /><p>Tim Crouch and Karl James in conversation</p></div>');
		
		/* Make it work */
		$('#event-images').after('<p><a href="#" id="back">&lsaquo; Previous</a> <a href="#" id="next">Next &rsaquo;</a></p>');
		$('#event-images').cycle({ fx: 'fade', speed:  1000, timeout:  0, prev: '#back', next: '#next' });

		
		
/* ***************************************
DON'T DELETE - End of code run once body has loaded
*************************************** */
});	