function p$(targetid)
{
  return $('#' + targetid).get(0);
}
function kosar_req(pars)
{
//  alert("kreq");
  $.getJSON("kosar.php",  pars,
  function(data) {
//      alert("ajaxfun");
      update_classes(data,{kosar_empty: function(hs)
{
  
  switch(hs)
  {
    case "hide": 
      document.getElementById('box_bottom').innerHTML='A kosár jelenleg üres.';
      $(".tohide_orderlink").hide(); 
      break;
    case "show": 
      $(".tohide_orderlink").show();
      break;
    
  }
},
kosaron: function(id){
  //alert('on'+id);
  $('.myaxu_kosarbag_'+id).show();
  $('.myaxu_kosarg_'+id).hide();
  
},
kosaroff: function(id){
  //alert('off'+id);
  $('.myaxu_kosarg_'+id).show();
  $('.myaxu_kosarbag_'+id).hide();
  
  
  
}

}
);
  }
  
  );



}



function testfn(data)
{
//  alert("testfn");
  
}
function update_classes(resp,nstdh)
{
var prefix="myaxu_", thecoll, ns, func;
//ns=$H(nstdh);

//iterating through json vars
//alert("udc");
$.each(resp, function(pkey,pvalue){

//$(resp).map(function(pvalue,pkey) {
//getting the collection
//alert(pvalue+','+pkey);
thecoll=$("."+prefix+pkey);
//getting the func to invoke on all the matched elements
func=nstdh[pkey];
//by default update the contents of the matched elements with the value
if(!$.isFunction(func))
{
  thecoll.html(pvalue);
  ajax_forms("."+prefix+pkey+" .ajax_kosar_form");
} else
{
//invoke the function if it exists with the value as parameter

  func(pvalue);
}


});
  
}

function ajax_forms(selector) //generalize with callbacks?
{
//alert("ajax_forms");
//handling the click element of the remove button
var thecoll;
thecoll=$(selector).filter(":not(.ajax_forms_active)");
thecoll.find(" .remv").click(function(ev)
  {
    var el=ev.target;
    $(this).parents("form").find(".input_qty").get(0).value=0;
   });
//handling the submit element, stopping the event and submitting via ajax
thecoll.submit(function(ev){
//alert("sm");
ev.preventDefault();
//alert("submit");
//var serd=ev.target.formSerialize();
var serd= $(this).formSerialize();

kosar_req(serd);


return false;
});
thecoll.addClass("ajax_forms_active");

}

function showkosar()
{
  /*Lightbox.showBoxString('<img id="ajaxloading" src="img/ajax_loading.gif" />', 700, 400);
  new Ajax.Updater('boxContents','kosar.php',{method: 'get',parameters: {k_view: "popup"},onComplete: function() {
    ajax_forms('#boxContents .ajax_kosar_form');
    }});*/
  /*url: "kosar.php",
  ajax: {data: {k_view: 'popup'},success: function() {
     //alert("BAZMEEEG!!!!");
     ajax_forms('.ajax_kosar_form');
    }}*/
  $.nyroModalManual({  minWidth: 700,
  minHeight: 400,
ajax:{url: 'kosar.php',data:{k_view: 'popup'}},
endShowContent: function() {
   ajax_forms('.ajax_kosar_form');
  
}



});
    //$('#contenttoupdate').load('kosar.php',{k_view: 'popup'},function(resp) {
      //$('#kosar_box').load('kosar.php',{k_view: 'popup'},function(resp) {
        //  ajax_forms('#kosar_box .ajax_kosar_form');

      //});
    
//ajax_forms('#contenttoupdate .ajax_kosar_form');
//$(".ajax_kosar_form").removeClass('ajax_kosar_form');
  
  
}

$(function() {
  //Lightbox.init();
//$(document).append("<div id='kosar_box'>");	
$(".fav").live("click",function() {
  $(this).removeClass("fav").addClass("notfav").html("Kedevencekhez ad");
  $.get("setfaves.php",{fn: "unset", id: $(this).attr('rel')});
  });
$(".notfav").live("click",function() {
  $(this).removeClass("notfav").addClass("fav").html("Kedvencekből eltávolít");;
  $.get("setfaves.php",{fn: "set", id: $(this).attr('rel')});
  });

/*$("div.scrollable").scrollable({
interval: 4000,
loop: true
});*/
  $('#close').click(function(ev) {
    kosar_req({type: "refresh", k_id: page_prodid});
  });
  $("a.lightbox").nyroModal();
  /*click(function(ev)
    {
      
       event.preventDefault();
      
      el=Event.findElement(ev,'a');
      if (el != document)
      Lightbox.showBoxImage(el.readAttribute("href"));
      
    });*/
  
  $('.megrendeles').click(showkosar);
  ajax_forms(".ajax_kosar_form");
  //$(".ajax_kosar_form").removeClass('ajax_kosar_form');
}

);

$(document).ready(function() {
  $('#slickbox').hide();
  $('a#slick-toggle').click(function() {
 $('#slickbox').toggle(400);
 return false;
  });
});


