Cufon.replace('h3', { fontFamily: 'font' });
Cufon.replace('h2', { fontFamily: 'font' });
Cufon.replace('#categorie_list', { hover: true, fontFamily: 'font_menu' });
Cufon.replace('.block_title', { fontFamily: 'font_menu' });
Cufon.replace('.cufon_small', { fontFamily: 'font_menu' });
			
///Toevoeging 1 juni 2011
$(document).ready(function(){
	//$('#newsticker').supersleight({shim: '../images/bg_ticker.png'});
	///preview website
	//var pathname = $(location).attr('href');
//	if (pathname.toLowerCase().indexOf("?preview") >= 0) {
//		$('a').each( function() {
//			var href = $(this).attr('href');
//    		
//			if(href)
//			$(this).attr('href', href + '?preview');
//		});
//	}

	//Clear all image link code from old website.
	pathArray = window.location.pathname.split( '/' );
	$('a').each( function() {
		var href = $(this).attr('href');	
		if(href)
			var href = href.replace('projects.finwize.nl/giw/', document.domain+'/'+pathArray[1]);
			$(this).attr('href',href);
			
	});
	$('img').each( function() {
		var href = $(this).attr('src');
		if(href)
			var href = href.replace('projects.finwize.nl/giw/', document.domain+'/'+pathArray[1]);
			$(this).attr('src', href);
	});
	
	if(Modernizr.backgroundsize)
	{
		$('.ondersteuning').css('display','block');
		$('a.geenondersteuning').parent('li').css('display','none');
		$('.ondersteuning').corner('6px');
		$('#main_content.ondersteuning').corner('8px');
	}
	else
	{
		//$.fn.corner.defaults.useNative = false;
		$('.geenondersteuning').css('display','block');
		$('a.ondersteuning').parent('li').css('display','none');
		$('.geenondersteuning').corner('6px');
		$('#main_content.geenondersteuning').corner('8px');
	}
	
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});

});
///Einde toevoeging 1 juni 2011

//Creating the submenu
$(document).ready(function(){ 
	$("#productlist ul li").click(function () {
    	$(this).toggleClass("highlight");
		get_products();
    });

	//Validate - Validation of forms
	$("#service_form").validate();
	$("#service_form2").validate();
	
	//Searchbox: hiding and showing value
	$('input[type="text"]').focus(function (){
		clearText(this);
	});
	$('input[type="text"]').blur(function (){
		addText(this);
	});
	$('textarea').focus(function (){
		clearText(this);
	});
	$('textarea').blur(function (){
		addText(this);
	});
	
	$('#sendafriend_link').click(function() {
		$('#sendafriend_div').show();
	});
	
	$('#submit').click(function() {
		post_sendafriend_form();
	});
	
	$('#cancel').click(function() {
	  $('#sendafriend_div').hide();
	});
	
	$("ul.sf-menu").superfish({autoArrows: false, animation: {height:'show'}});  // call supersubs first, then superfish, so that subs are 
                         				// not display:none when measuring. Call before initialising 
                         				// containing tabs for same reason. 
	
	
	
}); 


//Mailme - Email Spam Protector
$(function() {
    var at = / at /;
    var dot = / dot /g;
    $('span.mailme').each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        $(this)
            .after('<a href="mailto:'+addr+'" class="mailme">'+ addr +'</a>')
            .remove();
    });
});

//Links with the class external will open in a new window, to get the code valid in xhtml-strict
$(function() {
	$(".external").attr("target","_blank");
});

//Creating the scrolling newsticker on the frontpage
$(function(){ 
	$("ul#ticker").liScroll(); 
}); 


//Creating a nice scrollbar
$(function()
{
	$('#scroll').jScrollPane({showArrows:true, scrollbarWidth:20});
	$('#scroll2').jScrollPane({showArrows:true, scrollbarWidth:20});
	$('#scroll3').jScrollPane({showArrows:true, scrollbarWidth:20});
});

function clearText(theField)
{
if (theField.defaultValue == theField.value)
theField.value = '';
}

