window.addEvent('domready', function() {
	
	if ($chk($$('a.shop-remove'))) {
		$$('a.shop-remove').addEvent('click', function() {
			if (!confirm('Weet je zeker dat winkel "'+this.get('rel')+'" verwijderd moet worden?')) {
				return false;
			}
			return true;
		});
	}
	
	if ($chk($('crop-config'))) {
		var myAccordion = new Accordion($('crop-config'), 'img.crop-info', 'div.crop-text', {
			opacity: false,
			alwaysHide: true, 
			display: -1
		});
		formcheck = new FormCheck('crop-config');
	}
	
	if ($chk($('username'))) {
		$('username').addEvents({
			'focus' : function() {
				if (this.value == 'gebruikersnaam') {
					this.value = '';
				}
			},
			'blur' : function() {
				if (this.value == '') {
					this.value = 'gebruikersnaam';
				}
			}
		});
	}
	if ($chk($('password'))) {
		$('password').addEvents({
			'focus' : function() {
				if (this.value == 'wachtwoord') {
					this.value = '';
				}
			},
			'blur' : function() {
				if (this.value == '') {
					this.value = 'wachtwoord';
				}
			}
		});
	}
	if ($chk($('txtwebemail'))) {
		$('txtwebemail').addEvents({
			'focus' : function() {
				if (this.value == 'e-mail adres') {
					this.value = '';
				}
			},
			'blur' : function() {
				if (this.value == '') {
					this.value = 'e-mail adres';
				}
			}
		});
	}
	
	if ($chk($('verkoop-address'))) {
		var inputWord = $('verkoop-address');
		new Autocompleter.Request.HTML(inputWord, 'http://www.spitswallcoverings.nl/index.php?id=116', {
			'indicatorClass': 'autocompleter-loading'
		});
	}
	
	/*
	// Our instance for the element with id "demo-word2"
	new Autocompleter.Request.HTML(inputWord2, 'script.php', {
		'indicatorClass': 'autocompleter-loading',
		'postData': {
			'extended': '1' // send additional POST data, check the PHP code
		},
		'injectChoice': function(choice) {
			// choice is one <li> element
			var text = choice.getFirst();
			// the first element in this <li> is the <span> with the text
			var value = text.innerHTML;
			// inputValue saves value of the element for later selection
			choice.inputValue = value;
			// overrides the html with the marked query value (wrapped in a <span>)
			text.set('html', this.markQueryValue(value));
			// add the mouse events to the <li> element
			this.addChoiceEvents(choice);
		}
	});
	*/


	if ($chk($('prod_img_main'))) {
		$$('img.prod_img').addEvent('click', function() {
			$('prod_img_main').set('src',this.src);
		});
	}
	
	if ($chk($('accordion'))) {
		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
			opacity: false,
			alwaysHide: true, 
			display: -1,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#8e1b22');
				toggler.setStyle('background-image', 'url(assets/templates/spits/images/ico-collapse.gif)');
				toggler.setStyle('background-repeat', 'no-repeat');
				toggler.setStyle('background-position', 'right center');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#8e1b22');
				toggler.setStyle('background-image', 'url(assets/templates/spits/images/ico-expand.gif)');
				toggler.setStyle('background-repeat', 'no-repeat');
				toggler.setStyle('background-position', 'right center');
			}
		});
	}
	
	if ($chk($('image-top'))) {
		var obj = new Swiff('http://www.spitswallcoverings.nl/assets/templates/spits/flash/top-image.swf', {
	    id: 'image-header-top',
	    container: 'image-top', 
	    width: 856,
	    height: 228,
	    params: {
	        wmode: 'transparent',
	        bgcolor: '#ffffff'
	    },
	    vars: {
	   		afbeelding: ''+imgTop+'',
	   		regel1: ''+hr1+'',
	   		regel2: ''+hr2+'',
	   		regel3: ''+hr3+''
	    }
		});
	}
	
	if(typeof sIFR == "function") {
		sIFR.replaceElement(named({
			sSelector:"body h1", 
			sFlashSrc:"assets/templates/spits/flash/titles.swf", 
			sColor:"#737373", 
			sLinkColor:"#000000", 
			sBgColor:"#0055A5", 
			sHoverColor:"#CCCCCC", 
			nPaddingTop:0, 
			nPaddingBottom:0, 
			sWmode: "transparent",
			sCase: "upper",
			sFlashVars:"textalign=left&offsetTop=0"
		}));
	}
});

