$(document).ready(function(){
		
		nonNederland();
		var shopSelected = null;
		var provincie = 0;
		var stadLetter = null;
		
		$('.changerow').mouseover(function(){
			$(this).attr("class", "coll_mouseover");
		}).mouseout(function(){
			$(this).attr("class", "coll_mouseout");
		});
		//online shops ophalen
		$('.selectOnline').click(function(){
			updateSelect( 'selectOnline' );
			shopSelected = 'selectOnline';
			nonNederland();
			//$(this).parent().addClass("coll_mouseover");
			$.get(baseurl + "ajax/onlineshops/", function(data){
				var outputString = '<table width="700" border="0" cellspacing="0" cellpadding="0">';
				//verwerken xml data
				$("shops", data).each(function(){
					outputString += '<tr><td><a href="' + $("url", this).text() + '" target="_blank">' + $("naam", this).text() + '</a></td><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr>'; 
				});
				outputString += '</table>';
				$('#shop_overview').html('');
				$('#shop_overview').prepend( outputString );
			});
			return false;
		});
		//shops per country
		$('.countrySelection').click(function(){
			var land = $(this).attr("id");
			var aLandId = land.split('_');
			updateSelect( land );
			shopSelected = land;
			if( aLandId[1] == 3 ){
				nederland()
			} else {
				nonNederland();
			}
			$.get( baseurl + "ajax/ShopsByCountryId/" + aLandId[1] + "/", function(data){
				var outputString = '<table width="700" border="0" cellspacing="0" cellpadding="0">';
				//verwerken xml data
				$("shops", data).each(function(){
					if( $("url", this).text() == '' ){
						var urlTo = '';
					} else {
						var urlTo = 'href="' + $("url", this).text() + '" target="_blank"'
					}
					outputString += '<tr><td><a ' + urlTo + '>' + $("naam", this).text() + '</a></td><td><a href="' + $("google", this).text() + '" target="_blank">' + $("adres", this).text() + '</a></td><td>' + $("postcode", this) .text()+ '</td><td>' + $("plaats", this).text() + '</td></tr>';
				});
				outputString += '</table>';
				$('#shop_overview').html('');
				$('#shop_overview').prepend( outputString );
			});
			return false;
		});
		//shops per state
		$('.provincieSelection').click(function(){
			var prov = $(this).attr("id");
			var aProv = prov.split('_');
			//set interne counter op een provincie
			updateProvincieSelectie( aProv[1] );
			provincie = aProv[1];
			removeStadSelectie();
			$.get( baseurl + "ajax/ShopsByProvincie/" + aProv[1] + "/", function(data){
				var outputString = '<table width="700" border="0" cellspacing="0" cellpadding="0">';
				//verwerken van xml data
				$("shops", data).each(function(){
					if( $("url", this).text() == '' ){
						var urlTo = '';
					} else {
						var urlTo = 'href="' + $("url", this).text() + '" target="_blank"'
					}
					outputString += '<tr><td><a ' + urlTo + '>' + $("naam", this).text() + '</a></td><td><a href="' + $("google", this).text() + '" target="_blank">' + $("adres", this).text() + '</a></td><td>' + $("postcode", this) .text()+ '</td><td>' + $("plaats", this).text() + '</td></tr>';				
				});
				outputString += '</table>';
				$('#shop_overview').html('');
				$('#shop_overview').prepend( outputString );
			});
			return false;
		});
		//shops per city
		$('.stadSelect').click(function(){
			var stad = $(this).attr("id");
			var aStad = stad.split('_');
			updateStadSelectie( aStad[1] );
			stadLetter = aStad[1];
			$.get(baseurl + "ajax/ShopsByStad/" + aStad[1] + "_" + provincie + "/", function(data){
				var outputString = '<table width="700" border="0" cellspacing="0" cellpadding="0">';
				//verwerken van xml data
				$("shops", data).each(function(){
					if( $("url", this).text() == '' ){
						var urlTo = '';
					} else {
						var urlTo = 'href="' + $("url", this).text() + '" target="_blank"'
					}
					outputString += '<tr><td><a ' + urlTo + '>' + $("naam", this).text() + '</a></td><td><a href="' + $("google", this).text() + '" target="_blank">' + $("adres", this).text() + '</a></td><td>' + $("postcode", this) .text()+ '</td><td>' + $("plaats", this).text() + '</td></tr>';				
				});
				outputString += '</table>';
				$('#shop_overview').html('');
				$('#shop_overview').prepend( outputString );
			});
			return false;
		});
		
		function updateSelect( string )
		{
			if( shopSelected == null ){
				$('#' + string).parent().addClass("coll_mouseover");
			} else {
				$('#' + shopSelected).parent().removeClass("coll_mouseover");
				$('#' + string).parent().addClass("coll_mouseover");
			}
		}
		
		function updateProvincieSelectie( string )
		{
			if( provincie == 0 ){
				$('#selectProvincie_' + string ).parent().addClass("coll_mouseover");
			} else {
				$('#selectProvincie_' + provincie ).parent().removeClass("coll_mouseover");
				$('#selectProvincie_' + string ).parent().addClass("coll_mouseover");
			}
		}
		
		function updateStadSelectie( string )
		{
			if( stadLetter == null ){
				$('#selectStad_' + string).parent().addClass("coll_mouseover");
			} else {
				$('#selectStad_' + stadLetter).parent().removeClass("coll_mouseover");
				$('#selectStad_' + string).parent().addClass("coll_mouseover");
			}
		}
		
		function removeStadSelectie()
		{
			if( stadLetter !=null ){
				$('#selectStad_' + stadLetter).parent().removeClass("coll_mouseover");
			}
		}
		
		function nederland()
		{
			$('#provincieTabel').show();
			$('.StadTabel').show();
		}
		
		function nonNederland()
		{
			$('#provincieTabel').hide();
			$('.StadTabel').hide();
		}
	});