function addText(theField)
{
if (theField.value == '')
theField.value = theField .defaultValue;
}

function get_products()
{
	var no_features = '';
	
	$('#productlist ul li').each( function () {
		var id = $(this).attr('id');
		if($(this).hasClass(''))
		{
			no_features = no_features+id+" ";
		}
		
	});
	
	var cat_id = $('#productlist ul').attr('id');
	
	$.ajax({
		type: "GET",
		url: "../forms/products-overview.php?no_features="+no_features+"&cat_id="+cat_id,
		dataType: "html",
		error: function(){
			alert('Error loading XML document, contact Finwize');
		},
		success: function(data){
			$('#products_container').html(data);
			if(Modernizr.backgroundsize)
			{
				$('.ondersteuning').css('display','block');
				$('a.geenondersteuning').parent('li').css('display','none');
				$('.ondersteuning').corner('6px');
			}
			else
			{
				//$.fn.corner.defaults.useNative = false;
				$('.geenondersteuning').css('display','block');
				$('a.ondersteuning').parent('li').css('display','none');
				$('.geenondersteuning').corner('6px');
			}
		}
	 });
}

function post_sendafriend_form()
{
	var formdata = $("#sendafriend_form").serialize();
	var path = $("#sendafriend_form").attr('action');

	$.ajax({
		type: "POST",
		url: path,
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			alert(data);
			
			if(data == 'Verzonden'){
				$('#sendafriend_div').hide();
			}
		}
	});
};

function post_form(formid)
{
	var formdata = $("#"+formid).serialize();
	var path = $("#"+formid).attr('action');
	$.ajax({
		type: "POST",
		url: path,
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			if(data == 'Verzonden'){
				$("#"+formid+"_div").html('Bedankt voor uw bericht.<br/>Indien nodig nemen wij z.s.m. contact met u op.');
				$('#scroll')[0].scrollTo(0); 
				$('#scroll2')[0].scrollTo(0); 
				$('#scroll3')[0].scrollTo(0);
			}
			else
			{
				alert(data);
			}
		}
	});
};

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

function startCarousel()
{
	setTimeout(function() {			
		var total_li = $('.list_carousel ul li:hidden').length;
		var list_width = total_li * 105.5;
		$(".list_carousel ul").css('width',list_width+'px');
		
		var slide_times = total_li - 5;
		slideCarousel(slide_times,1);
	}, 2000);
	
}

function slideCarousel(slide_times,i)
{
	if(i <= slide_times){
		var slide_width = i * 105;
		$(".list_carousel ul").animate({marginLeft: '-'+slide_width+'px'},1200);
		i++;
		setTimeout(function() {
		slideCarousel(slide_times,i);
		}, 2000);
	}
	else
	{
		$(".list_carousel ul").animate({marginLeft: '0px'},1200);
		i = 1;
		setTimeout(function() {
		slideCarousel(slide_times,i);
		}, 2000);
	}
}

function post_reg_newsletter_form(form,path,second)
{
	if(second){
		second = second;
	} else {
		second = '';
	}	
	var formdata = $("#"+form+second).serialize();
	$.ajax({
		type: "POST",
		url: path+"exe/newsletter.php?t=signup",
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			var response=$(data);
            var oneval = response.filter('#kind').html();
			var subval = response.filter('#message').html();
			
			if(oneval == 'positive')
			{
				var mess_div = 'reg_newsletter_sended_div'+second;
				$('#reg_newsletter_form_div'+second).hide();
				$('#reg_newsletter_mess_div'+second).hide();
			}
			
			if(oneval == 'negative')
				var mess_div = 'reg_newsletter_mess_div'+second;
			
			$("#"+mess_div).removeClass();
			$("#"+mess_div).addClass(oneval);
			$("#"+mess_div).show();
			$("#"+mess_div).html("<span>"+subval+"</span>");
			$("#"+mess_div).animate({ "opacity" : 1 });
			
		}
	});
};
