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":
    $(".tohide_orderlink").hide();
    $(".megrendeles").removeClass("vanbenne");
    break;
    case "show":
    $(".tohide_orderlink").show();
    $(".megrendeles").addClass("vanbenne");
    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();
  
  
  
},free_van: function(vane){
  if(vane) $('.fcvan').show();
  else $('.fcvan').hide();
}
}
);
  }
  
  );



}



function testfn(data)
{
//  alert("testfn");
  
}
function update_classes(resp,nstdh)
{
var prefix="myaxu_", thecoll, ns, func;
//iterating through json vars
$.each(resp, function(pkey,pvalue){
//getting the collection
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()
{
  /*if(console!=undefined)
  {
    console.log(window.location);
  }*/
  /*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() {
     
     ajax_forms('.ajax_kosar_form');
    }}*/
  $.nyroModalManual({  minWidth: 700,
  minHeight: 420,
ajax:{url: 'kosar.php',data:{k_view: 'popup'}},
endShowContent: function() {
   ajax_forms('.ajax_kosar_form');
      $("#axsel input").change(function()
      {
	var akc=$(this).val();
	kosar_req({type: 'setdata', akcio_choice: akc});
       });
      
}, endRemove: function() {
  if(window.location.pathname=="/order.php")
  window.location.reload();
}



});
    //$('#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')});
  });

 $(function() {
    $(".scrollable").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		auto: 3000,
		speed: 1000
    });
}); 
  

  $('#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;
  });
});

$(document).ready(function(){
	$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
});



