/**
 * Bootstrap.js - Bootstrap for all Javascript functionality
 * 
 * @author  Webstores <info at webstores dot nl>
 *           Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

WS.DOM.ready(function() {
	
	// External links
	var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){if(/external/.test(a[i].rel)){a[i].target='_blank';}}
	
	// Toggle input values
	var inputs=WS.DOM.getElementsByClass('toggle-value');inputs.forEach(function(el){var v=el.value;WS.Event.addEvent(el,'focus',function(){if(this.value==v){this.value='';}WS.addClass(this,'focus');});WS.Event.addEvent(el,'blur',function(){if(this.value==''){this.value=v;WS.removeClass(this,'focus');}});});
	
	// IE6 hover
	if(WS.browser.IE6){var hoverEls=$('navigation').getElementsByTagName('li');for(var i=0;i<hoverEls.length;i++){WS.Event.addEvent(hoverEls[i],'mouseover',function(){WS.addClass(this,'iehover');});WS.Event.addEvent(hoverEls[i],'mouseout',function(){WS.removeClass(this,'iehover');});}}
	
	// Colorbox
	jQuery("a[rel='colorbox']").colorbox();
	
	//Accordions
	jQuery("#openingstijden").accordion({ autoHeight: false	});
	jQuery("#openingstijden-closed").accordion({ autoHeight: false, active:false, collapsible: true });
	jQuery("#contactgegevens").accordion({ autoHeight: false });
	jQuery("#contactgegevens-closed").accordion({ autoHeight: false, active:false });
	
	//Tabs
	jQuery("#contact-info ul.tabs").tabs("div#contact-info > p");
	jQuery("#route-wrapper ul.tabs").tabs("div#route-wrapper > div");
	jQuery("ul#homepage-visual-tabs").tabs("div#homepage-visual-panes > div", {
		tabs: 'li',
		current: 'selected',
		rotate: true,
		onClick: function() {
			setTimeout(function() {
				Cufon.replace('#homepage-visual-tabs a', { fontFamily: 'Neo Sans Bold' });
			}, 50);
		}
	}).slideshow({
		autoplay:true
	});
	
	if(jQuery('#contact-form').length > 0){
		jQuery('#contact-form').validate({
			/*submitHandler: function(form) {
		   		form.submit();
			},*/
			rules: {
				voornaam: "required",
				achternaam: "required",
				email: "required",
				bericht: "required"
			},
			messages: {
				voornaam: "",
				achternaam: "",
				email: "",
				bericht: ""				
			}
		});
	}
	
	jQuery('#bornerbroek').click(function(e){
		var zipnum = jQuery(this).prev().prev().val();
		var zipchar = jQuery(this).prev().val();
		
		if(zipnum != '1234' && zipchar != 'AB') {
			window.open('http://maps.google.nl/maps?saddr='+ zipnum +'+'+ zipchar +'&ll=52.323331,6.688716&daddr=Autobedrijf+Zuithof+Bornerbroek'); 
		}
		return false;
	});
	
	jQuery('#reutum').click(function(e){	
		
		var zipnum = jQuery(this).prev().prev().val();
		var zipchar = jQuery(this).prev().val();
		
		if(zipnum != '1234' && zipchar != 'AB') {
			window.open('http://maps.google.nl/maps?saddr='+ zipnum +'+'+ zipchar +'&ll=52.394534,6.838391&daddr=Autobedrijf+Zuithof+Reutum'); 
		}
		return false;
	});	
	
});

