$(document).ready(function()
{
	showarticles_init( $(this) );
		
});
	
function showarticles_init( target )
{
	//******************************************************************************************
	// enter-knop disablen voor bestelformulier
   	$('.class_orderform').keypress(function(e) {  if (e.which == 13) {  return false;   }   });
	  	  
	//******************************************************************************************
	// functies voor actionshots knop
	$(target).find('.class_button_actionshots').toggle( 
		
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_actionshotscontainer').show() ;
			
			partid = $(this).closest('.class_articlecontainer').find("input[name='partid']").attr("value");
	
			$(this).closest('.class_articlecontainer').find('.class_actionshotscontainer').load('/showarticles_actionshots.php?partid='+partid);
		},
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_actionshotscontainer').fadeOut(250); 	
		} 
	
	);
	$(target).find('.class_button_actionshots').mouseover( function() {	
		return overlib("<I>Click for customer pictures</I>."); }
	);		
	$(target).find('.class_button_actionshots').mouseout( function() {	
		return nd(); }
	);	
	
	// einde functies voor actionshots knop
	
	//******************************************************************************************
	// functies voor alternatieve onderdelen knop

	$(target).find('.class_button_alternatives').toggle( 
		
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_alternativescontainer').fadeOut(250); 	
		}, 
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_alternativescontainer').show() ;
			
			formulier = $(this).closest('.class_orderform');
			$(this).closest('.class_articlecontainer').find('.class_alternativescontainer').load('/showarticles_alternatives.php?'+$(formulier).serialize(), function() { showarticles_init( this ); } );	
		}	
	);
	$(target).find('.class_button_alternatives').mouseover( function() {	
		return overlib("<I>Click for alternative parts</I>."); }
	);		
	$(target).find('.class_button_alternatives').mouseout( function() {	
		return nd(); }
	);	
	
	// einde functies voor alternatieve onderdelen knop
	
	//******************************************************************************************	
	// functies voor helptopics knop	
	
	$(target).find('.class_button_helptopics').toggle( 
		
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').show() ;
			
			partid = $(this).closest('.class_articlecontainer').find("input[name='partid']").attr("value");
			topicids = $(this).attr("data-topicids");
	
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').load('/showarticles_helptopics.php?partid='+partid+'&topicids='+topicids);
		},
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').fadeOut(250); 	
		} 
	
	);	
	$(target).find('.class_button_helptopics').mouseover( function() {	
		return overlib("<I>Click for help on ordering this article</I>."); }
	);		
	$(target).find('.class_button_helptopics').mouseout( function() {	
		return nd(); }
	);	
	// einde functies voor helptopics knop
	
	
	//******************************************************************************************	
	// functies voor documentatie knop
		
	$(target).find('.class_button_documentation').toggle( 
		
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').show() ;
			
			partid = $(this).closest('.class_articlecontainer').find("input[name='partid']").attr("value");			
	
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').load('/showarticles_documentation.php?partid='+partid);
		},
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_helptopicscontainer').fadeOut(250); 	
		} 
	
	);	
	$(target).find('.class_button_documentation').mouseover( function() {	
		return overlib("Clicca per la documentazione per questo articolo.."); }
	);		
	$(target).find('.class_button_documentation').mouseout( function() {	
		return nd(); }
	);	
	// einde functies voor documentatie knop

	//******************************************************************************************		
	// functies voor meer info knop	
	
	$(target).find('.class_button_moreinfo').mouseover( function() {	
		return overlib("Clicca per avere più informazioni."); }
	);	
	$(target).find('.class_button_moreinfo').mouseout( function() {	
		return nd(); }
	);		
	// einde functies voor meer info knop
	
	//******************************************************************************************		
	// functies voor mailafriend knop	
	
	$(target).find('.class_button_mailafriend').mouseover( function() {	
		return overlib("Manda una mail a un amico o ad una amica con un link a questo articolo.  "); }
	);	
	$(target).find('.class_button_mailafriend').mouseout( function() {	
		return nd(); }
	);		
	// einde functies voor mailafriend knop
	
	//******************************************************************************************
	// functies voor addtowishlist knop	
	
	$(target).find('.class_button_addtowishlist').mouseover( function() {	
		return overlib("Aggiungere al hotlist (lista delle cose desiderate)."); }
	);	
	$(target).find('.class_button_addtowishlist').mouseout( function() {	
		return nd(); }
	);		
	// einde functies voor addtowishlist knop
	
	//******************************************************************************************		
	// functies voor bestel knop

	$(target).find('.class_button_addtoorderlist').click( function() {	
		// artikel op bestellijst zetten
		check_order_form( $(this).closest('.class_orderform') ); }
	);	
			
	$(target).find('.class_button_addtoorderlist').mouseover( function() {	
		return overlib("Clicca qui per aggiungere questo articolo alla tua lista d´ordine"); }
	);	
	$(target).find('.class_button_addtoorderlist').mouseout( function() {	
		return nd(); }
	);		
	// einde functies voor bestel knop		
	
	//******************************************************************************************		
	// functies voor stockinfo knop
	
	$(target).find('.class_button_stockinfo').toggle( 
		
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_stockinfocontainer').show() ;
			
			partid = $(this).closest('.class_articlecontainer').find("input[name='partid']").attr("value");
	
			$(this).closest('.class_articlecontainer').find('.class_stockinfocontainer').load('/showarticles_showstock.php?partid='+partid);
		},
		function() { 
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_articlecontainer').find('.class_stockinfocontainer').fadeOut(250); 	
		} 
	
	);
	$(target).find('.class_button_stockinfo').mouseover( function() {	
		return overlib("Clicca per avere più informazioni."); }
	);	
	$(target).find('.class_button_stockinfo').mouseout( function() {	
		return nd(); }
	);		
	// einde functies voor stockinfo knop
	
	
	//******************************************************************************************
	// dit geeft een popup als op de voorraad info clickt
	$(target).find('.class_stockinfo').click(function() {	
		return overlib("<I>UITLEG:LEVERTIJD</I>"); }
	);	
	$(target).find('.class_stockinfo').mouseout( function() {	
		return nd(); }
	);		
	
	//******************************************************************************************
	// functies voor class_showarticle_small	
	$(target).find('.class_showarticle_small').hover(function()
	{
			$(this).addClass('highlighted');
			return overlib("Clicca per avere più informazioni.");
	}, function()
	{	
			$(this).removeClass('highlighted');	
			return nd(); 
	}
	);		

	$(target).find('.class_showarticle_small').click(function()
	{
			nd();
			formulier = $(this).children('.class_orderform');
			
			$(this).closest('.class_articlecontainer').load('/showarticles_single_article.php?'+$(formulier).serialize(), function() { showarticles_init( this ); } );			
	}
	);			
	// einde functies voor class_showarticle_small
	//******************************************************************************************	
	
	//******************************************************************************************
	// functies voor button_toggle_view waarmee we alle small artikelen uitklappen en weer inklappen
	$(target).find('#button_toggle_view').toggle(
	
		function()
		{
			// expand naar groot
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_outer_articlecontainer').find('.class_showarticle_small').each(function(index)
			{
				formulier = $(this).closest('.class_articlecontainer').find('.class_orderform');
				$(this).closest('.class_articlecontainer').load('/showarticles_single_article.php?article_options=minimize_button&'+$(formulier).serialize(), function() { showarticles_init( this ); } );
			});	
		},
		function()
		{
			// collapse naar minimized
			$(this).find('.class_togglebutton').toggle();
			$(this).closest('.class_outer_articlecontainer').find('.class_showarticle_normal').each(function(index)
			{								
				formulier = $(this).closest('.class_articlecontainer').find('.class_orderform');
				$(this).closest('.class_articlecontainer').load('/showarticles_single_article.php?article_options=minimize_button&size=small&'+$(formulier).serialize(), function() { showarticles_init( this ); } );
			});			
		}	
	);	
	// einde functies voor button_toggle_view
	//******************************************************************************************
		
	//******************************************************************************************
	// functies voor als articledescription te lang is voor het vakje
				
	$(target).find('.class_articledescription').mouseover( function() 
	{			
		if( $(this)[0].scrollHeight > 65 )
		{
			$(this).removeClass('class_articledescription_normal');
			$(this).addClass('class_articledescription_expanded');
		}
	}
	);	
	$(target).find('.class_articledescription').mouseout( function() 
	{	
		if( $(this)[0].scrollHeight > 65 )
		{			
			$(this).removeClass('class_articledescription_expanded');
			$(this).addClass('class_articledescription_normal');				
		}
	}
	);		
	//*******************************************************************************************
	
		
	$('#div_popup').draggable({ cursor: 'move', zIndex: 300  });
		
}

