
$(document).ready(function(){


wyborbox = 0;

$(".list02").hide();
$("#wig-pot-0").show();

//ustawienie hide() dla domyślnie wybranych przepisów
var def_id;
for (i = 0; i < 12; i++){
  def_id = $("#przepis"+i).attr("value");
  if (def_id){
	$('#'+def_id).parent().hide();	
  }
}

var test;

   
if ($("#instr").attr("value") == 0) {
	$(".cntHide03").colorbox({href:".cntHideIns03", open:true});
}


$(".close").live('click',function(event){
  var index = $(this).index("div.close");
    
  //ustawienie show() dla potrawy, która jest zamykana
  var old_id = $("#przepis"+index).attr("value");
  $('#'+old_id).parent().show();
  
  $("#przepis"+index).attr("value",0);
  
//$.post("/kulinarne-inspiracje/session/0", {"nr": index}); 
 
 $.post("/kulinarne-inspiracje/session/0", {"nr": index, "instrukcja" : 1},
   function(data) {
	  if($.browser.msie && parseInt($.browser.version) <=7) {
		location.reload();
	  }
   });
 
$(this).parent().html('<div class="close add"><a class="cntHide cboxElement" style="color: #af150f;" href=".cntHideIns">+</a></div><div class="cnt"><img src="/kulinarne-inspiracje/images/boze-narodzenie-2011/empty-box.gif" width="128" height="128" alt="" /><p style="cursor: default;"></p></div><!-- end cnt --><div class="change"><a class="cntHide cboxElement" href=".cntHideIns">dodaj przepis &raquo;</a></div><!-- end change -->' );
  $(".cntHide, .cntHide02").colorbox({inline:true});



});

			
$('.cntHide').live('click',function(event){
	$(this).parent().parent().addClass("selectedBox");
});

$('.cntHide02').live('click',function(event){
 $("#tester").empty().html('<img src="http://www.szperaj.com/hostingfoto/images/loading.gif" style="position:absolute;top:50%;left:50%;margin-top:-25px;margin-left:-25px;"/>');
 var przepisAdres = '/kulinarne-inspiracje/potrawy-wigilijne-przepisy/'+$(this).attr("id");
 $.ajax({
  url: przepisAdres,
  cache: false,
  error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
  },
  success: function(html){
	  var resulthtml = html;
    document.getElementById('tester').innerHTML = resulthtml;
  }
 });
});


$('.choosePrzepis').live('click',function(event){
//	alert ('chosen!');
	var index = $('.selectedBox').index('.box');
	
	//ustawienie show() dla potrawy, która znika z listy 12 wybranych
	var old_id = $("#przepis"+index).attr("value");
	$('#'+old_id).parent().show();
	
	var markup = '<div class="close" title="usuń przepis">x</div><div class="cnt"><img src="/kulinarne-inspiracje/img/id/${idFoto}/140/94" width="140" height="94" alt="" /><p><a class="cntHide02 cboxElement" href=".cntHideIns02" title="" id="${url}">${Name} &raquo;</a></p></div><div class="change"><a class="cntHide cboxElement" href=".cntHideIns" title="">zmień przepis &raquo;</a></div>';
	//var new_markup = markup.replace("XXX", index);
	$.template( "boxTemplate", markup);
	$( ".selectedBox" ).empty();
	id = $(this).attr("id");
	
	//ustawienie hide() dla wybranej potrawy
	$(this).parent().hide();
	
	var no = index;
	$.post("/kulinarne-inspiracje/session/"+id, {"nr": no});
	
	 $.post("/kulinarne-inspiracje/session/"+id, {"nr": no, "instrukcja" : 1},
		function(data) {
		  if($.browser.msie && parseInt($.browser.version) <= 7) {
			location.reload();
		  }
	 });
	
	$("#przepis"+no).attr("value",id);
	$.tmpl( "boxTemplate", boxes[id] ).appendTo( ".selectedBox" );
	$('.selectedBox').removeClass('selectedBox');
	$(".cntHide, .cntHide02").colorbox({inline:true});
	$.colorbox.close();
	$(".selected").removeClass("selected");
	$(".list01 li a").first().addClass("selected");
	$(".list02").hide();
	$("#wig-pot-0").show();
});

$(document).bind('cbox_closed', function(){
	if (wyborbox){
		wyborbox = 0;
		$(".cntHide").colorbox({href:".cntHideIns", open:true});
	}else {
		 $('.selectedBox').removeClass('selectedBox');
		 $(".selected").removeClass("selected");
		 $(".list01 li a").first().addClass("selected");
	}
	
});

$('#wig-kat-0').click(function () {
	$(".list02").hide();
	$('#wig-pot-0').show();
});
$('#wig-kat-1').click(function () {
	$(".list02").hide();
	$('#wig-pot-1').show();
});
$('#wig-kat-2').click(function () {
	$(".list02").hide();
	$('#wig-pot-2').show();
});
$('#wig-kat-3').click(function () {
	$(".list02").hide();
	$('#wig-pot-3').show();
});
$('#wig-kat-4').click(function () {
	$(".list02").hide();
	$('#wig-pot-4').show();
});
$('#wig-kat-5').click(function () {
	$(".list02").hide();
	$('#wig-pot-5').show();
});
$('#wig-kat-6').click(function () {
	$(".list02").hide();
	$('#wig-pot-6').show();
});

$('.getPrzepis').click(function () {
  wyborbox = 1;
  $("#tester").empty().html('<img src="http://www.szperaj.com/hostingfoto/images/loading.gif"/>');
 var przepisAdres = '/kulinarne-inspiracje/potrawy-wigilijne-przepisy/'+$(this).attr("id");
 $.ajax({
  url: przepisAdres,
  cache: false,
  error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
  },
  success: function(html){
	  var resulthtml = html;
    document.getElementById('tester').innerHTML = resulthtml;
  }
 });

});



});

