

/*
*	font replacment
*/

Cufon.replace('div#content-wrapper h2');
Cufon.replace('.date');
Cufon.replace('#game-nav li, #game-nav li a ');
Cufon.replace('.hoewerkthet-content p');

/* 
*	FUS
*/ 

var lang = {
				'home_news_subscr_succes': {
											"nl": "<p class='news-subscribe-succes text-bold'>Ziezo, je bent ingeschreven voor onze nieuwsbrief.</p><p>IJsboerke zal je regelmatig trakteren op lekkere nieuwtjes en interessante aanbiedingen.</p>"
										},
				'news_subscr_succes': {
											"nl": 	"<p class='news-subscribe-succes'><span class='text-bold'>Ziezo, je bent ingeschreven voor onze nieuwsbrief.</span><br/>IJsboerke zal je regelmatig trakteren op lekkere nieuwtjes en interessante aanbiedingen.</p>"
				
									},
				'news_subscr_error': {
											"nl": "Foutje! Vul alsjeblieft je <span id='field-name'></span> correct in."
				}
			};
			

$(document).ready(function(){
	
	$('.hoewerkthet-content').hide();
	
	$('.btn-hoewerkthet-link').click(function () {
		$('.hoewerkthet-content').show();
	});
	
	$('.hoewerkthet-close').click(function () {
		$('.hoewerkthet-content').hide();
	});
	

	
	$('#game-nav li a').click(function () {
		$(this).parent(li).addClass("border");
	});

	

	
	

	
	// init slider
	initSlider();
	
	// init fancybox
	$('a[rel=fancybox]').fancybox({ type: 'swf' });
	
	// bottom-bar-fold container 
	initFoldCarousel('#bottom-bar-fold-left');
	initFoldCarousel('#bottom-bar-fold-right');
	
	/*
	*	product selector jCarousel
	*/
	$('#product-scroll-thumbs ul').jcarousel({	
		wrap: 'circular',		
		scroll: 4,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		initCallback: function(c){
			// btnNext 
			$('#product-scroll-right a').click(function(){
				c.next();
				return false;
			});	
			// btnPrev
			$('#product-scroll-left a').click(function(){
				c.prev();
				return false;
			});	
		}
	});


	/*
	*	slides
	*/
	
	// init cycle plugin
	$('.slides-container ul').cycle({ timeout: 0, fx: 'fade' });
	
	// adding a number to all thumbs
	$('#product-scroll-thumbs ul li a').each(function(i){
		$(this).attr('rel',i);
	});
	
	$("#product-scroll-thumbs ul li a").click(function(){
		// rel attribute event target
		var rel = $(this).attr('rel');
		
		// go to the right slide
		$('.slides-container ul').cycle(eval($(this).attr('rel')) + 1);
		
		// adding and removing the selected class
		$('#product-scroll-thumbs ul li a').each(function(i){
			if($(this).attr('rel') != rel){
				$(this).removeClass('selected');	
			}else{
				$(this).addClass('selected');
			}
		});

		return false;
	});
	
	/*
	*	fun page gamecycle
	*/
	var fx;
	// fading effects on png images fails in IE 
	if($.browser.msie){
		fx = 'none';		
	}else{
		fx = 'fade';	
	}
	
	$('ul#games').cycle({ 
		fx:     fx, 
    	prev:   '#btn-prev-game', 
    	next:   '#btn-next-game', 
    	timeout: 0,
		cleartypeNoBg:  true
	});
	
	
	/*
	*	clear textfields onfocus
	*/
	$('.clearfield').clearField();
	
	
	/*
	*	form validation
	*/
	$('#submit-news-subscribe').click(function(e){
		validateNewsFrm($('#first-name'),$('#last-name'),$('#email'));
		e.preventDefault();
	});
	
	
	/*
	*	Close folds when there is click event 
	*	anywhere outside the fold
	*/
	$('body').click(function(e){
						  
		var target = e.target;
		var bool = false;
		
		$(target).parents().each(function(i){
			if($(this).attr('id') == 'bottom-bar-fold-left' || $(this).attr('id') == 'bottom-bar-fold-right'){
				bool = true;
			}
		});
		
		if(bool == false && $(target).attr('id') != 'bottom-bar-fold-left' && $(target).attr('id') != 'bottom-bar-fold-right'){
			$('#bottom-bar-fold-left').hide();
			$('#bottom-bar-fold-right').hide();

			return;
		}
									 
	});
	
	/*
	*	show/hide folds
	*/
	$('#btn-fold-left').click(function(){
		$('#bottom-bar-fold-left').show();
		$('#bottom-bar-fold-left').css('visibility','visible');
		$('#bottom-bar-fold-right').hide();
		return false;
	});
	
	$('#btn-fold-right').click(function(){

		$('#bottom-bar-fold-right').show();
		$('#bottom-bar-fold-right').css('visibility','visible');
		$('#bottom-bar-fold-left').hide();
		
		return false;
	});
	
	// close fold 
	$('#bottom-bar-fold-right .btn-close,#bottom-bar-fold-left .btn-close').click(function(){
		
		$(this).parent().parent().hide();
		return false;
		
	});
	

});

