/**
 * @author Johan Huijkman, Eden design & communication
 */
//	::::::::::::::::::::::::: start Add javascript specific stylesheet:
var head = $('<link rel="stylesheet" href="../style/js-enabled.css" type="text/css" media="screen" />').appendTo($('head')[0]);
//	::::::::::::::::::::::::: end Add javascript specific stylesheet


//	:::::::::::::::::::::::::::::: start onload function calls

$(document).ready(function() {
	
//	:::::::::::::::::::::::::::::: Start hover functionality	
	//hover submit knoppen:
	$(':image').each(function(){
		$(this).hover(function() {
			$(this).attr('src',$(this).attr('src').replace('.gif','-ro.gif'));
		}, function() {
			$(this).attr('src',$(this).attr('src').replace('-ro.gif','.gif'));
		});
	});
	$(':submit').each(function(){
		$(this).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	});
	$('.submit-filter').each(function(){
		$(this).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	});
//	:::::::::::::::::::::::::::::: End hover functionality	

//	:::::::::::::::::::::::::::::: Start Embed logo animation
	if($("body:first").hasClass('home')){
		$('h1').append('<div id="logo-animation"><div id="animation-object"></div></div>');
		var flashvars = {};
		var params = { menu: "false", wmode: "transparent"};
		var attributes = {};
		swfobject.embedSWF("../media/logo-animation.swf", "animation-object", "200", "34", "9.0.0","", flashvars, params, attributes);
	}	
//	:::::::::::::::::::::::::::::: End Embed logo animation

//	:::::::::::::::::::::::::::::: Start function calls

	FunctSitemap.init();
	FunctInfoForDropDown.init();
	FunctSectionNav.init();
	FunctDetailNav.init();
	FunctFeatures.init();
	FunctHilites.init();
	FunctFaq.init();
	FunctSiteSearch.init();	
	
	FunctMapsNav.init();
	FunctOverlay.init();
	
	//	:::::::::::::::::::::::::::::: End function calls
});

//	:::::::::::::::::::::::::::::: end onload function calls

//	:::::::::::::::::::::::::::::: Start Sitemap
FunctSitemap = {
	init:function(){
		//alert(jQuery.browser.version);
		$('#sitemap').prepend('<a href="[link]" class="show-sitemap">Toon sitemap</a>');
		$('a.show-sitemap').click(function(){
			if($(this).hasClass('show-sitemap')){
				//if(jQuery.browser.msie && jQuery.browser.version == '6.0') $('#sitemap ul.col-sitemap').show();
				//else $('#sitemap ul.col-sitemap').show('normal');
				$('#sitemap ul.col-sitemap').show();
				$(this).removeClass('show-sitemap').addClass('hide-sitemap');
				$(this).html('Verberg sitemap');
			}else{
				//if(jQuery.browser.msie && jQuery.browser.version == '6.0') $('#sitemap ul.col-sitemap').hide();
				//else $('#sitemap ul.col-sitemap').hide('normal');
				$('#sitemap ul.col-sitemap').hide();
				$(this).removeClass('hide-sitemap').addClass('show-sitemap');
				$(this).html('Toon sitemap');
			}
			return false;
		})
	}
}
//	:::::::::::::::::::::::::::::: End Sitemap

//	:::::::::::::::::::::::::::::: Start Info Dropdown
FunctInfoForDropDown = {
	hideTimer: null,
	init:function(){
		$('#page-container').prepend('<ul id="list-info-for"></ul>');
		$('#info-for select option').each(function(){
			if($('#info-for select option').index(this)>0) $('#list-info-for').append('<li><a href="">'+$(this).html()+'</a></li>');
		});
		$('#list-info-for li a').click(function(){
			var i = $('#list-info-for li a').index(this)+1;		
			document.getElementById('info-for').getElementsByTagName('select')[0].options[i].selected = "selected"; 
			$('#info-for input').click();
			return false;
		});	
		$('#info-for').append('<div id="link-info-for"><a href="#">Informatie voor</a></div>');
		
		$('#list-info-for').slideDown('fast');
		$('#list-info-for').slideUp('fast');
		
		if($('#info-for label').hasClass('selected')) $('#link-info-for a').addClass('selected');
		
		$('#link-info-for a').hover(function(){
			clearTimeout(FunctInfoForDropDown.hideTimer);
			$(this).addClass('hover');
			FunctInfoForDropDown.position();
			$('#list-info-for').slideDown('fast');
		}, function(){
			FunctInfoForDropDown.hideTimer = setTimeout(function(){FunctInfoForDropDown.hide()},500);
		});
		$('#link-info-for a').click(function(){ 
			return false; 
		});
		$('#list-info-for').hover(function(){
			clearTimeout(FunctInfoForDropDown.hideTimer);
		}, function(){
			FunctInfoForDropDown.hideTimer = setTimeout(function(){FunctInfoForDropDown.hide()},500);
		})
	},
	hide:function(){
		$('#list-info-for').slideUp('fast');
		$('#link-info-for a').removeClass('hover');
	},
	position:function(){
		var x = Essentials.findElementPosition(document.getElementById('link-info-for'))[0]-13;
		$('#list-info-for').css({left:x+"px"});		
	}
}
//	:::::::::::::::::::::::::::::: End Info Dropdown

