/**
 * Bootstrap.js - Bootstrap for all Javascript functionality
 * 
 * @author  Webstores <info at webstores dot nl>
 *           Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

if(typeof(jQuery) != 'undefined') {
	jQuery.noConflict();
}

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');});}}
	
	jQuery('.colorbox').colorbox({slideshow: true});
	
	if($('gallery')) {
		if(jQuery('#gallery-images img').length > 1) {
			jQuery('#gallery').scrollable({
				speed:800,
				size:1,
				clickable:false,
				globalNav:true,
				next: '#next',
				prev: '#prev',
				onSeek:function() {
					var slideEl = this.getItems()[this.getIndex()+1];
					$('gallery-title').innerHTML = slideEl.getElementsByTagName('img')[0].title;	
					$('gallery-text').innerHTML = slideEl.title;
					$('gallery-link').href = slideEl.href;
					return false;
				}
			}).autoscroll({
				interval:5000
			}).circular();
			jQuery('#next, #prev').click(function(e) {
				e.preventDefault();
				return false;
			});
		}
	}
	
	if($('visual-scroller')){
		if(jQuery('#visual-scroller img').length > 1) {
			jQuery('#visuals').scrollable({
				speed:800,
				size:1,
				clickable:false,
				globalNav:true
			}).autoscroll({
				interval:5000
			}).circular();			
		}
	}	
	
	if($('contact-form')) {
		var contactVal = new WS.Validation('contact-form');
		contactVal.initialize();
	}	
});
