var html = '';

page_image_click = function() {	
	var href = this.href.replace('index.php', 'ajax.php');
	
	page_information_hide_click
	
	$.get(href, {}, page_image_load);
	
	$('#image img.image').fadeOut('3', page_image_show);
	$('#image').addClass('loading');
	$('#image').css('height', $('#image img.image').height() + 'px');
	
	page_information_hide_click
	
	return false;
}

page_image_load = function(data) {
	html = data;
}

page_image_show = function() {
	if (html) {
		$('#image').html(html);
		$('#image img.image').hide();
		$('#image img.image').fadeIn('2000');
		page_init();
		$('#image').css('height', '');
	}
	else {
		$('#image img.image').fadeIn('3');
	}
	
	$('#image').removeClass('loading');
}

page_information_click = function() {
	$('div.information').toggle();
	
	return false;
}

page_information_hide_click = function() {
	$('div.information').hide();
	
	return false;
}

show_video_click = function() {
	var anchor = $(this);
	
	$('.navigation a.active').removeClass('active');
	$('.video-links .active').removeClass('active');
	
	anchor.addClass('active');
	
	if (jwplayer()) {
		jwplayer().destroy();
	}
	
	$('.content *').hide();
	$('#video-container').html('');
	$('#video-container').show();

	if (anchor.attr('href') && anchor.attr('href').indexOf('vimeo')) {
		$('#video-container').html('<iframe src="http://player.vimeo.com/video/21303116?portrait=0&amp;color=F6894D&amp;autoplay=1" width="740" height="490" frameborder="0"></iframe>')
	}
	else {
		jwplayer("video-container").setup({
			autostart: true,
			controlbar: "over",
			file: "/files/AmelieLosier-201102-Berlinale.mp4",
			flashplayer: "/contrib/jwplayer/player.swf",
			volume: 80,
			width: 740,
			height: 494
		});
	}
	
	return false;
};

page_init = function() {
	$('div.information').hide();
	
	$('#image a.pager').click(page_image_click);
	$('#image a.information').click(page_information_click);
	$('#image div.information').click(page_information_hide_click);
	
	$('.video').click(show_video_click);
}

$(document).ready(function() {
	page_init();
});