function check_order_form(formulier) 
{	
	var submit_in_background = 0 ;
	
	// checken of er een maat of kleur gekozen moet zijn.
	if( $(formulier).find("[name='alt_partid']").length  )
	{
		alt_partid = $(formulier).find("[name='alt_partid']").find(':selected').val();
		geselecteerd = $(formulier).find("[name='alt_partid']").find(':selected').text();
		onderscheidsveld = $(formulier).find("[name='onderscheidsveld']").val();
					
		if(alt_partid == 0)
		{
			msg = "Ti sei scordato di indicare quale. "+onderscheidsveld.toLowerCase()+" vuoi ordinare.\nSeleziona la tua scelta e clicca ancora su ´Aggiungere alla lista d´ordine´";
			alert(msg);
			return;
		}	
			
		$(formulier).find("[name='extrainfo']").val(onderscheidsveld+":"+geselecteerd+" ");
		$(formulier).find("[name='partid']").val(alt_partid);
	}

	if( $(formulier).find("[name='submit_in_background']").length )
	{	
		if( $(formulier).find("[name='submit_in_background']").val() > 0 ) submit_in_background = 1;
	} 
	
	if(submit_in_background)
	{
	
		// formulier in de achtergrond verzenden en geen bestellijst laten zien
		$.post('/orderlist.php3?'+$(formulier).serialize() , function ( data ) 
		{			
			result = $(data).find('result').text();	
		
			if(result == 'ok') alert("L'articolo è stato aggiunto alla tua lista d´ordine.");
		});		
	} else
	{
		// formulier verzenden en bestellijst laten zien, met vertraging voor IE6

		setTimeout(function(){	$(formulier).submit(); }, 100);
	}
	return;	
}

function addtowishlist(formulier)
{	
		$.post('/addtowishlist.php3?'+$(formulier).serialize() , function ( data ) 
		{			
			result = $(data).find('result').text();	

			if(result == 'ok') alert("L'articolo è stato aggiunto alla tua hotlist.\nMostrare la tua hotlist sotto MyEasyParts.");
			if(result == 'notloggedin') alert("Per aggiungere un articolo al hotlist devi aver fatto il login. \nClicca su 'fare il login' per fare il login o per registrarti. ");
		});	
}


