var currentheader = 1;
var amountheader;
var stop_header = false;
$(document).ready(function(){
	// vars
	$('#header1').clone().appendTo('#slider ul');
	amountheader = $('#slider ul li').length;

	// functions
	doCufon();
	flashMessage();
	inputDefaults();
	
	setInterval("nextheader();", 6000);
	
	//launch function on initialize
	if(window.location.hash == '#sjonicthemovie'){
		stop_header = true;
		goToHeaderMovieAndPlay();
	}
	$("a[href$='#sjonicthemovie']").click(function(){
		stop_header = true;
		goToHeaderMovieAndPlay();
		return false;
	});
	
	scaleColumnToSameSize();

	loadAjaxForm();
});

function loadAjaxForm() {
	wrap_box = $('#contact_ajax_form');
	form = $('form#ContactHomeContactForm');
	form_action = form.attr('action');

	wrap_box.html('<img src="'+webroot+'img/icons/ajax-loader-white.gif" />');
	$.ajax({
		type: "POST",
		url: webroot+"home_contact/",
		success: function(msg){
			wrap_box.html(msg);
		}
	});
}

function nextheader() {
	if (stop_header==false) {
		if (currentheader==amountheader) {
			$('#slider ul').css('marginLeft', '-960px');
			currentheader = 1;
		}
		if (currentheader < amountheader) {
			pos = -960 + 1920 + (1920*currentheader);
			$('#slider ul').animate({marginLeft: '-'+pos+'px'}, 2200, 'easeInOutCubic', function() {
				currentheader++;
			});
		}
	}
}

function scaleColumnToSameSize(){
	if($("#left_coll").height() != $("#main").height()){
		var top = $("#main").height()-364;
		$("div#sjon_image_box").css('padding','0');
		$("div#sjon_image_box").css('top',top);
		$("div#sjon_image_box").css('position','absolute');
		$("div#left_coll").css('position','relative');
	}
}

function goToHeaderMovieAndPlay(){
	$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
	pos = -960 + 1920;
	if (currentheader!==1) {
		$('#slider ul').animate({marginLeft: '-'+pos+'px'}, 1000, 'easeInOutCubic');
	}
	$('#header1:first').addClass("movie_head");
	$('#header1:first').flash({src: '/files/bedrijfsfilm.swf', width: 1066, height: 600, wmode:'transparent'}, { version: 8 });
}

function doCufon() {
	Cufon.replace('ul#navigation li a', {hover: true, fontFamily: 'Bebas'});
	Cufon.replace('div#inrip', {hover: true, fontFamily: 'Bebas'});
	Cufon.replace('h3', {fontFamily: 'Bebas'});
	Cufon.replace('h3 span', {fontFamily: 'Bebas'});
	Cufon.replace('h2', {hover: true, fontFamily: 'Georgia'});
	Cufon.replace('div.block_top h3', {hover: true, fontFamily: 'Georgia'});
	Cufon.replace('div#footer h3', {fontFamily: 'Bebas'});
}
function flashMessage() {
	//#flashMessage
}

/*
function doHeaderActions() {
	$('div#header div#slider ul li#header1 a')
	.css('opacity', 0)
	.animate({'opacity':0.0}, 1000)
	.show()
	.animate({'opacity':1.0}, 2000, 'easeInOutCubic', function() {
		headerFadeInOut();
		setInterval("headerFadeInOut()", 3000 );
	});
	
	// 2011-03-29 modified by Bart
	// split up the animation and event listener and added an extra element to the listeren (.watch_sjonic_movie)
	$('div#header div#slider ul li#header1 a, .watch_sjonic_movie').click(function(){
		goToHeaderMovieAndPlay();
		return false;
	});
}
function headerFadeInOut() {
	$('div#header div#slider ul li#header1 a img')
	.animate({'opacity':0.4}, 1500, 'easeInOutQuad')
	.animate({'opacity':1.0}, 1500, 'easeInOutQuad');
}
function checkFlashForHeader(){
	if(swfobject.hasFlashPlayerVersion("1")){
		doHeaderActions();
	}
	else{
		$('div#header div#slider ul li#header1 a').css('opacity', 0);
	}
}
*/
