var autocompleter = {
	init: function() {
        $('div.search input[type=text]').autocomplete('/cms/ajaxfiles/readtags.php');
	}
};

var togglers = {
	active: null,
	
	init: function() {
		/**
		$('ul.toggling-menu li').click(function(event) {
			
			if ($(this).find('a').attr('class') == "rookgas") {
				document.getElementById('header').style.background = "url('images/headers/rookgasafvoer.jpg') top left no-repeat";
			}
			$(this).find('a').addClass('active');
			$(this).find('div').slideDown('fast');
		});
		$('ul.toggling-menu li').mouseleave(function(event) {
			$(this).find('a').removeClass('active');
			$(this).find('div').slideUp('fast');
			if ($(this).find('a').attr('class') == "rookgas") {
				document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
			}
		});
		*/
		
	    $('ul.toggling-menu li a').click(function(event) {
			if (togglers.active == this) {
				$(this).removeClass('active');
				$(this).next('div').slideUp('fast');
				togglers.active = null;
				if ($(this).attr('class') == "rookgas") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "beveiliging") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "particulier") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "woningbouw") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "utiliteit") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "service") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}
				if ($(this).attr('class') == "dakbedekking") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}	
				if ($(this).attr('class') == "installatie") {
					document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
				}				
				return;
			}
			
	        if (togglers.active !== null) {
	            $(togglers.active).removeClass('active');
	            $(togglers.active).next('div').slideUp('fast');
	        }
			
	        if ($(this).attr('class') == "rookgas") {
				document.getElementById('header').style.background = "url('images/headers/rookgasafvoer1.jpg') top left no-repeat";
			}
			else if ($(this).attr('class') == "beveiliging") {
				document.getElementById('header').style.background = "url('images/headers/beveiliging_1.jpg') top left no-repeat";
			}
			else if ($(this).attr('class') == "particulier") {
				document.getElementById('header').style.background = "url('images/headers/particulier_1.jpg') top left no-repeat";
			}
			else if ($(this).attr('class') == "woningbouw") {
				document.getElementById('header').style.background = "url('images/headers/woningbouw_1.jpg') top left no-repeat";
			}			
			else if ($(this).attr('class') == "utiliteit") {
				document.getElementById('header').style.background = "url('images/headers/utiliteit_1.jpg') top left no-repeat";
			}		
			else if ($(this).attr('class') == "service") {
				document.getElementById('header').style.background = "url('images/headers/service_1.jpg') top left no-repeat";
			}			
			else if ($(this).attr('class') == "dakbedekking") {
				document.getElementById('header').style.background = "url('images/headers/dakbedekking_1.jpg') top left no-repeat";
			}			
			else if ($(this).attr('class') == "installatie") {
				document.getElementById('header').style.background = "url('images/headers/originals_1.jpg') top left no-repeat";
			}		
			else {
				document.getElementById('header').style.background = "url('images/default/header.jpg') top left no-repeat";
			}
			
	        $(this).addClass('active');
	        $(this).next('div').slideDown('fast');
			
	        togglers.active = this;
	    });
	    
	}	
};

$(function() {
	togglers.init();
	autocompleter.init();
});

