

$.fn.opacity = function(amount) {
        if (amount > 1) amount = 1;
        if (amount < 0) amount = 0;
        if ($.browser.msie) {
                amount = (parseFloat(amount) * 100);
                this.css('filter', 'alpha(opacity='+amount+')');
        } else {
                this.css('opacity', amount);
                this.css('-moz-opacity', amount);
        }
        return this;
}






$(document).ready(function(){


	jQuery.easing.def = 'easeOutBack';
	//$('.img_container img').hide();

	$('.img_container').mouseover(function()
	{
		
		$(this).stop();
		$(this).animate({ 
			width: "144px"
		      }, 500, 'easeOutBounce' );

		var selectat = $(this).html();
		var h = $(this).width();


		$(this).parent().find('.img_container').each(function(i){
			   
				if($(this).html()!=selectat && h>=$(this).width())
				{	
					$(this).stop();
					$(this).animate({ 
						width: "1px"
					      }, 500, 'easeOutBounce', function(){$(this).hide();} );	
				}

			 });

	
	});
	$('.teapa').click(function()
		{
			alert("Trebuie sa fii logat pentru a comanda");
		}
		);


	$('.img_container').mouseout(function()
	{
		
		var selectat = $(this).html();
		var h = $(this).width();
		
		var cn = $(this).parent().find('.img_container').size(); 

		
		
		var cn2 = 144/cn;		
		var size = 144;


		$(this).parent().find('.img_container').each(function(i){
			   
				//alert(cn+" "+cn2+" "+size);
				$(this).show();
				$(this).stop();
				$(this).animate({ 
					width: size+"px"
				      }, 500, 'easeOutBack' );	

				//alert(size+"px");
				//$(this).css("width", size+"px");
				//$(this).css("opacity", "0.5");	
				//$(this).css("z-index", i);				
				size -= cn2;
				

			 });

	
	});



        $('.portii').change(function()
	{
		
		var val = $(this).val();
		var id  = $(this).parent().find(".id").val();
		var da  = $(this).parent().find(".da").val();



		if (!isInteger(val)) 
		{
			alert("ATENTIE! Trebuie sa introduceti un numar!");
			$(this).val("0");
			$(this).parent().parent().animate({ backgroundColor: "#e85c00" }, 1000);

			return false;
		}	
		
		


		var url = 'utilities/edit_meniu.php?';
		var pars = 'id=' + id  + '&value=' + val + '&da=' + da;
	
		//alert(pars);
	
		if(val) $(this).parent().parent().animate({ backgroundColor: "#FFCC00" }, 1000);
				if(val==0) $(this).parent().parent().animate({ backgroundColor: "#e85c00" }, 1000);

	
		//alert(pars);
	
		$.ajax({
		  type: "POST",
		  url: url+pars,
		  
		  success: function(data) {
				//alert('am salvat informatia');
			    
				
				//alert(data);
				
				if(data)
				{
					$("#cos_de_cumparaturi").html(data);
				
				
					$("#cos_de_cumparaturi").fadeIn(500);
					$("#antet_cos").fadeIn(500);
				}
				else
				{
					$("#cos_de_cumparaturi").fadeOut(500);
					$("#antet_cos").fadeOut(500);

				}
				//document.getElementById('produs'+nume+'_submit').disabled=false; 
				//document.getElementById('arata_meniu').innerHTML = data;
			
				req = null;
			}, 

		  
		  //altele
		  error: function(data)
		  {
	
			alert ('eroare: nu am putut salva informatia');  
		
			/*document.getElementById('produs'+nume+'_submit').value='modifica'; 
			document.getElementById('produs'+nume+'_submit').disabled=false; */
		
			}
		  
		}); 



        });

	$('.comenzi_efectuate').click(function(){


		$(this).find("p").slideToggle(200);
		
	
	});

	

	$('.info img').click(function(){


		var id = $(this).parent().parent().parent().find('.id').val();

		var url = 'utilities/get_data.php?';
		var pars = 'modul=meniu&func=arata_detalii&id='+id;

	
		
		$("#antet").hide();
		
		$("#bg_detalii_preparat").opacity(.9);
		$("#bg_detalii_preparat").css("height", ($("body").height()-(-100))+"px");

		jQuery.easing.def = 'easeOutQuad';

		$("#bg_detalii_preparat").fadeIn(1000);
			
		$("#loading_detalii_preparat").show();

		$("#loading_detalii_preparat").css("top", $(window).scrollTop());
		$("#loading_detalii_preparat").css("left", (($(window).width() - $("#loading_detalii_preparat").width())/2)+"px");



		jQuery.easing.def = 'easeOutBack';

		$.ajax({
		  type: "POST",
		  url: url+pars,
		  
		  success: function(data) {
				
					
					$("#loading_detalii_preparat").fadeOut();
					
					$("#detalii_preparat").hide();
				

					$("#detalii_preparat").css("top", $(window).scrollTop());
					$("#detalii_preparat").css("left", (($(window).width() - $("#detalii_preparat").width())/2)+"px");


					$("#detalii_preparat .info_bg").opacity(.7);

					
					$("#detalii_preparat").html(data);

					$("#detalii_preparat").show();
					
				    $(".imgclose").click(function(){hide_detalii();});


				    req = null;
			}, 

		  
		  //altele
		  error: function(data)
		  {

			//alert ('eroare: nu am putut incarca poza');  
			$("#loading_detalii_preparat").fadeOut();
	
	
			}
		  
		}); 	

		
	
	});	
	

	/*$(window).scroll(function(){
		
		$("#detalii_preparat").stop();
		$("#detalii_preparat").animate({top: $(window).scrollTop()}, 500);

	});*/


		
	
});