function ipaddress(el) {
		var error = false;
		var IPvalue = el.value;
		var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
		var ipArray = IPvalue.match(ipPattern);
		
		if (IPvalue == "0.0.0.0")
			error = true;
		else if (IPvalue == "255.255.255.255")
			error = true;
	
		if (ipArray == null)
			error = true;
		else {
			for (i = 0; i < 4; i++) {
				thisSegment = ipArray[i];
				if (thisSegment > 255) {
					error = true;
					i = 4;
				}
				if ((i == 0) && (thisSegment > 255)) {
					error = true;
					i = 4;
				}
			}
		}
		
		if (error === true) {
			var errorMsg = ("Voer een geldig IPv4 adres in.");
			el.errors.push( errorMsg );
			return false;
		} else {
			return true;
		}
	}

function load() {
	if (GBrowserIsCompatible()) {
		if (document.getElementById("map2")) {
			var map = new GMap2(document.getElementById("map2"));
			var geocoder = new GClientGeocoder();
			map.setUIToDefault();
			map.removeMapType(G_HYBRID_MAP);
			map.removeMapType(G_PHYSICAL_MAP);
			
			showAddress2(map,geocoder,'Opweg 90a, Schoonhoven', 'Spits Wallcoverings BV<br />Opweg 90a<br />2871 NG Schoonhoven<br />Nederland<br /><br />t. +31 (0)182 - 38 65 55<br /><br />f. +31 (0)182 - 38 23 24<br />info@spitswallcoverings.nl');
			
		}
		if (document.getElementById("map")) {
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(52.18958, 5.29524), gzoom);
			var geocoder = new GClientGeocoder();
			map.setUIToDefault();
			map.removeMapType(G_HYBRID_MAP);
			map.removeMapType(G_PHYSICAL_MAP);
	
			//create randomnumber to prevent caching and retrieve xml file
			var randomnumber=Math.floor(Math.random()*11111)
			GDownloadUrl("http://qlt.sonoind.nl/spits/index.php?id=50&random="+randomnumber, function(data, responseCode) {
				var xml = GXml.parse(data);
		
				//store markers in markers array
				var markers = xml.documentElement.getElementsByTagName("marker");
		
				// create marker icon
				var icon = new GIcon();
				icon.image = "assets/templates/spits/images/google-marker.png";
				icon.iconSize = new GSize(15, 15);
				icon.iconAnchor = new GPoint(7, 7);
				icon.infoWindowAnchor = new GPoint(5, 1);
	
				//loop over the markers array
				for (var i = 0; i < markers.length; i++) {
					var address = markers[i].getAttribute("address");
					var html = markers[i].getAttribute("html");
					showAddress(map,geocoder,address,html,icon);
				} 
			});
		}
	}
}

function showAddress2(map,geocoder,address,html) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = createMarker2(point,html);
        map.addOverlay(marker);
      }
    }
  );
}

function createMarker2(point,html){
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(decodeURIComponent(html));
	});
	return marker;
}

function createMarker(point,html,icon){
	//var marker = new GMarker(point,icon);
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(decodeURIComponent(html.replace(/\+/g, '%20')));
	});
	return marker;
}

function showAddress(map,geocoder,address,html,icon) {
	geocoder.getLatLng(
		address,
		function(point) {
			if (point != false) {
				var marker = createMarker(point,'<strong>'+html+'</strong><br/><br/>'+address,icon);
				map.addOverlay(marker);
			}
		}
	);
}




















