var activated;
var homeTimeOut;
var homeMessageHidden = false;

var windowHeight = $(window).height();
var windowWidth = $(window).width();

$(function() {
	
	ContentBlockWidth();
	$(window).resize(function() {
	  	//ContentBlockWidth();
		var newWidth = $(window).width();
		if(windowWidth > newWidth){
			newWidth = windowWidth;
		}
		$('div#header').innerWidth(newWidth);
		$('div#footer').innerWidth(newWidth);
	});

	if ($.browser.msie){
		var delay = 0;
	} else {
		var delay = 500;
	}
 	
	if (($.browser.msie && $.browser.version == 7.0) ){
		if($('div.cie7f').length > 0){
			$('div#wrapper').height(500);
		}
		if($('div.home').length > 0){
			setTimeout(function(){
				var ieFixMargin = $('div.choice').find('img').height();
				//console.log(ieFixMargin);
				$('div#footer').css('margin-top',ieFixMargin-150+'px')
			},200);
		}
	}

	//homepage
	var origSource = '';
	var newSource = '';
	//$('div#home-choice div.choice').find('img').css('display','none');
//	$('div.menu li.active').prepend('<img style="position:absolute;" src="content/img/menu_arrow.png"/>');

	var homeImageWidth = $('div#home-choice div.choice').eq(0).find('img').eq(0).width();
	var homeImageHeight = $('div#home-choice div.choice').eq(0).find('img').eq(0).height();

	if(homeImageHeight == 0 ){
		homeImageHeight = windowHeight-$('div.home-message').outerHeight()-$('div#header').outerHeight()-25;
	}
	$('div#home-choice div.choice').css('height',homeImageHeight)
	$('div#home-choice div.choice').eq(1).css('border-right','2px solid #dce2e5');
	$('div#home-choice div.choice').eq(1).css('border-left','2px solid #dce2e5');
	//$('div#home-choice div.choice').find('img').css('display','block');
	$('div#home-choice div.choice').css('background-image','none');
		
	$('div#home-choice div.choice').mouseenter(function(){
			setTimeout(function(){
			 /* if(homeMessageHidden == false){
				$('div.home-message').animate({
						'height': '2px'
				},2000,'linear',function(complete){
						//$(this).hide(1000);
						footer();
				});
				homeMessageHidden = true;
			} 
				console.log('tartue'); */
			}, 2000);
			var choice = $(this);	
			choice.find('a').eq(1).css({'opacity':0,'display':'block'});
			choice.find('a').eq(0).stop().animate({
				'opacity': 0
			},500,'linear',function(complete){
				 if ($.browser.msie){choice.find('a').eq(0).find('img').addClass('invisible');};
				choice.find('a').stop().eq(1).animate({
					'opacity': 1
				},delay,'linear',function(){
				 if ($.browser.msie){choice.find('a').eq(1).find('img').removeClass('invisible');};
				})
				//choice.find('div.choice-text').toggle();
			})
		}).mouseleave(function(){
			var choice = $(this);
			//console.log('mouseLeave');
			choice.find('a').stop().eq(0).css('opacity',1);
			choice.find('a').stop().eq(1).css('opacity',0);
			if ($.browser.msie){
				choice.find('a').eq(0).find('img').removeClass('invisible');
				choice.find('a').eq(1).find('img').addClass('invisible');
			};
	});
	// contentpage
	if($('div#content-block').length){
		var dizHeight = $('div#content').height();
		var maxHeight = $('div#content-block').innerHeight();
		var setHeight = $('div#menu').height();
		var contentHeight = $('div#content-block div.text-block').height();
		if(contentHeight > 435){
				$('div#content-block div.text-block').css('height',maxHeight-77);
				$('div#content-block div.text-block').addClass('scroll-pane');
				$('.scroll-pane').jScrollPane({
						verticalDragMinHeight: 10,
						verticalDragMaxHeight: 20,
						horizontalDragMinWidth: 20,
						horizontalDragMaxWidth: 20					
					});
		} else {
			$('div#content-block div.text-block').css('overflow','hidden');
		}
	}
	if($('div#content-block div.gallery').length > 0){
		if($('div#content-block div.gallery').find('img').length > 0){
			var img = $('div#content-block div.gallery').find('img');
			img.css('opacity','0');
			img.attr('src',img.attr('src')+'?'+ new Date().getTime());
			img.load(function () {
				if(img.width() > img.height()){
					var diff  = $('div.gallery').height();
					img.css({'height':diff,'width':'auto'})
					//if(img.width() > $('div#content-block div.gallery').width()){
					//	img.css({'left':-100});
					//}
					//console.log('width>height');
				} else {
					var diff  = $('div.gallery').width();
					img.css({'width':diff,'height':'auto','display':'block','float':'right'});
					//console.log('height>width');
				}
				$('div#content-block div.gallery').css('background-image','none');
				img.animate({
					'opacity': 1
				},1000,'linear');
			});
		}
	}
	var uitgeklapt = false;
	$('div.menu-event').click(function(e){
	
		$('div#menu2, div#menu3').css({'height':'415px','left':'0','width':200,'padding':'20px 0 40px 10px'});
		//$(this).toggleClass('active');
		//$('div#menu2').toggle();
		$('div#menu ul:first, div#menu h1:first').fadeOut('slow',function(){
			$('div#menu2').fadeIn('slow');
			setTimeout(function(){
				var arrowUrl = "http://www.fhs-bv.nl/"+$('div#menu2 a').eq(0).attr('href');
				document.location.href=arrowUrl;
			},450);
		});
		//$('div#menu').animate({'left':'-'+(aniWidth)},1000,'linear',function(complete){
		//});
	});
	
	// Cufon --------------------------------------------------------------------------
		Cufon.now();

		Cufon('h1');
		Cufon('h2');
		Cufon('h3');
		Cufon('div#header ul li');
		Cufon('div#menu li');
		Cufon('div.choice-text');
		Cufon('div.home-message');
		
	
});

function ContentBlockWidth(){
	//var windowWidth = $(window).width();
	var contentBlockWidth = windowWidth-$('div.menu').outerWidth()-100;
	var contentBlockWidthPadding = $('div.menu').width()-$('div.menu').outerWidth();
	contentBlockWidth = contentBlockWidth-contentBlockWidthPadding;
	//console.log(contentBlockWidth);
	if(contentBlockWidth > 680){
		$('div#content-block').width(contentBlockWidth);
	} else {
		$('div#content-block').width(680);
	}
	$('div#footer').innerWidth(windowWidth);
	$('div#wrapper').innerWidth(windowWidth);		
}
