$(document).ready(function(){
	 $("#port-all").click(function(event){
	   event.preventDefault();
	 });

	lastBlock = $("#a1");
    maxWidth = 370;
    minWidth = 97;	

    $("#producatori ul li a").hover(
      function(){
        $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
	$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
	lastBlock = this;
      }
    );


    $("#link1 a").click(function(){
           // var $this = $(this);
            if( $(this).is('.inactive') ) {
					$(this).attr("class","active");
					
					$("#les_producatori").fadeIn("fast");
			}
            else {
					$(this).attr("class", "inactive");
					$("#les_producatori").fadeOut("fast");
            }
            return false;
    });


	 $(".promotie").bind("mouseenter",function(){
		$(this).addClass("sesame");
	})
	 $(".promotie").bind("mouseleave",function(){
		$(this).removeClass("sesame");
	})



	$('#gallery a').lightBox();
	$('.stire span a').lightBox();





	$(".boxedend").prev().css({ paddingBottom: '0px' });
	$("#ofertespeciale .oferta").fadeOut("fast");
	$(".stire:last").addClass('nomargin');
	$(".row:odd").addClass('oddrow');
	$(".produs:odd").addClass('par');
	$("input[type=button]").addClass('submit');
	$("input[type=submit]").addClass('submit');
	$("input[type=radio]").addClass('radio');
	$("input[type=checkbox]").addClass('radio');
	$(".MsoNormal").attr('style', '').removeClass('MsoNormal');
	$("a[href='#']").attr("href", "javascript:void(0)");

}); /* se termina onready */




function arata(id) {
		$("#ofertespeciale .sevede").fadeOut("fast", function() {
			$("#ofertespeciale .sevede").removeClass("sevede");
			$(".visible").removeClass("visible");
				$("#oferta"+id).fadeIn("fast", function () {
					$("#oferta"+id).addClass("sevede");
					$("#arata"+id).addClass("visible");
			});
		});		
}



function sch(id,stop)
{
	if (id==stop) id=1;else id++;
	arata(id);
	try
	{
	clearTimeout(masa);
	}
	catch(e)
	{
		
	}
	masa=setTimeout("sch('"+id+"','"+stop+"')",9000); 
}	

function categ(id) {
	   $(".active").removeClass("active");
	   $("#categ"+id+">a").addClass("active");
	   $(".sevede").fadeOut("fast", function() {
	   $(".sevede").removeClass("sevede");
		$("#prod"+id).fadeIn("fast");
		$("#prod"+id).addClass("sevede");
		
		});
		var ctt=$("#span_cu_nr").html();
		$("#span_cu_nr").html(id);
		$("#ul_"+ctt).fadeOut('fast');
		$("#ul_"+id).fadeIn('slow');
}

/* ************************************ pentru cos *********************************** */

function esteIE()
	{
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer") 
			return true;
			
		return false;		
	}
function MakeObject() {
	var xmlhttp=false; 
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); 
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); 
        }
		return xmlhttp;
	}


function sterge(id)
{
	var request=MakeObject();
	
	

	total=1*$("#total_tot").html()-1*$("#pret_total_"+id).html();
	$("#total_tot").html(total);
$("#tr_"+id).remove();
	
			request.open('get', 'returnant.php?tip=stergecos&id=' + id);
			request.send(false);
						
		
}

function update_bucati(key,nr_bucati)
{
	var request=MakeObject();


   $("#pret_total_"+key).html(nr_bucati*$("#pret_unitar_"+key).html()); 
		total=0.0;
			$("[id^=pret_total_]").each(function(){
				total +=parseInt(this.innerHTML*100)/100;
			})
		$("#total_tot").html(total);
	
			request.open('get', 'returnant.php?tip=updatecos&key='+key+'&buc='+nr_bucati);
			request.send(false);
						
		
}
/* *********************************** sfarsit pentru cos ********************************** */

function change_color(val){
	$("#poza_principala_produs").css("backgroundImage","url("+val+")");
}

function favorite(id,del)
{
	var request=MakeObject();
	
	
	//list = document.getElementById('select_judet');
			//id = list.selectedIndex+1;
		
			if (del) 
			{
				request.open('get', 'returnant.php?tip=favdel&id=' + id);
			//	document.getElementById('oferta_'+id).className=document.getElementById('oferta_'+id).className.replace(' fav','');
				}
			else 
			{
			request.open('get', 'returnant.php?tip=fav&id=' + id);
			//document.getElementById('oferta_'+id).className=document.getElementById('oferta_'+id).className+' fav';
			}
			request.onreadystatechange = function () {
				
						if(request.readyState == 4)
					{ 
						
						var raspuns = request.responseText;	
						//alert(raspuns);
						var c = document.getElementById('faves');
						var d = document.getElementById('linkfav');
						if(esteIE() || (navigator.appName.indexOf("Opera") + 1))
						{
							if (del)
							d.outerHTML = '<span id="linkfav"><a id="addtofaves" href="javascript:favorite('+id+')">adauga la favorite</a></span>';
							else
							d.outerHTML = '<span id="linkfav"><a id="removefaves" href="javascript:favorite('+id+',1)">sterge de la favorite</a></span>';
							
							c.outerHTML = '<span id="faves">'+raspuns+'</span>';
						}
						else {
							if (del)
							d.innerHTML = '<a id="addtofaves" href="javascript:favorite('+id+')">adauga la favorite</a>';
							else
							d.innerHTML = '<a id="removefaves" href="javascript:favorite('+id+',1)">sterge de la favorite</a>';
							
							c.innerHTML = raspuns;
						}
						
					} 
			}
			request.send(false);
			}
			
function schimba_poza(poza, lightbox){
	$("#pozaprod").attr({href:lightbox})
	$("#poza_principala_produs").css({background:"url("+poza+")"})
	$('#pozaprod').lightBox();
}
			
function schimba_poza_u(poza, lightbox, unghi){
        if(unghi==1)  {
         $("#poza_unghi").hide();
         $("#poza_principala").show();
        }
        else if(unghi==0)  {
         $("#poza_unghi").show();
         $("#poza_principala").hide();
        }
	$("#pozaprod").attr({href:lightbox})
	$("#poza_principala_produs").css({background:"url("+poza+")"})
	$('#pozaprod').lightBox();
}
