function dump (o){
	var str = "----\n";
	for (a in o){
		str += a + "(" +typeof(o[a])+ "): " + o[a] + "\n";
	}
	alert(str);
}

function getTextNode(root, nodeName){
	try{
		return root.getElementsByTagName(nodeName).item(0).firstChild.nodeValue;
	} catch (err) {
		return null;
	}
}

function empty(str){
	return str == null || str.length == 0;
}


function showRecepie(){
	var recepie = $("#recepie").html();
	if (empty(recepie)){
		// Do nothing
		return;
	}
	alert(recepie.replace(/<br\s*\/?>/ig, "\n"));
}
	
function showAanbieding(a, p){
	if (empty(a)) return;
	$("#aanbiedingholder").show();  		
  
  if (!empty(p)){
  	$("#price").html(p);
  	$("#priceholder").show();  	
  }
  
  $("#item").html(a);
  if ($("#item").height( ) < 25){
  	$("#itextholder").css("padding-top", "15px");
  }
}

var processor = function(data){
	 showAanbieding(getTextNode(data, 'aanbieding'), getTextNode(data, 'price'));
	 
	 
	 var recepie = getTextNode(data, 'recepie');
	 
	 if (empty(recepie)) return;
	 
	 $("#recepielink").css("display", "block");
	 
   $("#recepie").html(recepie);
   
   $('#ex3c').jqDrag('.jqDrag')
    .jqResize('.jqResize')
    .jqm({
      trigger:'#recepielink',
      overlay: 30,
      overlayClass: 'overlay',
      onShow: function(h) {
        /* callback executed when a trigger click. Show notice */
        h.w.css('opacity',1).fadeIn(); 
        },
      onHide: function(h) {
        /* callback executed on window hide. Hide notice, overlay. */
        h.w.fadeOut("fast", function() { if(h.o) h.o.remove(); }); } 
      });


   
   //alert("price: " + price + "\n" + "recepie: " + recepie + "\n" + "aanbieding" + aanbieding);
   
}

$(document).ready(function(){
 var email = $("#email").text().replace("[at]", "@").replace("[punt]", ".")
 
 $("#email").html("<a style='color:cyan' href='" + email + "'>" +email +"</a>");
 $.get("visboer.xml", {}, processor, "xml");
});

