 	$('html').addClass('js');



	// Open all external links in new window
	function externalLinks() {
		$('#content a[href^="http://"]:not(.jPlayer):not(:has(img))')
			.attr({
				target: "_blank", 
				title: "Opens in a new window"
			})
			.addClass('external');
	}

	// float alternate images to the right
	function floatImages() {
		$('#hijaxDisplay img:even').addClass('float-right');
		$('#hijaxDisplay img:odd').addClass('float-left');
		$('body.blog #hijaxDisplay img').removeClass('float-right').addClass('float-left');
		$('body.blog #hijaxDisplay img').removeClass('float-right').addClass('float-left');
	}
	
	// general #content functions
	function contentFunctions() {
		externalLinks();
		floatImages();
	}



	function fnStartGrid(sUrl) {
		var nScript = document.createElement('script');
		nScript.setAttribute('language','JavaScript');
		nScript.setAttribute('src',sUrl);
		document.body.appendChild(nScript);
	}


	
	$(function () {

		// general #content functions
		contentFunctions();

		// Run functions on AJAX content
		$('#hijaxDisplay').ajaxComplete(function() {
			contentFunctions();
		});
		
		// RECORDINGS
		$('body.recordings #recordingChoose').show();
		
		$('body.recordings #hijaxLinks li.type-G').hide();

		$('body.recordings #recordingChoose a').click(function() {
			$('body.recordings #hijaxLinks li').hide();
			$('body.recordings #recordingChoose a').removeClass('active');
			$('body.recordings #hijaxLinks li.' + this.id).fadeIn();
			$(this).addClass('active');
			return false;
		});


		// BLOG comments popup
		$('body.blog a.addComment').attr("href", function () {
			return $(this).attr("href") + '?ajax=true';
		});


		// GRID
		$('body').dblclick(function() {
// 			fnStartGrid('http://www.sprymedia.co.uk/design/grid/media/js/grid-loader.js');
// 			fnStartGrid('http://localhost/test/grid/js/grid-loader.js');
		});
		$('#frame').dblclick(function() {
			return false;
		});


		// Diary
		$('body.dates div.programme').hide();
		$('body.dates a.programmeDetailsToggle').show();
		$('body.dates a.programmeDetailsToggle').click(function() {
			$(this).parent().siblings('div.programme').toggle();
		});


		// Fake CSS3 for IE
		$("ul li:first-child, tr.header:first-child").addClass("first-child");
		$("ul li:last-child, body.default.index #images img:last-child, blockquote > p:last-child, body.dates div.concert:last-child, tr:last-child").addClass("last-child");
		
		
		// iPhone fix for nav menu
		$('ul.navigation li').click(function() {
			$(this).trigger('hover');
		});
		
		
		// Audio popup window
// 		$('#audioLink a').click(function() {
// 			var topPos  = 120;
// 			var leftPos = screen.width - 470;
// 
// 			window.open(this.href, 'audio_popup', 
// 				'height=520,width=430,toolbar=0,scrollbars=0,'
// 				+ 'status=0,resizable=0,location=0,menuBar=0,'
// 				+ 'left=' + leftPos +',top=' + topPos)
// 			.focus();
// 			
// 			return false;
// 		});
		$('#audioLink a').attr({
			target: "_blank", 
			title: "Opens in a new window - disable your pop-up blocker first!"
		});
		

		// Audio tracks for sale
		$('body.audio table.tracksForSale tbody.tracks').hide();
		$('body.audio table.tracksForSale tr.trackReveal').show();
		$('body.audio table.tracksForSale tr.trackReveal a').click(function() {
			$('body.audio table.tracksForSale tbody.tracks').show();
			$('body.audio table.tracksForSale tr.trackReveal').hide();
			return false;
		});

		// Audio add to cart ajax
		$('body.audio a.addToCart').click(function() {
			var url = $(this).attr('href') + '/format/html';
			
			$.get(url, function(data) {
				$('#hijaxLinks').html(data);

				if ($('body').scrollTop() > $('#hijaxLinks').offset().top) {
					$.scrollTo($('#hijaxLinks').offset().top, 600);
				}

				$('#hijaxLinks').pulse({
						opacity: [0.3, 1]
				}, 800, 2, 'swing');

			});
			
			return false;
		});

  
	});