// JavaScript Document


		
		// Initialize the products
		function initializeSliderClick(activeOfferPage)
		{
			
			
			var productsArray = $('#Products a');
			for(var i=0; i < productsArray.length; i++ )
			{								
				productsArray[i].href = 'javascript: void(0);';
				// $(productsArray[i]).click(activateOffer(activeOfferPage++, this))
				
				$(productsArray[i]).click(function(){
					$('#offer_p0').fadeOut();
					$('#offer_p1').fadeIn();
					 });
			}							
		}
		
		// disable enter key
		function disableEnterKey(e)
		{
			 var key;
		
			 if(window.event)
				  key = window.event.keyCode;     //IE
			 else
				  key = e.which;     //firefox
		
			 if(key == 13)
				  return false;
			 else
				  return true;
		}
		




function setSliderWidth()
{
	
	var productWidth = $('#ProductList');
// 	alert()
	  $('#Products').width((productWidth.children("li").length*(productWidth.children("li").width()+12)));
}

function initializeProducts()
{
	var activeOfferPage = 0;

	// activate initialization functions
	// initializeSliderClick(activeOfferPage);

		// slider
		if ($('#Products').length > 0) 
		{
			
			
			// initialize the slider
			$("#sliderBar").slider({ handle: '#handleBar', animate: true, slide: function(event, ui) 
				{
					width = $('#Products').css("width")
					width = width.substr(0,width.length-2)							
					steps = (width-960)/100;
					
					
					
					// $('#Products').animate({"left",-(steps*ui.value)+'px'});	
					$('#Products').animate({
						left: "-"+(steps*ui.value)+"px"
					});
				}});
		

		
	// form change events
	
		// get all forms inside 
		var priceChangingFields = $('input[class^="priceChanging"]');
		var price; 
		for(var a=0; a < priceChangingFields.length; a++ )
		{
			
				// price = priceChangingFields[a].class
				$(priceChangingFields[a]).change(
					function() {
					$('#orderBag').load('/frontend/order/bag.tpl');
					}
				);
				
		}
	}
}
	


$(document).ready(function() {
  initializeProducts();  
  setSliderWidth();	
  

	// switch between 1 and 2 year contracts
	$('#orderYear2').click(function(){
		//	changer to two year packages
		$('#Products ul').load('/frontend/bestellen/product.php?years=2', function() {;
			setSliderWidth(); // this<.js
			initializeProducts(); // this<.js
			initializeTooltip(); // tooltip.js
	   });
	 });
	
	
	$('#orderYear1').click(function(){
		//	changer to two year packages
		$('#Products ul').load('/frontend/bestellen/product.php?years=1', function() {
			setSliderWidth(); // this<.js
			initializeProducts(); // this<.js
			initializeTooltip(); // tooltip.js
		});
		  
	 });

});