function poza_mouseover(t, m)
{

	
	//alert(t + " " + m);
		
	$("#img_mare_"+t).stop();
	$("#img_mare_"+t).animate({ 
		width: "750px"
	      }, 500, 'easeOutBounce' );


	for(i=t; i<=m; i++)
	{
		
	

		if(i!=t)
		{	
			$("#img_mare_"+i).stop();
			$("#img_mare_"+i).animate({ 
				width: "1px"
			      }, 500, 'easeOutBounce', function(){$("#img_mare_"+i).hide();} );	
		}
	}
 

	
};

function poza_mouseout(t, m)
{
	
	
	var cn2 = 750/m;		
	var size = 750;

	
	for(i=1; i<=m; i++)
	{
		
			
			$("#img_mare_"+i).show();
			$("#img_mare_"+i).stop();
			$("#img_mare_"+i).animate({ 
				width: size+"px"
			      }, 500, 'easeOutBack' );	
			size -= cn2;
		
	}

	

}


function hide_detalii()
{
	
	$("#loading_detalii_preparat").fadeOut();
						
				
	$("#detalii_preparat").hide();

	$("#bg_detalii_preparat").hide();
	
	$("#antet").show();



	
	
}

function goleste_cosul()
{
	
	var a  = confirm("Doriti sa goliti cosul?");	
	
	if(!a) return;

	var url = 'utilities/get_data.php?';
	var pars = 'modul=meniu&func=goleste_cosul';

	

	$.ajax({
	  type: "POST",
	  url: url+pars,
	  
	  success: function(data) {
			
			$("#cos_de_cumparaturi").fadeOut(500);
			$("#antet_cos").fadeOut(500);	

			$(".info").animate({ backgroundColor: "#e85c00" }, 1000);
			$(".portii").val(0);


			req = null;
		}, 

	  
	  //altele
	  error: function(data)
	  {

		alert ('eroare: nu am putut sterge cosul');  
	
	
	
		}
	  
	}); 

}

function trimite_comanda()
{
	parent.document.location = "index.php?generallayout=meniu&layout=lista_comenzi";
	
}


