Cufon.replace('#header .menu a,#header .nice-menu a,.avenir_shaduw, #block-block-21 a', { fontFamily: 'Avenir LT Std',textShadow: '1px 1px #111111'});
Cufon.replace('.avenir,#support_nodig .kolom', { fontFamily: 'Avenir LT Std',hover:true});
Cufon.replace('.caecilia,#page-title', { fontFamily: 'PMN Caecilia' ,hover:true});

Cufon.replace('.block-menu-block ul li a', { fontFamily: 'Avenir LT Std'});
Cufon.replace('.block-menu-block ul li .active,.block-menu-block li a.active-trail', { fontFamily: 'Avenir LT Std',textShadow: '1px 1px #111111'});

function reset_drupal_icon(){
	(function ($) {
		
	$('#drupal_7_embleem').animate({
	    left:icon_left+'px',
		top:icon_top+'px',
		filter: ''
	  }, 1000, 'easeOutElastic',function() {
	    
	  });
	
	})(jQuery);
	
}

function show_drupal_icon(){
	(function ($) {
		$('#drupal_7_embleem').animate({
			top:icon_top+'px',
			opacity:'1',
			filter: ''
		  }, 1000,'easeOutBounce',function() {

		  });
		
	})(jQuery);	

}

var icon_left = 0;
var icon_top = 0;
var resizeTimer;
/*Start Jquery*/
(function ($) {
/*Portfolio slideshow*/	
$(document).ready(function(){
	window.onload = start_slideshow;
	start_drupal_icon();
	$('#xio_mail_domein').focus(function(){
		$(this).val('');
	});
	
	$(window).resize(function () { 
		calculate_icon();
		//icon_left -= 100;
		clearTimeout(resizeTimer);
		resizeTimer = setTimeout("reset_drupal_icon()", 1000 );
    });
	
	if($('.arrow').length > 0){
		var width = $('.arrow_left').width()+$('.arrow_right').width()+$('.arrow_center').width()+30;
		$('.arrow').width(width);
		//alert($('.arrow_center').width());
	}
});

function calculate_icon(){
	//icon_left = $('#content_gradient .inner_con')[0].offsetLeft +960;
  icon_left = $('#content_gradient .inner_con')[0].offsetLeft +880;
	var cont = $('#content').position();
	icon_top =  cont.top - 58;
}

function start_drupal_icon(){
  var width = $('body').width() - 114;

	var height = $('body').height() - $('#drupal_7_embleem img').height()/2;
	
	//var main = $('#content_gradient .inner_con').position();
	calculate_icon();

	$('#drupal_7_embleem').css({'opacity':'0','left':icon_left+'px'});	
	setTimeout("show_drupal_icon()", 2000 );
	
	/*$('#drupal_7_embleem').draggable({
		opacity:'0.5',
		zindex:'500',
		containment:[0, 0, width, height]
	});
	
	$( "#drupal_7_embleem" ).bind( "dragstop", function(event, ui) {
	  interval = setTimeout("reset_drupal_icon()", 1000 );
	});*/
	
	/*$('#drupal_7_embleem').click(function(){
		alert('klik');
		interval = setInterval("reset_drupal_icon()", 1000 );
	});*/
	
	
}



function start_slideshow(){
	slideshow_count();
	
	//Cufon.replace('.slideshow .avenir', { fontFamily: 'Avenir LT Std' ,textShadow: '2px 2px #111111'});
    var fnAfter = function()
    {
		var parent = $(this).parent().parent().parent().parent().parent();
		var id = '#'+$(parent).attr('id');
		var nCurrIndex = $(id+" .slideshow .field-items .field-item").index(this);
		var volgende = nCurrIndex+1;
		var isaanwezig = $($(id+" .slideshow .field-items .field-item")[volgende]).find('img').length;
		//alert(isaanwezig);
		if(isaanwezig == 0){
			var url= $($(id+" .slideshow .field-items .field-item")[volgende]).html();
			var image = '<img src="'+url+'" />';
			$($(id+" .slideshow .field-items .field-item")[volgende]).html(image);
		}
    }

    var fnBefore = function()
    {	
		var parent = $(this).parent().parent().parent().parent().parent();
		var id = '#'+$(parent).attr('id');
		var nCurrIndex = $(id+" .slideshow .field-items .field-item").index(this);
		
		var isaanwezig = $($(id+" .slideshow .field-items .field-item")[nCurrIndex]).find('img').length;
		//alert(isaanwezig);
		if(isaanwezig == 0){
			var url= $($(id+" .slideshow .field-items .field-item")[nCurrIndex]).html();
			var image = '<img src="'+url+'" />';
			$($(id+" .slideshow .field-items .field-item")[nCurrIndex]).html(image);
		}
		
		//alert(nCurrIndex);
		/*var img = new Image();
		$(img).load(function () {
			
		}).attr('src', url);*/  

        $(id+" .slideshow_controls li.page")
        .each(function(index, el)
        {
            //alert(nCurrIndex);
            if (index == nCurrIndex)
            {
                $(el).removeClass("inactive");
                $(el).addClass("active");
            }
            else
            {
                $(el).removeClass("active");
                $(el).addClass("inactive");
            }

        });

        $(id+" .slideshow_controls a").attr('disabled');
    }

	$('.slideshow_controls li').each(function(){
		var parent = $(this).parent().parent().parent().parent();
		var id = '#'+$(parent).attr('id');
		$(this).click(function(){
			 slideshow_goto(id,this);
		});
	});

  $('.slideshow .field-items').each(function(){
	var parent = $(this).parent().parent().parent().parent();
	var id = '#'+$(parent).attr('id');
	 $(this)
	    .cycle({
	        speed: 500,
	        timeout: 5000,
	        after: fnAfter,
	        before: fnBefore,
	        next: id+" .next",
	        prev: id+" .prev",
			fx: 'fade'
	    });
  });

 

}

function slideshow_count() {
	$('.slideshow .field-items').each(function(){
	var parent = $(this).parent().parent().parent().parent();
	var id = '#'+$(parent).attr('id');
	var length = ($(this).find('.field-item').length);
	var output = '<ul class="slideshow_controls" style="display: block;"><li class="pager"><a class="prev avenir_shaduw" href="javascript:void(0)">Vorige</a></li>';
    for (var i = 1; i <= length; i++) {
		var index = i -1;
		if(i == 1){
			output += '<li class="page active avenir_shaduw '+index+'">' + i + '</li>';
		}else{
			output += '<li class="page inactive avenir_shaduw '+index+'">' + i + '</li>';
		}

    }
    output += '<li class="pager"><a class="next avenir_shaduw" href="javascript:void(0)">Volgende</a></li></ul>';

    $(id+" .slide_nav").html(output);

  });	
}

function slideshow_goto(container_id,element_clicked){
	var classes = $(element_clicked).attr('class').split(" ");
	//halen de juiste classe op, degene die een integer is
	for(var i =0;i<classes.length;i++){
		var parsed_id = parseInt(classes[i]);
		if(parsed_id || parsed_id ==0){
			jQuery(container_id + ' .slideshow .field-items').cycle(parsed_id);
		}
	}
	

}


/*Einde portfolio*/



/*Einde JQUERY*/
})(jQuery);


