(function($){
	
	var ishomepage = true;
	
	$(function(){
		// Scrollable content panes
		$('#scrollcontent').jqScroll();
		// Is homepage?
		ishomepage = $('#homepage').get(0)? true : false;
		// Tab menus
		$('#tabmenu-topmenu li').mouseenter(function(){
			if(!$(this).hasClass('current-menu-item') && !$(this).hasClass('current_page_parent')){
				$('a', this).animate({top:'10px'}, 400);
				hightlightPicture(this, 'menu-topmenu', true);
			}
		}).mouseleave(function(){
			if(!$(this).hasClass('current-menu-item') && !$(this).hasClass('current_page_parent')){
				$('a', this).animate({top:'10px'}, 200).animate({top:'22px'}, 200);
				hightlightPicture(this, 'menu-topmenu', false);
			}
		});
		
		
		$('#tabmenu-bottommenu li').mouseenter(function(){
			if(!$(this).hasClass('current-menu-item') && !$(this).hasClass('current_page_parent')){
				$('a', this).animate({top:'-6px'}, 400);
				hightlightPicture(this, 'menu-bottommenu', true);
			}
		}).mouseleave(function(){
			if(!$(this).hasClass('current-menu-item') && !$(this).hasClass('current_page_parent')){
				$('a', this).animate({top:'-6px'}, 200).animate({top:'-19px'}, 200);
				hightlightPicture(this, 'menu-bottommenu', false);
			}
		});
		// Homepage menu pictures
		$('#menu-topmenu li').mouseenter(function(){
			highlightTopTabs(this, true);
		}).mouseleave(function(){
			highlightTopTabs(this, false);
		});
		$('#menu-bottommenu li').mouseenter(function(){
			highlightBottomTabs(this, true);
		}).mouseleave(function(){
			highlightBottomTabs(this, false);
		});
		
		// Show Contact Form
		$('#contactadviseur').bind('click', function(){
			var name = $(this).attr('href').replace('#','');
			$('#mailto option[value="'+name+'"]').attr('selected', true);
			$('#adviseurdetails').slideUp(300);
			$('#adviseurcontact').slideDown(300);
			return false;
		});
		
		// Show Contact Form
		$('#contactform').bind('click', function(){
			var name = $(this).attr('href').replace('#','');
			$('#contactdetails').slideUp(300);
			$('#contactcontact').slideDown(300);
			return false;
		});
		
		// Adviseurs add div overlay
		$('#adviseurdetails div.adviseurs a').append( $('<div />') );
		
	});
	
	function hightlightPicture(obj, menu, bool){
		if(ishomepage){
			var c = $(obj).attr('class').split(' ')[0];
			var li = $('#'+menu+' li.'+c);
			if(bool) li.addClass('hover'); else li.removeClass('hover');
		}
	}
	
	function highlightTopTabs(obj, bool){
		if(ishomepage){
			var c = $(obj).attr('class').split(' ')[0];
			var li = $('#tabmenu-topmenu li.'+c);
			if(bool){
				$('a', li).addClass('hover').animate({top:'10px'}, 400);
			}else{
				$('a', li).removeClass('hover').animate({top:'10px'}, 200).animate({top:'22px'}, 200);
			}
		}
	}
	
	function highlightBottomTabs(obj, bool){
		if(ishomepage){
			var c = $(obj).attr('class').split(' ')[0];
			var li = $('#tabmenu-bottommenu li.'+c);
			if(bool){
				$('a', li).addClass('hover').animate({top:'-6px'}, 400);
			}else{
				$('a', li).removeClass('hover').animate({top:'-6px'}, 200).animate({top:'-19px'}, 200);
			}
		}
	}
	
})(jQuery);
