/**
 * Bootstrap.js - Bootstrap for all Javascript functionality
 * 
 * @author  Webstores <info at webstores dot nl>
 *           Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

WS.Event.addEvent(window, 'load', function() {
	
	// Search field
	WS.Util.toggleValue('search', 'focus');
	if($('maps-zipnum')) {
		WS.Util.toggleValue('maps-zipnum', 'focus');
		WS.Util.toggleValue('maps-zipchar', 'focus');
	}
	// Fix PNG label transparency in IE6
	if(WS.browser.IE6) {
		var labels = WS.DOM.getElementsByClass('label');
		if(labels.length > 0) {
			for(var i = 0; i < labels.length; i++) {
				WS.Util.fixPngBackground(labels[i], 'resources/img/product-label-bg.png');
			}
		}
	}
	
	// Homepage visual tabs
	if($('categories')) {
		var visualSwitch = new VisualSwitcher('categories', 'selected', true);
		visualSwitch.initialize();
	}
	
	// Sidebar accordion
	if($('sidebar-accordion')) {
		var accOptions = { classNames: { toggle: 'accordion-button', toggleActive: 'accordion-button-active', content: 'accordion-content' } };
		var acc = new accordion('sidebar-accordion', accOptions);
		acc.activate(WS.DOM.getElementsByClass('accordion-button', $('sidebar-accordion'))[0]);
	}
	
	// Sidebar maps-form
	if($('maps-form')) {
	WS.Event.addEvent('maps-form', 'submit', function(e) {
		WS.Event.stopEvent(e);
		
		var zipnum = $('maps-zipnum').value;
		var zipchar = $('maps-zipchar').value;
		if($('divstaalbouw')) {
			var dest = 'Hoogeveenseweg+7-F+7777+TA+Schuinesloot';
		} else if($('divspecialproducts')) {
			var dest = 'Hoogeveenseweg+7-D+7777+TA+Schuinesloot';
		}else if($('divinterieurbouw')) {
			var dest = 'Hoogeveenseweg+7-B+7777+TA+Schuinesloot';
		}
		if(zipnum != '1234' && zipchar != 'AB') {
			window.location.href = 'http://maps.google.nl/maps?saddr='+ zipnum +'+'+ zipchar +'&daddr=' + dest;
		}
	});
	}	
	// Product image carousel
	if($('product-image-scroller')) {
		var carousel = new Carousel($('product-image-scroller'), $$('.slide'), $$('a.carousel-jumper', 'a.carousel-control'), {
			duration: 1.5,
			auto: true,
			frequency: 5
		});
	}
	
	// Reference image carousel
	if($('reference-image-scroller')) {
		var carousel = new Carousel($('reference-image-scroller'), $$('.slide'), $$('a.carousel-jumper', 'a.carousel-control'), {
			duration: 1.5,
			auto: true,
			frequency: 5
		});
	}
	
	// Footer ticker
	if($('brand-ticker')) {
	var brandTicker = new Ticker('brand-ticker');
	setTimeout(function() { brandTicker.initialize(); }, 3000);
	}
	// Footer service navigation
	var serviceNav = new Toggler();
	serviceNav.initialize();
});

// Initialize Google Maps
google.load('maps', '2');
google.setOnLoadCallback(function() {
	if($('map')) {
	var mapCt = $('map');
	var map = new google.maps.Map2(mapCt);
	var center = new google.maps.LatLng(52.640337, 6.537123);
	var marker = new google.maps.Marker(center);
	
	map.setCenter(center, 11);
	map.addOverlay(marker);
	
	WS.hide(WS.DOM.getChild(mapCt, 3));
	}
});

// Initialize Google Maps
google.load('maps', '2');
google.setOnLoadCallback(function() {
	if($('map-contact-data')) {
	var mapCt = $('map-contact-data');
	var map = new google.maps.Map2(mapCt);
	map.setMapType(G_SATELLITE_MAP);
	var center = new google.maps.LatLng(52.640337, 6.537123);
	var marker = new google.maps.Marker(center);
	
	map.setCenter(center, 11);
	map.addOverlay(marker);
	
	WS.hide(WS.DOM.getChild(mapCt, 3));
	}
});

// GJ: Initialize Form validation
WS.Event.addEvent(window, 'load', function() {
	if($('contact-form')) {
		var contactFormVal = new WS.Validation('contact-form');
		contactFormVal.initialize();
	}
	if($('newsletter-form')) {
		var contactFormVal = new WS.Validation('newsletter-form');
		contactFormVal.initialize();
	}
});

