// JavaScript Document


$(document).ready(function(){
	initAll();
	if($("#map").length > 0){
		loadGmaps();
	}
});

function initAll(){
	$("#blocks a:not(.active)").wbflip();
	$("#logos li a, .winkelscroll a, #plattegrondwinkels li a, #plattegrond a, #winkels li a").hover(function(){
		wbShopOver($(this).attr('href'));
	},function(){
		wbShopOff($(this).attr('href'));
	});
	$("#plattegrondwinkels [rel^=shop], #plattegrond [rel^=shop]").hover(function(){
		wbShopOver($(this).attr('rel'),'rel');
	},function(){
		wbShopOff($(this).attr('rel'),'rel');
	});	
	

	$("#legenda li").click(function(){
		var current = $("#legenda li.active");
		current.removeClass('active');
		legendaOff(current);
		$(this).addClass('active');
		legendaOver($("#legenda li.active"));
	});
									
	$("#legenda li").hover(function(){
		legendaOver($(this));
	},function(){
		legendaOff($(this));		
	});	
	 $('.cycle').cycle({
		fx: 			'fade',
		timeout: 		5000
	});
	 
	$('.scroll').jScrollPane();
	
	$("#plattegrondtoggle").click(function(e){
		if($(this).hasClass('active')){
			$(this).removeClass('active')
			$("#media .cycle").show();		
			$("#plattegrond").hide();	
		}else{
			$(this).addClass('active')
			$("#media .cycle").hide();
			$("#plattegrond").show();
		}
		e.preventDefault();
	});
	
	$("#actie .pictures").cycle({
		fx: 			'fade',
		timeout: 		2000
	});
	
	setTimeout(function(){ 
		$("#actie").show().animate({'marginLeft':'+=100'},0).css({'opacity':0}).animate({'marginLeft':'-=100','opacity':1},1500).find('.scrolleractie').jScrollPane(); 
	}, 1000);
	
	$("#actie .close").click(function(e){
	 $("#actie").fadeOut(500);
	  e.preventDefault();
	})
}

function legendaOver(el){
	var nr = el.attr('rel');
	$(".bol[nr="+el.attr('rel')+"]").css('background-position','0px '+(nr*-12)+'px').addClass('active');
	/*
	$(".bol[nr="+el.attr('rel')+"]").each(function(){
		if($(this).attr('href')){
			wbShopOver($(this).attr('href'));
		}else{
			wbShopOver($(this).attr('rel'),'rel');
		}
	})
	*/
}
function legendaOff(el){
	if(!el.hasClass('active')){
		$(".bol[nr="+el.attr('rel')+"]").css('background-position','0px 0px').removeClass('active');
	}
	/*
	if(!el.hasClass('active')){
		$(".bol[nr="+el.attr('rel')+"]").each(function(){
			if($(this).attr('href')){
				wbShopOff($(this).attr('href'));
			}else{
				wbShopOff($(this).attr('rel'),'rel');
			}
		});
	}
	*/
}

function wbShopOver(href,type){
	if(href){
		if(type == 'rel'){
			$("[rel="+href+"]:not(.bol)").addClass('active');
			$(".bol[nr][rel="+href+"]:not(.active)").css('background-position','0px '+($(".bol[rel="+href+"]").attr('nr')*-12)+'px');
		}else{
			$("#logos li:not(.active) a[href="+href+"]").find('img').stop().animate({'marginTop':'0px'},200);
			$("a[href="+href+"]:not(.bol)").addClass('active');
			$(".bol[nr][href="+href+"]:not(.active)").css('background-position','0px '+($(".bol[href="+href+"]").attr('nr')*-12)+'px');
		}
	}
}
function wbShopOff(href,type){
	if(href){
		if(type == 'rel'){
			$("[rel="+href+"]:not(.bol)").removeClass('active');
			$(".bol[nr][rel="+href+"]:not(.active)").css('background-position','0px 0px');	
		}else{
			$("#logos li:not(.active) a[href="+href+"]").find('img').stop().animate({'marginTop':'20px'},200);
			$("a:not(.bol)[href="+href+"]").removeClass('active');
			$("a.bol[nr][href="+href+"]:not(.active)").css('background-position','0px 0px');
		}
	}
}