Cufon.replace('a.nav',{hover: true})('a.subnav',{hover: true})('a.medewerkerslinks',{hover: true})('h1')('h2')('h3')('h4')('h5')('#titlebar')('#admin_menu a');

$(document).ready(function(){

//$("#blocks a").wbflip({targetdiv: '#titlebar'});
 $('#file_upload').uploadify({
    'uploader'  : '/uploadify.swf',
    'script'    : '/uploadify.php',
    'cancelImg' : 'images/cancel.png',
    'folder'    : '/website_files',
    'auto'      : true,
    'multi'			:	true,
    'buttonImg' : '/images/upload.jpg',
    'width'     : 82,
    'queueSizeLimit' : 8,
    'onError'     : function (event,ID,fileObj,errorObj) {
      alert(errorObj.type + ' Error: ' + errorObj.info);
    },
    'onAllComplete' : function(event,data) {
      alert(data.filesUploaded + ' files uploaded successfully!');
      $('#upload_results').load('includes/ajax.loadfiles.php', function(){
      	setTypesetter();
      });      
    },
   	'scriptData': { 'session': $('#file_upload').attr('rel')}
  });

$("#blocks a").hover(
	function(){
		$this = $(this);
		$('#titlebar').stop(true).css({opacity: 0});
		$('#titlebar').html($this.attr('title'));
		$('#titlebar').fadeTo(500, 1);
		Cufon.refresh();
	},
	function(){
		$('#titlebar').fadeTo(500, 0);
	}
);

setTypesetter();

$('#fotogallery a').lightBox();
$('#slideshow a').lightBox();

if ($('#splash').length > 0) {
	$('body').css({
		background: '#000000'
	});
}

$('input.valuecount').keyup(function(){
	var totalvalue = 0;
	$('input.valuecount').each(function(){
		if($(this).val()){
			totalvalue = parseInt(totalvalue) + parseInt($(this).val());
		} 
	});
	$('#totalvalue').text(totalvalue);
})
 
$('#fotoslides').cycle();

$('#slides').cycle({ 
			fx:     'fade', 
			speed:  500, 
			timeout: 0, 
			pager:  '#pager', 
			containerResize: 1,
			easeIn:  'easeInQuad', 
			easeOut:  'easeOutQuad', 
			cleartypeNoBg: true,
			pagerAnchorBuilder: function(idx, slide) { 
       			return '#pager a:eq(' + idx + ')'; 
			}
		});
		 
$('a.fancybox').fancybox();


$('#form_strTekst').each(function() {
	var input = '#' + this.id;
	var count = input + '_count';
	$(count).show();
	word_count(input, count);
	$(this).keyup(function() { word_count(input, count) });
});
	var totalvalue = 0;
	$('input.valuecount').each(function(){
		if($(this).val()){
			totalvalue = parseInt(totalvalue) + parseInt($(this).val());
		} 
	})
	$('#totalvalue').text(totalvalue);
});

$(window).load(function(){

	if($('#splash').length > 0){
		setTimeout(function(){
			$('#splash').animate({
				width: 0	
			},500, false, function(){
				$('body').css({
					background: '#000000 url(../images/20eap.png) repeat-x left center'
				});
			});
		},2000);
	}
	var totalvalue = 0;
	$('input.valuecount').each(function(){
		if($(this).val()){
			totalvalue = parseInt(totalvalue) + parseInt($(this).val());
		} 
	})
	$('#totalvalue').text(totalvalue);
});

$(window).resize(function(){
	
});

function setTypesetter(){
	$('select.typesetter').change(function(){
	$(this).parent().load('includes/ajax.settype.php', 'id='+$(this).attr('rel')+'&value='+$(this).val(), function(){
		alert('Type was saved succesfully');
		//setTypesetter();
	});
});
}

function word_count(field, count) {
	var number = 0;
	var matches = $(field).val().match(/\b/g);
	if(matches) {
		number = matches.length/2;
	}
	var text = (300 - number) + ' word' + (number != 299 ? 's' : '') + ' left';
	if(300 - number < 0){
		text = '<span style="color: #ff6666; font-weight: bold; line-height: inherit">' + text + '</span> -> Every word exceeding the 300 limit will be removed after submitting this form';
	}
	$(count).html(text);

}