/*XIO redirect*/
function xio_mail_redirect(){
	(function ($) {
		var error  = false;
		if($('#xio_mail_domein').val() == ''){
	        $("#xio_mail_error").html("Wrong format");       
	        error = true;
         }
	
		var xio_road = $('#xio_mail input:radio:checked').val();
            
		var url = 'http://mail.'+$("#xio_mail_domein").val();
	
		if(xio_road == "admin"){
            	url += '/admin';
		}
	
		if(!error){
         //window.location = url;
			window.open(url,'_blank');
		}
	})(jQuery);
}

/*EInde Xio redirect*/
function lees_meer(id){
	(function ($) {	
		$('.moreintro').slideUp('fast');
		$('.readmore').fadeIn('fast');
		
		$(id+' .moreintro').slideToggle('fast');
		$(id+' .readmore').fadeToggle('fast');
	})(jQuery);
	

}

function tag_detail(parent){
	(function($){
		$('.menu-mlid-549').addClass('active');
		$(document).ready(function(){
			$('#block-block-3 .kolom').css('opacity','0.1');
			$('#block-block-3 .kolom:not(.term_'+parent+')').animate({
				opacity : 0.4
			},1000);
			
			
			$('#block-block-3 .kolom:not(.term_'+parent+')').hover(
			  function () {
			    $(this).animate({
					opacity : 1
				},500);
			  }, 
			  function () {
			    $(this).animate({
					opacity : 0.4
				},500);
			  }
			);
			
			
			
			
			
			$('.term_'+parent).animate({
				opacity : 1
			},1500,function(){
				var position_el = $('.term_'+parent).position();
				var left =$('#sub_header .inner_con')[0].offsetLeft+position_el.left + 110;
				
				$('#arrow').animate({
					left : left
				},2000,"easeOutBounce");
			});

			
		});
		
		
	})(jQuery);
}

var active_port = 0;
var tot_port = 0;
var busy = false;
function slide_portfolios(){
	(function($){
		$(document).ready(function(){
			$($('#block-system-main .portfolio')[active_port]).show();
			tot_port = $('#block-system-main .portfolio').length -1;
			
			$('#port_next').click(function(){
				if(!busy){
					busy = true;
					if(active_port < tot_port){
						$('#port_prev').show();
						$($('#block-system-main .portfolio')[active_port]).hide("slide", { direction: "left" }, 1000,function(){
							active_port ++;
							$($('#block-system-main .portfolio')[active_port]).show("slide", { direction: "right" }, 1000,function(){
								busy=false;

							});
							var volgende = active_port +1;

							if(volgende > tot_port){
								$('#port_next').hide();
							}
						});

					}else{
						busy = false;
						$('#port_next').hide();
					}
				}
				
			});
			
			$('#port_prev').click(function(){
				if(!busy){
					busy = true;
					
					if(active_port > 0){
						$('#port_next').show();
						$($('#block-system-main .portfolio')[active_port]).hide("slide", { direction: "right" }, 1000,function(){
							active_port --;
							$($('#block-system-main .portfolio')[active_port]).show("slide", { direction: "left" }, 1000,function(){
								busy=false;
							});
							var vorige = active_port -1;

							if(vorige < 0){
								$('#port_prev').hide();
							}
						});
					}else{
						busy = false;
						$('#port_prev').hide();
					}
				}
			});
			
			
			
		});
	})(jQuery);	
}


function slide_arrow_k1(){
	(function($){
		$(document).ready(function(){
			if($('#k1').length > 0){
				//var position_el = $('#k1 .kolom').position();
				var left = $('#sub_header .inner_con')[0].offsetLeft+$('#k1 .kolom')[0].offsetLeft + 110;

				$('#arrow').animate({
					left : left
				},2000,"easeOutElastic");
			}

		});
	})(jQuery);		

}

function resize(){
	var right = document.documentElement.scrollWidth;
	if(!right){
		right = document.body.scrollWidth;
	}

	if(icon_left > right){
		$('#drupal_7_embleem').css('left',icon_left);
	}
	
}