//	:::::::::::::::::::::::::::::: Start Section Navigation
FunctSectionNav = {
	//activeSectionMenuItem:null,
	init:function(){
		$('#section-nav li ul').each(function(){
			if($(this).parent().hasClass('open')){
				//
			}else{
				$(this).parent().addClass('closed');
			}
			$(this).parent().children('a').addClass('goto');
		});
		
		$('#section-nav li a.goto').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
		
		$('#section-nav li a.goto').click(function(){
			var i = $('#section-nav li a.goto').index(this);
			if($(this).parent().hasClass('open')){
				$(this).parent().children('ul').slideUp('fast',function(){$(this).parent().removeClass('open').addClass('closed')});
				//FunctSectionNav.activeSectionMenuItem = null;
			}else{
				/*if(FunctSectionNav.activeSectionMenuItem != null){
					var thisParent = FunctSectionNav.activeSectionMenuItem.parent();
					FunctSectionNav.activeSectionMenuItem.slideUp('fast',function(){thisParent.removeClass('open').addClass('closed')});
				}*/
				$(this).parent().children('ul').slideDown('fast',function(){$(this).parent().removeClass('closed').addClass('open')});
				//FunctSectionNav.activeSectionMenuItem = $(this).parent().children('ul');
			}
			return false;
		});
	}	
}
//	:::::::::::::::::::::::::::::: End Section Navigation

//	:::::::::::::::::::::::::::::: Start Detail Navigation
FunctDetailNav = {
	init:function(){
		$('#detail-navigation div.block-detail-nav h3').each(function(){
			$(this).addClass('closed');
			var totalHTML = $(this).children('span.total').html();
			$(this).children('span.total').remove();
			$(this).html('<span class="hovertext">'+$(this).html()+'</span><span class="total">'+totalHTML+'</span>');
		});	
		$('#detail-navigation div.block-detail-nav h3').click(function(){
			if($(this).hasClass('closed-hover')){
				$(this).removeClass('closed-hover').addClass('open-hover');
				$(this).next().slideDown('fast');
			}else{
				$(this).removeClass('open-hover').addClass('closed-hover');
				$(this).next().slideUp('fast');
			}
		});	
		$('#detail-navigation div.block-detail-nav h3').hover(function(){
			if($(this).hasClass('closed')){
				$(this).removeClass('closed').addClass('closed-hover');
			}else{
				$(this).removeClass('open').addClass('open-hover');
			} 
		}, function(){
			if($(this).hasClass('closed-hover')){
				$(this).removeClass('closed-hover').addClass('closed');
			} 
			else{
				$(this).removeClass('open-hover').addClass('open');
			} 
		});
	}	
}
//	:::::::::::::::::::::::::::::: End Detail Navigation

//	:::::::::::::::::::::::::::::: Start Features
FunctFeatures = {
	init:function(){	
		$('div.feature-small').click(function(){
			if($(this).hasClass('video')) return; 
			var i = $('div.feature-small').index(this);
			var currentHref = $('div.feature-small a.link-read-more').eq(i).attr('href');
			document.location = currentHref;
		});
		$('div.feature-small h3').hover(function(){
			if($(this).parent().hasClass('video')) return;
			$(this).addClass('hover');
		}, function(){
			if($(this).parent().hasClass('video')) return;
			$(this).removeClass('hover');
		});
		$('div.feature-large').click(function(){
			var i = $('div.feature-large').index(this);
			var currentHref = $('div.feature-large a.link-read-more').eq(i).attr('href');
			document.location = currentHref;
		});
		$('div.feature-large h3').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
		$('div.feature-large p').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
	}	
}
//	:::::::::::::::::::::::::::::: End Features

//	:::::::::::::::::::::::::::::: Start Hilites
FunctHilites = {
	init:function(){	
		$('div.hilite-small .info-text').click(function(){
			var i = $('div.hilite-small .info-text').index(this);
			var currentHref = $('div.hilite-small .info-text a').eq(i).attr('href');
			document.location = currentHref;
		});
	}	
}
//	:::::::::::::::::::::::::::::: End Hilites

