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

$(document).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';
		}
	}
	
	// Scrollpanes for the brands on the right
	$('.brands').jScrollPane({ showArrows:true, scrollbarWidth: 0, scrollbarMargin: 0 });
	$('.jScrollArrowUp, .jScrollArrowDown').css('width', '28px');
	
	// Colorbox for page thumbs
	var thumbBoxHeight = 611;
	if(WS.browser.IE6 || WS.browser.IE7) { thumbBoxHeight = 643; }
	$('a[rel="page-gallery"]').colorbox({ iframe: true, width: 675, height: thumbBoxHeight, opacity: 0.8 });
	
	// Colorbox for carousel product items
	var productBoxHeight = 730;
	if(WS.browser.IE6 || WS.browser.IE7) { productBoxHeight = 762; }
	$('.colorbox').colorbox({ iframe: true, width: 675, height: productBoxHeight, opacity: 0.8 });
	
	if($('#home-content').length > 0) {
		// New arrivals carousel
		$('#new-arrivals .jcarousel').jcarousel({
			initCallback: function(carousel) {
				$('#new-arrivals .controls a').bind('click', function(e) {
					e.preventDefault();
					carousel.scroll($.jcarousel.intval($(this).text()));
				});
			},
			itemFirstInCallback: {
				onBeforeAnimation: function(carousel, object, index, state) {
					var realIndex = index-1;
					var currentItem = $('#new-arrivals .controls a')[realIndex];
					$('#new-arrivals .controls a').removeClass('selected');
					$(currentItem).addClass('selected');
				}
			},
			scroll: 1,
			auto: 7,
			wrap: 'last',
			animation: 'slow',
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		
		// Seizoen trends carousel
		$('#seizoen-trends .jcarousel').jcarousel({
			initCallback: function(carousel) {
				$('#seizoen-trends .controls a').bind('click', function() {
					carousel.scroll($.jcarousel.intval($(this).text()));
				});
			},
			itemFirstInCallback: {
				onBeforeAnimation: function(carousel, object, index, state) {
					var realIndex = index-1;
					var currentItem = $('#seizoen-trends .controls a')[realIndex];
					$('#seizoen-trends .controls a').removeClass('selected');
					$(currentItem).addClass('selected');
				}
			},
			scroll: 1,
			auto: 7.5,
			wrap: 'last',
			animation: 'slow',
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		
		// Filialen carousel
		$('#filialen .jcarousel').jcarousel({
			initCallback: function(carousel) {
				$('#filialen .controls a').bind('click', function() {
					carousel.scroll($.jcarousel.intval($(this).text()));
					return false;
				});
			},
			itemFirstInCallback: {
				onBeforeAnimation: function(carousel, object, index, state) {
					var realIndex = index-1;
					var currentItem = $('#filialen .controls a')[realIndex];
					$('#filialen .controls a').removeClass('selected');
					$(currentItem).addClass('selected');
				}
			},
			scroll: 1,
			auto: 8,
			wrap: 'last',
			animation: 'slow',
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
	}
	
	if(get('contact-form')) {
		var contactVal = new WS.Validation('contact-form');
		contactVal.initialize();
	}

	if(get('cheque-code-form')) {
		var chequeCodeVal = new WS.Validation('cheque-code-form');
		chequeCodeVal.initialize();
	}
	
	if(get('cheque-gegevens-form')) {
		var chequeGegevensVal = new WS.Validation('cheque-gegevens-form');
		chequeGegevensVal.initialize();
	}	
});

