$(document).ready(function(){
	clearInput();
	styleSwitch();
	popupInlog();
});

function clearInput() {
	$('.fade').focus(function() {
		$(this).select();
		$(this).prev().fadeTo(150, 0.33);
		$(this).keydown(function() {
			$(this).css('background-repeat', 'repeat');			 
		});
	});
	$('.fade').blur(function() {
		if ( $(this).val() == '' ) {
			$(this).css('background-repeat', 'no-repeat');
			$(this).prev().fadeTo(150, 1);
		}
	});
	$('.fade').each(function(){
		if ( $(this).val() != '') {
			$(this).css('background-repeat', 'repeat');
		};
	});
}
function customSelect(){
	$("select").each(function(){
		$(this).wrap("<div class='selector'></div>");
		// Store the value of title in the variable spanText
		var spanText = $(this).attr('title');
		// Use the variable span text as the default for the select field
		var span = "<span class='select'>" + spanText + "</span>";
		$(this).before(span)
		.fadeTo(1, 0)
		.focus(function(){
			$(this).parents(".selector").addClass("focus");
		})
		.change(function(){
			$(this).siblings("span").text($(this).children(":selected").text());
		}).click ( function (){
			$(this).siblings("span").text($(this).children(":selected").text());		
		}) 
		.blur(function(){
			$(this).parents(".selector").removeClass("focus");
		});	
	});
	$('select').trigger("change");
}

function styleSwitch() {
    if($.cookie("css")) {
        $(".changeme").attr("href",$.cookie("css"));
    }
    $("#topnav li a").click(function() {
		var sId = $(this).attr('id');
		switch(sId) {
			case 'default':
				var sStyle = 'http://www.webkey6.nl/klant/webego/css/fontdefault.css';
			break;
			case 'medium':
				var sStyle = 'http://www.webkey6.nl/klant/webego/css/fontmedium.css';
			break;
			case 'large':
				var sStyle = 'http://www.webkey6.nl/klant/webego/css/fontlarge.css';
			break;
		}
        $(".changeme").attr("href", sStyle);
        $.cookie("css", sStyle, {expires: 365, path: '/'});
    });
}

function popupInlog() {	
	$('.button-inloggen').click(function() {
	 	$('#popup-overlay').fadeTo(0, 0.75);
		$('#popup-overlay, #inloggen').fadeIn(500);					   
	});
	$('.close, #popup-overlay').click(function() {
		$('#popup-overlay, #inloggen').fadeOut(500);					   
	});
}

function initialize() {
	var myLatlng = new google.maps.LatLng(51.763365,4.188902);
	var myOptions = {
	  zoom: 13,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("google_maps"), myOptions);
	
	var image = new google.maps.MarkerImage('images/tpl/icon_webego.png',
		// This marker is 20 pixels wide by 32 pixels tall.
		new google.maps.Size(100,89),
		// The origin for this image is 0,0.
		new google.maps.Point(0,0),
		// The anchor for this image is the base of the flagpole at 0,32.
		new google.maps.Point(47,81)
	);
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		icon: image
	});  
}

function gaDirectNaar(){
	$('#gadirectnaar').change(function(){
		var sLink = $(this).attr('value');
		if(sLink != ''){
			window.location.href = sLink;	
		}											
	});
}