// JavaScript Document

/* 
Voor de functie uit als de DOM klaar is met laden (ondomready)
function 'enhanceFileInputs'
Voor all <input type=file"> elementen in de DOM:
	1. Voeg deze html in NA het element:
		<div id="fakeInput_[id van de input]" class="fakeFileInput"><em class="input"><span>...</span></em><a href="" class="button"><span>Bladeren...</span></a></div>
	2. Hang aan de parent (div element) van het input element de class 'styledFileInput'
	3. Koppel het 'change' event aan het input element met de functie:
		a. Stop de waarde uit 'this.value' in het text-attribuut van het element '#fakeInput_[id van de input] em span'.

*/
$(document).ready(function(){
	// enhanche inputs
	inlineLabel();
	// enable fancybox
	if($.fn.fancybox) {
        var fbonstart = ($('.fancybox-ie').length != 0) ? function(){if($('#fbiecssfix').length == 0) $('head').append('<link id="fbiecssfix" rel="stylesheet" type="text/css" media="screen" href="'+themepath+'/fancybox/jquery.fancybox-ie.css" />');} : null; 
	
		$('div.image a[rel=fancybox_group]').fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	// enhance fileinputs
	fileinput();
	// enable caroussel
	caroussel();
});

caroussel = function() {
	$('div.caroussel a.next').click(function(){
		$('div.caroussel div.data').scrollLeft($('div.caroussel div.data').scrollLeft()+$('div.caroussel div.data div.item').outerWidth());
	});
	$('div.caroussel a.prev').click(function(){
		$('div.caroussel div.data').scrollLeft($('div.caroussel div.data').scrollLeft()-$('div.caroussel div.data div.item').outerWidth());
	});
};

inlineLabel = function() {
	$('input[type=text],textarea').each( function() {
		if($(this).attr('title')==null || $(this).attr('title')=='') { return }
		$('<label for="'+$(this).attr('id')+'" class="inline-label">'+$(this).attr('title')+'</label>').appendTo($(this).parent());
		if($(this).val()!=''){
			$('label[for='+$(this).attr('id')+'].inline-label').fadeOut(1);
		}
		$(this).focus(function(){
			$('label[for='+$(this).attr('id')+'].inline-label').fadeOut('fast');
		});
		$(this).blur(function(){
			if($(this).val()==''){
				$('label[for='+$(this).attr('id')+'].inline-label').fadeIn('fast');
			}
		});
	});
};

fileinput = function() { $('input[type=file]').each( function() {
		$('<div id="fakeInput_'+$(this).attr('id')+'" class="fakeFileInput"><em class="input"><span>...</span></em><a href="" class="button"><span>Bladeren...</span></a></div>').appendTo($(this).parent());
		$(this).parent().addClass('styledFileInput');
		$(this).change(function(){ $('em.input span',$(this).parent()).html($(this).val()) });
	});
};

