  $(document).ready(function(){

	$('#ex1a').jqm({
		ajax: '@href',
		onLoad:load,
		//ajax: 'web/pagini/prod.php',
		//trigger: 'a.jqmodalfer',
		overlayColor: '#fff',
		overlay: 65,
		modal:true,
      	onShow: open,
      	onHide: close});

	$('#ex1c').jqm({
		ajax: '@href',
		onLoad: loaddd,
		//ajax: 'web/pagini/prod.php',
		//trigger: 'a.jqmodalfer',
		overlayColor: '#fff',
		overlay: 65,
		modal:true,
      	onShow: open,
      	onHide: close});

    $('#div_noutati a').lightBox();

	$('#poza_schimb').cycle({ 
		timeout: 5000,
		fx:     'scrollDown',
		pause:	1,
		random:	1
	});



		$('#prod_cum a.comanda')
			.click(
				function() {

				$('#ex1b').remove();
				var inputs= [];
				var i=0;
				var caut=$('#prod_cum .cum span.cant').html();
				if (caut>=1)
				{
					$('body').append('<div class="jqmWindow" id="ex1b"><img src="imagini/busy.gif" alt="loading" /> Asteptati... </div>');
					$('#ex1b').load('web/pagini/comanda.php', function() {adaugafer();});
				}
				  else
				{
					  alert('Pentru a putea comanda trebuie sa selectati cel putin un articol!!!!');
				}
				return false;
		});


		$('#prod_cmp a.compara')
			.click(
				function() {

				$('#ex1b').remove();
				var inputs= [];
				var caut=$('#prod_cmp .cum span').html();
				if (caut>=2)
				{
					$('body').append('<div class="jqmWindow" id="ex1b"><img src="imagini/busy.gif" alt="loading" /> Asteptati... </div>');
					$('#ex1b').load('web/pagini/compara.php', function() {adaugafercomp(caut);});
					$('#prod_cmp .cum span').html("0");
				}
				  else
				{
					alert('Pentru a putea face o comparare trebuie sa selectati cel putin doua articole!!!!');
				}
				return false;
		});


		$('.produs a.compar')
			.click(
				function() {

				$('#ex1b').remove();
				var inputs= [];
				var caut=$('#prod_cmp .cum span').html();
				if (caut>=3)
				{
					alert('Nu se pot compara mai mult de 3 articole simultan!!!!');
					return false;
				}

		});

            var newTriggers = $('a.jqmodalfer',this);
            $('#ex1a').jqmAddTrigger(newTriggers);

            var newTriggers = $('a.jqmodalfer1',this);
            $('#ex1c').jqmAddTrigger(newTriggers);

  });


	  var adaugafer = function () {
				latime = ((($(document).width()-760)/2)+300);
			    $('#ex1b').css("left",latime+'px');
			    $('#ex1b').css("width","760px");
				$('#ex1b').css("height","530px");

				$('#ex1b').jqm({
					overlayColor: '#fff',
					overlay: 65,
					modal:true,
			      	onShow: open,
			      	onHide: close}).jqmShow().jqmAddClose('#inchide');
				addClickHandlersOnlyForm();
				$(".comprod a").bind(
				'click', 
				function(){$(this.parentNode.parentNode).fadeOut(
					400,
					function() {
						$(this).remove();
								}
					 );
				return false;
				})

				}

	  var adaugafercomp = function (fer) {
				var lattot,latime,inaltime;
				var caut=$('#ex1b .cproddrc');
				inaltime=0;
				lattot=(fer*320);
				if ($.browser.msie)
				{
					lattot=lattot+10;
				}

				latime = ((($(document).width()-lattot)/2)+300);
				$('#ex1b').css("left","-3000px");
				$('#ex1b').css("display","inline");
				caut.each(function() {
					if (inaltime<$(this).height())
					{
						inaltime=$(this).height();
					}
				});
				$('#ex1b').css("display","none");
				inaltime=inaltime+60;
				$('#ex1b').css("height",inaltime+"px");

			    $('#ex1b').css("width",lattot+"px");
			    $('#ex1b').css("left",latime+'px');

				$('#ex1b').jqm({
					overlayColor: '#fff',
					overlay: 65,
					modal:true,
			      	onShow: open,
			      	onHide: close}).jqmShow().jqmAddClose('#inchide');
				}
	var addClickHandlersOnlyForm = function() {

      $('#trimitcomForm a.btntrimitecomanda').click(function() {

          var inputs = [];
          $(':input', this.parentNode.parentNode.parentNode.parentNode).each(function() {
            inputs.push(this.name + '=' + escape(this.value));
          })


		 $.ajax({
		   type: "POST",
		   url: "web/pagini/trimitmail.php",
		   data: inputs.join('&'),
		   success: function(msg){alert(msg);stergeprodusecos();$('#ex1b').jqmHide();},
		   error:function(){alert("Nu sa putut face transmisia !!!");}
		 });

		  return false;
        })

	}


      var load=function(hash){
		    hash.w.css("width",latpoza+"px");
			var latime = ((($(document).width()-latpoza)/2)+300);
			var inaltime = $("#cproddr").height()+50;
			if (inaltime < 500) { inaltime=500; }
			hash.w.css("height",inaltime+"px");
		  };

    // onShow : show+make the window translucent
      var open= function(hash) { hash.w.css('opacity',1).show(); };
	  

    // onHide : fade the window out, kill overlay after fade.
      var close=function(hash) {
				hash.w.fadeTo(680,0.15,function(){ 
				hash.w.slideUp("normal",function() {
				hash.o.remove();
				$('#ex1a').empty();
				$('#ex1a').append('<img src="imagini/busy.gif" alt="loading" /> Asteptati... ');
						}); 
					});
				}

      var loaddd=function(hash){
		    hash.w.css("width","600px");
			var latime = ((($(document).width()-600)/2)+300);
		    hash.w.css("left",latime+'px');
			hash.w.css("height","600px");
		  };


