$(document).ready(function() {

	$('#home .start_big_button').css('display','inline-block');

	if (!$.browser.msie || $.browser.msie && $.browser.version > 6) {
	
		$("#main_home_illustration").hover(function () {
			$('#home .start_big_button').addClass('hover');
		}, function () {
			$('#home .start_big_button').removeClass('hover');
		});
	
	};
	
	// JS ON - FLASH OFF
	var flash_player = swfobject.getFlashPlayerVersion();

	if (flash_player.major<9) {
		$('#intro_flash_off').show();
		$('.start_big_button').hide();
		$('#intro_js_on').hide();
	}
	else {
		$('#intro_js_off').hide();
		$('#intro_js_on').show();
		$('#home .start_big_button').css('display','inline-block');
		$("#main_home_illustration").click(function(){
			$('#home .start_big_button').click();
		});
	}
	
	$('#intro ul li').prepend('<span></span>');
	
	var in_progress = false;
	$('<li id="divider"></li>').insertAfter($('#site_nav_sections .site_nav_section .section_content.last').parent());
	$('#site_nav_sections .site_nav_section .section_content').hide();
	$('#site_nav').prepend('<div id="selected_slide"></div>');
	$('#site_nav_sections .site_nav_section .section_content').eq(0).show();

	if ($('#site_nav_sections .site_nav_section h3.selected').length==0) {
		$('#site_nav_sections .site_nav_section > h3:not(.selected)').click(function(){
			$('#site_nav_sections .site_nav_section > h3').removeClass('selected');
			$(this).addClass('active');
			switchSection($(this).next('.section_content'));
		});
	}
	
//Slide show initialisation
	var cur_slide = $('#site_nav_sections .site_nav_section .section_content').eq(0);
	fluidContent(cur_slide);
	var rotation;
	var initial_position = 50;
	var position = initial_position;
	var slide_unit = 50;

	function fluidContent(content) {
		if (!$.browser.msie || $.browser.version > 6) {
			var content_height = $(content).innerHeight();
			var site_nav_height=490
			if (content_height>400) {site_nav_height = content_height+100}
			$('#site_nav').css('height',site_nav_height);
		}
	}
	
	function switchSection(section){
		$('#site_nav_sections .site_nav_section .section_content').fadeOut('fast').next('.types_all').fadeOut();
		
		$(section).fadeIn(function(){
			$('#site_nav_sections .site_nav_section > h3').removeClass('selected');
			$(section).prev('h3').removeClass('active').addClass('selected');
		}).next('.types_all').fadeIn();
		$('#selected_slide').fadeOut();
		fluidContent(section);
	}
		
	function sectionsSlideshow() {
		$('#selected_slide').css('top',position+'px').show();
		cur_slide.fadeOut().next('.types_all').fadeOut();
		$('#site_nav_sections h3').removeClass('selected');
		if (cur_slide.is('.last')) {
			cur_slide = $('#site_nav_sections .site_nav_section .section_content').eq(0);
			cur_slide.fadeIn().next('.types_all').fadeIn();
			$('#selected_slide').animate({top: initial_position}, 100,function(){in_progress=false;});
			position = initial_position;

		}
		else {
			cur_slide = cur_slide.parent().next().find('.section_content');
			cur_slide.fadeIn().next('.types_all').fadeIn();
			$('#selected_slide').animate({top: position+slide_unit}, 300,function(){in_progress=false;});
			position=position+slide_unit;
		}
		fluidContent(cur_slide);
	}
	
	if (!$.browser.msie || $.browser.version > 7) {
	//rotation = setInterval(sectionsSlideshow, 3000 );
	
	$('#site_nav').hover(function(){
		clearInterval(rotation);
/*		},function(){
			cur_slide = $('#site_nav_sections .site_nav_section .section_content').eq(0);
			position = initial_position;
			switchSection($('#site_nav_sections .site_nav_section > h3').eq(0).next('.section_content'));
			rotation = setInterval(sectionsSlideshow, 3000 );
			
*/
	});
	$('#site_nav').click(function(){clearInterval(rotation);});
	}
	
	// click box magic
	if (!$.browser.msie || $.browser.msie && $.browser.version > 6) {
		//clickBox();
	}
	
});