/*
*	Form validation
*/
function validateNewsFrm(fname,lname,email){
	
	
	var msg = $('div#news-subscribe .error-msg, div#subscribe-form-container .error-msg');

	var errors = new Array();
	
	// reset layout
	$(msg).hide();
	$(fname).removeClass('frm-error');
	$(lname).removeClass('frm-error');
	$(email).removeClass('frm-error');
	
	// validation
	if($(fname).val() == '' || $(fname).val() == $(fname).attr('rel')){
		$(fname).addClass('frm-error');
		errors.push('Voornaam ');	
	}
	
	if($(lname).val() == '' || $(lname).val() == $(lname).attr('rel')){
		$(lname).addClass('frm-error');
		errors.push('Achternaam ');
	}
	
	if(!isEmail($(email).val()) || $(email).val() == '' || $(email).val() == $(email).attr('rel')){
		$(email).addClass('frm-error');
		errors.push('E-mailadres ');
	}
	
	
	if(errors.length > 0){
		$(msg).html(lang.news_subscr_error.nl).find('#field-name').text(errors[0]);
		$(msg).show();
	}else{
		$('#news-subscribe').html(lang.home_news_subscr_succes.nl);
		$('#subscribe-wrap').html(lang.news_subscr_succes.nl);
	}
	
}

/*
*	Check if a string is an email adres
*/
function isEmail(v) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(v);
}

/*
*	bottom-bar-fold carousel 
*/
function initFoldCarousel(selector){
	
	$(selector + ' .fold-carousel ul').jcarousel({	
			wrap: 'circular',		
			scroll: 3,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: function(c){
				
				// btnNext 
				$(selector + ' .fold-carousel .btn-next').click(function(){
					c.next();
					
					return false;
				});	
				
				// btnPrev
				$(selector + ' .fold-carousel .btn-prev').click(function(){
					c.prev();
					
					return false;
				});
								
			}
		});	
}


/**
 * Slider for IJsboerke
 * 
 * @author Stijn Van Minnebruggen
 * @copyright These Days
 * 
 */

var initSlider = function() {
	
	// stop if not needed
		if(!$('.sliderbar_wrapper').size()) return false;
	
	// get slider values and init click actions
		var currentVisibleItem = 0;
		var sliderValues = [];
		$('.sliderbar_numbers ul li a').each(function(index) {
			var el = $(this);
			sliderValues.push(el.text());
			el.click(function() { $('.sliderbar_wrapper').slider({ value: index }); return false; });
		});
	
	// init slider
		$('.sliderbar_wrapper').slider({
			min: 0,
			max: sliderValues.length-1,
			value: 0,
			change: function() {
				var index = $('.sliderbar_wrapper').slider('value');
				var value = sliderValues[index];
				var newX = 25+(53*index);
				$('.sliderbar_numbers ul li a').removeClass('active');
				$('.sliderbar_handle').animate({ left: newX }, 500, function() {
					$('.sliderbar_numbers ul li:eq('+index+') a').addClass('active');
					gotoItem(index);
				});
			}
		});
	
	// animate background
		var gotoItem = function(index) {
			$('#timeline ul li:eq('+currentVisibleItem+')').animate({ opacity: 0 }, 1000, function() { $(this).hide(); });
			$('#timeline ul li:eq('+index+')').show().animate({ opacity: 1 }, 1000, function() { currentVisibleItem = index; });
		};
	
};




