function createRoundRect(context,x,y,w,h,cornerRadius) {
  var x1 = x, x2 = x + cornerRadius, x3 = x + w - cornerRadius, x4 = x + w;
  var y1 = y, y2 = y + cornerRadius, y3 = y + h - cornerRadius, y4 = y + h;

  context.beginPath();
  context.moveTo( x1, y1);
  context.lineTo( x1, y3);
  context.arc( x2, y3, cornerRadius, Math.PI, 0.5*Math.PI, true );

  context.lineTo( x3, y4 );
  context.arc( x3, y3, cornerRadius, 0.5*Math.PI, 0.5, true);
  
  context.lineTo( x4, y2);
  
  context.lineTo( x4, y1);

}


function test() {
  var canvas = document.createElement("canvas");

    var context=canvas.getContext("2d");

    context.fillStyle = "rgb(200,0,0)";
    createRoundRect(context,50,50,200,80,10);

    context.fill();


  document.body.appendChild(canvas);
}

function canvasInit() {
  
  //var canvas = $(".subnav canvas.subnavhack");
  //$.each(canvas, function(indexInArray, valueOfElement) {
   // alert(valueOfElement);  
  //});
  /*alert(canvas);
  console.debug(canvas);
  return;   */
  //var canvas = document.getElementsByName("canvas");
   //      alert(canvas);
   //      return;
   var canvas = document.getElementById("menuitem2");
   
  if (G_vmlCanvasManager != undefined) { // ie IE
    G_vmlCanvasManager.initElement(canvas);
  }

  if (canvas.getContext) {

    var ctx = canvas.getContext('2d');
    ctx.fillStyle = "rgb(253,202,0)";
    createRoundRect(ctx,0,0,200,10,10);

    ctx.fill();
    /*el.appendChild(canvas);*/
  }
}

function createCanvas( parentEl ) {
  var canvas = document.createElement('canvas');
   
  if ( typeof(G_vmlCanvasManager) != 'undefined') { // ie IE
    G_vmlCanvasManager.initElement(canvas);
    if (canvas.getContext) {
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = "rgb(253,201,0)";
      createRoundRect(ctx,0,0,201,12,8);

      ctx.fill();
      
      $(canvas).addClass('subnavhack');

      $(parentEl).append(canvas);
    } 
  } else {
    if (canvas.getContext) {
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = "rgb(253,202,0)";
      createRoundRect(ctx,0,0,300,12,8);

      ctx.fill();
      
      $(canvas).addClass('subnavhack');

      $(parentEl).append(canvas);
    } 
  }
}