//	:::::::::::::::::::::::::::::: Start Faq
FunctFaq = {
	init:function(){	
		$('div.faq-block dt').each(function(){
			$(this).html('<span class="inner-faq-span">'+$(this).html()+'</span>');
		});
		$('div.faq-block dt span.inner-faq-span').hover(function(){
			$(this).css({textDecoration:'underline'});
		},function(){
			$(this).css({textDecoration:'none'});
		})
		$('div.faq-block dt').click(function(){			
			if($(this).hasClass('open')){					
				$(this).next().slideUp('fast',function(){$(this).prev().removeClass('open'); $(this).removeClass('open');$(this).prev().css({borderBottom:"1px solid #2eb135"});});
			} else {
				$(this).css({borderBottom:"1px solid #fff"});
				$(this).next().slideDown('fast',function(){ $(this).prev().addClass('open'); $(this).addClass('open')});
			}
		});
	}	
}
//	:::::::::::::::::::::::::::::: End Faq
//	:::::::::::::::::::::::::::::: Start sitesearch
FunctSiteSearch = {
	init:function(){	
		$('#site-search input:text').each(function(){
			var initValue = $(this).val();
			$(this).focus(function(){
				if($(this).val() == initValue) $(this).val('');
			})
			$(this).blur(function(){
				if($(this).val() == '') $(this).val(initValue);
			})
		})
		
	}	
}
//	:::::::::::::::::::::::::::::: End sitesearch

//	:::::::::::::::::::::::::::::: Start modal screen functionality
FunctModalScreen = {
	init:function(){
		//create modal screen
		if($('#modal-screen').length == 0){
			$('body').append('<div id="modal-screen"></div>');
			$('#modal-screen').click(function(){
				FunctOverlay.hide();
			});
		} 
		//create iframe mask
		if($('#modal-mask').length == 0 && jQuery.browser.msie) $('body').append('<iframe id="modal-mask" src="../../images/htmweb/algemeen/iframe-fake-src.gif"></iframe>');
		
	},
	sizing:function(){
		var h = $(window).height()>=$('#page-container').height() ? $(window).height() : $('#page-container').height()+30;
		$('#modal-screen').height(h);
		if(jQuery.browser.msie) $('#modal-mask').height(h);
		
		var w = $(window).width()>=$('#page-container').width() ? $(window).width() : $('#page-container').width()+40;
		$('#modal-screen').width(w);
		if(jQuery.browser.msie) $('#modal-mask').width(w);
	},
	show:function(){	
		FunctModalScreen.init();
		FunctModalScreen.sizing();
		$('#modal-screen').show();
		if(jQuery.browser.msie) $('#modal-mask').show();
		$(window).bind("resize", function(){
			FunctModalScreen.sizing();
		});
	},
	hide:function(){				
		$('#modal-screen').hide();
		if(jQuery.browser.msie) $('#modal-mask').hide();
		$(window).unbind("resize", function(){
			FunctModalScreen.sizing();
		});
	}	
}
//	:::::::::::::::::::::::::::::: End modal screen functionality

