var isie6 = ($.browser.msie && $.browser.version.substr(0,1)<7);
var isie = $.browser.msie;

$(document).ready(function() {
	png_fix_all();
	
	Cufon.replace('.font-asenine');
	/*
	$('#nav li a').click(function() {
		var tab_name = $(this).html().replace(' ', '-');
		
		Cufon.refresh('#nav a.font-asenine');
		$('#nav a').removeClass('active');
		$(this).addClass('active');
		$('#content').attr('class', tab_name);
		
		$('#content .page').fadeOut().filter('.' + tab_name).fadeIn();
		
		return false;
	});
	*/
	setup_slideshow();
	setup_videos();
	
	/* setup directory */
	$('.page.directory .area-uk').fadeIn();
	$('.page.directory .hpt_element a').each(function() {
		var hf = $(this).parents('.photo').next().find('a').attr('href');
		$(this).attr('href', hf);
		$(this).attr('target', '_blank');
	});
	$('.page.directory ul.nav li').click(function() {
		$(this).addClass('active').siblings().removeClass('active');
		$('.page.directory ul.list').hide().filter('.area-' + $(this).find('a').attr('title').toLowerCase()).show();
		Cufon.refresh();
		return false;
	});
	
	/* setup links */
	$('.page.links div.source a').each(function() {
		$("<li></li>").append($(this)).appendTo('.page.links ul');
	});
	
});

function png_fix_all() {
	if(isie6) {
		DD_belatedPNG.fix('.pngfix');
	}
}

/* Videos */
function setup_videos() {
	$('.page.videos .vids li').click(function() {
		//alert($(this).find('.invisible a:eq(0)').html());
		jwplayer("video-player").setup({
			flashplayer: templateroot + "/jwplayer/player.swf",
			file: $(this).find('.invisible a:eq(0)').attr('href'),
			width: 525,
			height: 320,
			controlbar: 'bottom'
		});
		$('.page.videos .player').fadeIn();
		return false;
	});
}

/* Slideshow */
function setup_slideshow() {
	// On the pictures page
	$('.page.pictures .pics a').click(function() {
		var this_gal = 'gallery-' + $(this).parents('li.gallery-item').prevAll().length;
		var gal = $('.page.pictures .slideshow .' + this_gal);
		
		if( gal.length == 0 ) {
			var slides = [];
			$(this).parents('li.gallery-item').find('div.invisible a').each(function() {
				slides.push({image: $(this).attr('href'), alt: $(this).attr('title')});
			});
			gal = createGallery(slides, this_gal);
			// Create the gallery container
			gal.find('.back').click(function() {
				$(this).parents('.slideshow').fadeOut();
				$('.page.pictures .pics').fadeIn();
				return false;
			});
			
			$('.page.pictures .slideshow').append(gal);
		}	
		
		$('.page.pictures .slideshow .gallery').hide();
		$('.page.pictures .pics').fadeOut();
		$(gal).show().fadeIn();
		var gal = $('.page.pictures .slideshow').fadeIn();
		gotoSlide(gal.find('.'+this_gal), 0);
		return false;
	});
	
	// On the Play-room page
	if($('.page.playroom').length > 0) {
		var slides = [];
		$('.page.playroom a').each(function() {
			slides.push({image: $(this).attr('href'), alt: $(this).attr('title')});
		});
		//alert(slides);
		gal = createGallery(slides);
		
		$("<div class='gallery-wrap'><div class='slideshow'></div></div>").appendTo($('.page.playroom')).find('.slideshow').append(gal).fadeIn();
	}
}



