
	jQuery(function( $ ){
		/**
		 * Demo binding and preparation, no need to read this part
		 */
			//borrowed from jQuery easing plugin
			//http://gsgd.co.uk/sandbox/jquery.easing.php
			$.easing.elasout = function(x, t, b, c, d) {
				var s=1.70158;var p=0;var a=c;
				if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
				if (a < Math.abs(c)) { a=c; var s=p/4; }
				else var s = p/(2*Math.PI) * Math.asin (c/a);
				return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
			};
	});
	 
	var htmlOUT = '';
	var a_li	= '';
	var a_ul	= '';
	var a_a		= '';
	var a_top	= '';
	var i 	= 0;

	$(document).ready(function() {
		
		var i = 0;
		a_ul = $("<ul></ul>").attr('class','toc');

		//$(".content-holder a[@name]").each(function() {
		$("#midcontent h2").each(function() {													
			i++;
			
			if($(this).attr('class') != 'order-header'){

			// create <li> element
			a_li = $("<li></li>"); 
			// create <a> element
			//a_a = $("<a></a>").text($(this).attr('name').replace(/_/g," ")).attr('href','#'+$(this).attr('name')).click(somefunction); 
			a_a = $("<a></a>").text($(this).text().replace(/_/g," ")).attr('href','#deel_'+i); // .click(somefunction); 
            // append <a> to <li>
            a_li.append(a_a);
            // append <li> to <ul>
            a_ul.append(a_li);
 			
			if(i>1){
				var div_top = $("<div></div>").attr('class','backtotop');
				a_top = $("<a></a>").attr('href','#top').text('naar boven');
				div_top.append(a_top)
				a_a__ = $("<a></a>").attr('name','cl'+i).attr('id','deel_'+i); //.click(somefunction); 
								div_top.append(a_a__)
				$(this).before(div_top);
				
								
				
				//$(this).before(a_a__);
			};
};

		});
	
		$('#midcontent h1').after(a_ul);


	 });





	function somefunction (){

		//alert('asdadad');
		///$('.content-holder').trigger( 'next' );



	};


	// activate localscroll on internal #anchor links
	$(document).ready(function() {
		$.localScroll({duration:900, axis:'y',easing:'elasout'})
	 });
	
	

	
	$(document).ready(function() {
		$(".details").each(function() {
		var   mySH = 50; //$(window).height();
	//	alert($(window).height());
		mySH = parseInt(mySH) +   $('.advanced').height() + $('.details').height() + 100;
	//	alert(mySH)
		$('.detail-holder').css('height',''+mySH+'px');
	});
		$(".images-gallery").each(function() {
		// reference to the image holder
		var img_ = '.gallery-image img';

		// hide and fadein image
		$(img_).hide();
		$(img_).fadeIn('slow');

		// loop thru all images
		$(".gallery-thumbs img").each(function() {

			$(this).click(
				function() {
					$(img_).hide();
					changeImg($(this).attr('src'),img_)
				}
			);
			
			// hide and fadein thumb
			$(this).hide();
			$(this).fadeIn('slow');

			// add hand cursor to each thumb
			$(this).css('cursor','pointer');
	
		});

		// move bodytext below images gallery
		var h 	= $(".images-gallery").height();
		h 		= h - 150;
		if(h < 1){
			h = 15;
		};
		$('.bodytext').css('padding-top',''+h+'px');
//detail-holder

		var   mySH = 650;
	//	alert($(window).height());
		mySH = parseInt(mySH) + $('.bodytext').height() + + $('.commerce').height();
	//	alert(mySH) 
		$('.detail-holder').css('height',''+mySH+'px');
		});

	 });	
		

	function changeImg(in_,t){
		
		// remove "_tn" from thumnbnail src
		// sun_tn.jpg => sun.jpg
		var img_p = in_.replace(/_tn/g,"");

		// set src of the main image
		c = $(t).attr('src',img_p);
		// fade in 
		$(t).fadeIn('slow');


     var img = $(t); 
    // a.html('Loading&#8230;'); 
     img.onload = function() { 
      alert('cc');
 //  a.html(text); 
     }; 

	  $(t).load(function () { 


		// move bodytext below images gallery
		var h 	= $(t).height();
		h 		= h  - 350;
		if(h < 1){
			h = 15;
		};
		//alert(h);
		$('.bodytext').css('padding-top',''+h+'px');

	  });
	};



	$(document).ready(function() {


		$(".cart-buy").click(
			function() {

				cart_grow();


				var u =  encodeURI(window.location.href).replace(/&/g,"^");
				d = $(".cart-small").load("http://www.centrumhethof.nl/bizz_shop.php?product_add="+$("#cart_add_serviceid").attr('value')+"&product_url="+u+"", function(){
			cart_grow();
p_();
		});

			//	d2 = $("<div>"+d+"</div>")
     		//	$(".cart-small").append(d2); 
				


			}
		);

	});	




	$(document).ready(function() {

		var state = 'ready';

		$(".cart-buy-advanced").click(
			function() {


				var store = $(this).css('backgroundImage');
				$(this).css('backgroundImage','url()'); 
				$(this).html('een moment..');
				cart_grow();
				cart_small_loading();
				var u =  encodeURI(window.location.href).replace(/&/g,"^");
				var t = this;

				if(state == 'ready'){

					state = 'busy';
					d = $(".cart-small").load("http://www.centrumhethof.nl/bizz_shop.php?product_add="+$(this).attr('id')+"&product_url="+u+"&product_advanced="+$(this).attr('id')+"", function(){
						cart_grow();
						p_();
	
						$(t).css('backgroundImage',store); 
						$(t).html(''); 
						state = 'ready';
					});

				}else{
					//alert('busy');
				};

			}
		);

	});	



	$(document).ready(function() {

		d = $(".cart-small").load("http://www.centrumhethof.nl/bizz_shop.php?getcart=small", function(){


			cart_grow();
			p_();



		});


	});	


	

 

	function p_(){
	
		$(".cart-small-delete").click(

			function() {
								
				$(".cart-small").load("http://www.centrumhethof.nl/bizz_shop.php?product_delete="+$(this).attr('id')+"", function(){
					cart_grow();

				});
			}
		);
	};
		var tm = '';
	function deleteWarning(){

		$('.warning').animate({ opacity: 0 }, "slow", function(){
				$('.warning').remove();
				cart_grow();	
		});

			clearInterval(tm);

	};

	function cart_grow(){

		$(".product").each(function() {
			if($(this).find(".text").height() > 0 ){
				$(this).css('height',$(this).find(".text").height());
			};
		});		




		$(".cart-small-checkout").click(
			function() {
				//alert('asad');
				document.location.href = '/default/shop/checkout';
			}
		);

		h = $(".cart-small-products").height();
		//h = h - 15;


		$('.cart-small').animate({ height: h }, "slow", function(){

			p_();	
//			setTimeout("deleteWarning()", 7000);
			clearInterval(tm);
			tm = setInterval("deleteWarning()", 7000);
		});



	};

	$(document).ready(function() {




	});
	


	function cart_small_loading(){

		//$('.cart-small').animate({ opacity: 0 }, "slow", function(){
	
		//$(".cart-small").html('loading..');

		//});

	};

/*


$('a').click(function() { 
     var a = $(this), text = a.html(), img = $('img.full_img')[0]; 
     a.html('Loading&#8230;'); 
     img.onload = function() { 
         a.html(text); 
     }; 
     img.src = a.attr('href'); 
     return false; 



}); 

                
$.ajax({
    url: 'document.xml',
    type: 'GET',
    dataType: 'xml',
    timeout: 1000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(xml){
        // do something with xml
    }
});
*/