//	:::::::::::::::::::::::::::::: Start Maps
FunctMapsNav = {
	activeFilter:null,
	activeSubFilter:null,
	initFilters:function(){
		$('div.filter a.filter-switch').click(function(){
			$(this).parent().toggleClass('open');
			return false;
		});
		$('div#filter-panes ul.tab-pane li').each(function(){
			if($(this).hasClass('active')) FunctMapsNav.activeFilter = $(this).attr('id');
			FunctMapsNav.showFilter(FunctMapsNav.activeFilter);
			$(this).click(function(){
				$('div#filter-panes ul.tab-pane li').each(function(){
					$(this).removeClass('active');
				});
				$(this).addClass('active');
				var id = $(this).attr('id');
				FunctMapsNav.showFilter(id);
				TabClicked(id);
			})
		});	
		//$('div#filter-panes ul.tab-pane li a').click(function(){
			//return false;
		//})
	},
	showFilter:function(id){
		$('div.filter.' + FunctMapsNav.activeFilter + ' a.filter-switch').removeClass('show');
		$('div.filter.' + FunctMapsNav.activeFilter).removeClass('open');
		$('div.filter.' + id + ' a.filter-switch').addClass('show');
		FunctMapsNav.activeFilter = id;
	},
	initSubFilters:function(){
		$('ul.subTabs li').each(function(){
			if($(this).hasClass('active')) FunctMapsNav.activeSubFilter = $(this).attr('id');
			FunctMapsNav.showSubFilter(FunctMapsNav.activeSubFilter);
			$(this).click(function(){
				$('ul.subTabs li').each(function(){
					$(this).removeClass('active')
				});
				$(this).addClass('active');
				var id = $(this).attr('id');
				FunctMapsNav.showSubFilter(id);		
			})
			//alert(FunctMapsNav.activeSubFilter);			
		})
		
		//$('ul.subTabs li a').click(function(){
			//return false;
		//})
		
		$('.subfilter:first').prepend($('.filter.huur a.filter-switch:first').clone());
		$('.subfilter a.filter-switch').each(function(){
			$(this).css({display:"none"});
		})
	},
	showSubFilter:function(id){
		var oldClass = FunctMapsNav.activeSubFilter.substring(FunctMapsNav.activeSubFilter.lastIndexOf('-')+1);
		$('div.subfilter.' + oldClass).removeClass('show');
		var newClass = id.substring(id.lastIndexOf('-')+1);
		$('div.subfilter.' + newClass).addClass('show');
		FunctMapsNav.activeSubFilter = id;
		$('.filter.huur a.filter-switch:first').html($('div.subfilter.' + newClass + ' a.filter-switch').html());
	},
	initAreaFilter:function(){
		$('#paneArea ul.filterArea li a').click(function(){
			$('#paneArea a.filter-switch:first span').html($(this).html());
		return false;
		})
	},
	//viewState:'text',
	position:function(){
		var contentHeight = $('#content-container').height()-30;
		var minHeight = 400;
		var navHeight = 111;
		if($('.text-view').css("display")=='block'){
			$('#mapcontainer').removeClass('mapactive');		
			$('#map').css({height:'auto'});
			$('#switch-map').removeClass('active');
			$('#switch-text').addClass('active');
			
			var mapsHeight = $('#map').height();
			$('#mapcontainer').height(mapsHeight+navHeight);
		} else {
			$('#mapcontainer').addClass('mapactive');		
			$('#map').css({height:'100%'});
			$('#switch-map').addClass('active');
			$('#switch-text').removeClass('active');
			
			if(contentHeight<(minHeight+navHeight)){
				$('#mapcontainer').height(minHeight+navHeight);
				$('#map').height(minHeight);			} 
			else {
				$('#mapcontainer').height(contentHeight);
				$('#map').height(contentHeight-navHeight);
			}
		}
		
		//$('#mapcontainer').height();
	},
	init:function(){
		$('#mapcontainer').addClass('mapactive');
		$('#switch-map').click(function(){
			$(this).addClass('active');
			$('#switch-text').removeClass('active');
		});
		$('#switch-text').click(function(){
			$(this).addClass('active');
			$('#switch-map').removeClass('active');	
		});		
		//if(jQuery.browser.msie && Number(jQuery.browser.version)<7) $('#map').css({top:'18em'});
		FunctMapsNav.initFilters();
		FunctMapsNav.initSubFilters();
		FunctMapsNav.initAreaFilter();
		FunctMapsNav.position();
		$('#table-results tbody td').hover(function(){
			$(this).parent().addClass('hover');
		}, function(){
			$(this).parent().removeClass('hover');
		});
	}
}
//	:::::::::::::::::::::::::::::: End Maps

//	:::::::::::::::::::::::::::::: Start Show Overlay
FunctOverlay = {
	init:function(){	
				
		$('#table-results tbody tr').click(function(){
			FunctModalScreen.show();
			var goURL = this.getElementsByTagName('a')[0].href;
			FunctOverlay.show(goURL);
			return false;
		});
		$('a.go-overlay').click(function(){
			FunctModalScreen.show();
			var goURL = this.href;;				
			FunctOverlay.show(goURL);
			return false;
		})
	},
	mapLink:function(ref){
		FunctModalScreen.show();
		var goURL = ref.href;;				
		FunctOverlay.show(goURL);
		return false;
	},
	show:function(u){	
		document.location = "#top";			
		if($('#overlay-positioning').length == 0){
			$('body').append('<div id="overlay-positioning"><div id="iframe-pos"><iframe id="overlay-frame" src="'+u+'" scrolling="no" frameborder="0"></iframe></div></div>');
		} else {
			$('#overlay-frame').attr('src',u);
		}
	},
	hide:function(){
		$('#overlay-positioning').remove();
		FunctModalScreen.hide();
		//$('#overlay-frame').attr('src','');
	},
	rezizeFrame:function(h){
		$('#overlay-frame').attr('height',h);
		$('#overlay-frame').css({height:h+"px"});
	}
}
//	:::::::::::::::::::::::::::::: End Show Overlay

//	:::::::::::::::::::::::::::::: Start General essential functions
Essentials = {
	findElementPosition : function (elem){
		var curleft = curtop = 0;
		if (elem.offsetParent) {
		
			curleft = elem.offsetLeft
			curtop = elem.offsetTop
			while (elem = elem.offsetParent) {
				curleft += elem.offsetLeft
				curtop += elem.offsetTop
			}
		}
		return [curleft,curtop];
	}
}
//	:::::::::::::::::::::::::::::: End General essential functions
//	:::::::::::::::::::::::::::::: Start function calls on resizing
$(window).resize(function(){
	//FunctOverlay.position();
});
//	:::::::::::::::::::::::::::::: End function calls on resizing