//--------------------------------
//********************************
//******** color        **********
//********************************
//--------------------------------


//********************************
//********* color *********
//********************************
function color(r,g,b,a)
{  
   this.r = r;
   this.g = g;
   this.b = b;
   this.a = a;
}

function owk_color_rgb_to_hex() {return this.to_individual_hex(this.r)+this.to_individual_hex(this.g)+this.to_individual_hex(this.b)}

function owk_color_to_individual_hex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}


function owk_color_rgba(i_r, i_g, i_b, i_a)
{
   this.r = i_r;
   this.g = i_g;
   this.b = i_b;
   this.a = i_a;
}

color.prototype.rgb_to_hex = owk_color_rgb_to_hex;
color.prototype.to_hex = owk_color_rgb_to_hex;
color.prototype.set_rgba = owk_color_rgba;
color.prototype.to_individual_hex = owk_color_to_individual_hex;



/*
owk_ubyte alpha_percent_to_8bit(owk_float i_opacity) 
{
   return (owk_ubyte)(255.0f * i_opacity / 100.0f);
}

//-----------------------------------------------------------------------------------------------------

void color::hsl(owk_float i_hue, owk_float i_saturation, owk_float i_lightness) 
{ 
   float r1, g1, b1, rc, gc, bc, rs, gs, bs;

   while (i_hue < 0)
      i_hue += 360.0;
   while (i_hue > 360.0)
      i_hue -= 360.0;

   if (i_hue < 120) {
      rs = (120 - i_hue) / 60.0f;
      gs = i_hue / 60.0f;
      bs = 0;
   } else if (i_hue < 240) {
      rs = 0;
      gs = (240.0f - i_hue) / 60.0f;
      bs = (i_hue - 120.0f) / 60.0f;
   } else {
      rs = (i_hue - 240.0f) / 60.0f;
      gs = 0;
      bs = (360.0f - i_hue) / 60.0f;
   }
   rs = owk_min(rs,1.0f);
   gs = owk_min(gs,1.0f);
   bs = owk_min(bs,1.0f);

   rc = 2 * i_saturation * rs + (1 - i_saturation);
   gc = 2 * i_saturation * gs + (1 - i_saturation);
   bc = 2 * i_saturation * bs + (1 - i_saturation);

   if (i_lightness < 0.5) {
      r1 = i_lightness * rc;
      g1 = i_lightness * gc;
      b1 = i_lightness * bc;
   } else {
      r1 = (1 - i_lightness) * rc + 2 * i_lightness - 1;
      g1 = (1 - i_lightness) * gc + 2 * i_lightness - 1;
      b1 = (1 - i_lightness) * bc + 2 * i_lightness - 1;
   }

   redf(owk_min(1.0f, owk_max(r1, 0.0f)));
   greenf(owk_min(1.0f, owk_max(g1, 0.0f)));
   bluef(owk_min(1.0f, owk_max(b1, 0.0f)));       
}

owk_float color::huef() 
{ 
   float themin,themax,delta, h;
   
   themin = owk_min(redf(), owk_min(greenf(),bluef()));
   themax = owk_max(redf(), owk_max(greenf(),bluef()));
   delta = themax - themin;
   h = 0;
   if (delta > 0) 
   {
      if (themax == redf() && themax != greenf())
         h += (greenf() - bluef()) / delta;
      if (themax == greenf() && themax != bluef())
         h += (2 + (bluef() - redf()) / delta);
      if (themax == bluef() && themax != redf())
         h += (4 + (redf() - greenf()) / delta);
      h *= 60;
   }

   while (h < 0)
      h += 360;
   while (h > 360)
      h -= 360;

   return owk_min(360.0f, owk_max(h, 0.0f));
}

owk_float color::saturationf() 
{ 
   float themin, themax,delta, s, l;
   
   themin = owk_min(redf(), owk_min(greenf(),bluef()));
   themax = owk_max(redf(), owk_max(greenf(),bluef()));
   delta = themax - themin;
   l = (themin + themax) / 2;
   s = 0;
   if (l > 0 && l < 1)
      s = delta / (l < 0.5 ? (2*l) : (2-2*l));

   return owk_min(1.0f, owk_max(s, 0.0f));
}

owk_float color::lightnessf() 
{ 
   float themin, themax, l;
   
   themin = owk_min(redf(), owk_min(greenf(),bluef()));
   themax = owk_max(redf(), owk_max(greenf(),bluef()));
   l = (themin + themax) / 2;
   return owk_min(1.0f, owk_max(l, 0.0f));
}





*/



//--------------------------------
//********************************
//********    bitmap    **********
//********************************
//--------------------------------


//********************************
//********* bitmap *********
//********************************
function bitmap()
{    
  this.width = 0;
  this.height = 0;
  this.m_background = new color();  
  this.m_img = document.createElement('img');  
}

function bitmap_create(i_width, i_height, i_clear)
{    
  this.width = i_width;
  this.height = i_height;
}


function bitmap_load_image(i_url)
{
   this.m_img.src = i_url;
}

bitmap.prototype.create = bitmap_create;
bitmap.prototype.load_image = bitmap_load_image;

//--------------------------------
//********************************
//******** pattern_decorator******
//********************************
//--------------------------------


//********************************
//********* pattern_decorator ****
//********************************
function pattern_decorator()
{       
   this.m_mode = "1";   
   this.m_numberofimage=0;
}

function owk_pattern_decorator_create(i_layer)
{    
   this.m_layer_ptr = i_layer;
   this.size_top_left = new dim();
   this.size_top = new dim();
   this.size_top_right = new dim();
   this.size_bottom_left = new dim();
   this.size_bottom = new dim();
   this.size_bottom_right = new dim();
   this.size_left = new dim();
   this.size_middle = new dim();
   this.size_right = new dim();
}

function owk_pattern_decorator_load_image(i_url) {
   
    this.m_mode = 4;
    this.img0 = document.createElement("div"); 
  
    var mypd = this;
    this.img0.onload = function() { mypd.verify_all_image_loaded(); };
    this.img0.style.left = 0;
    this.img0.style.top = 0;

    this.img0.style.position = 'absolute'; 
    this.img0.style.backgroundRepeat = 'no-repeat';
    this.img0.style.backgroundImage = "url(" + i_url + ")";
   
   if(isIE()) {
      
      if(navigator.appVersion.split(";")[1] == " MSIE 6.0")
      {         
         this.img0.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "', sizingMethod='image', enabled=true)";
   	   this.img0.style.backgroundImage = "none";
      }
   }


   var arrayURL = i_url.split('/');

   var xmlDoc = null;

   if (window.ActiveXObject) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url.replace(arrayURL[arrayURL.length - 1], '') + "info.xml");
   }
   else if (window.XMLHttpRequest) {
       var xmlDoc2 = new window.XMLHttpRequest();
       xmlDoc2.open("GET", i_url.replace(arrayURL[arrayURL.length - 1], '') + "info.xml", false);
       xmlDoc2.send("");
       xmlDoc = xmlDoc2.responseXML;
   }
   else if (ActiveXObject("Microsoft.XMLDOM")) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url.replace(arrayURL[arrayURL.length - 1], '') + "info.xml");
   }
   
   try
   {
      if (xmlDoc!=null)
      {    
         var x=xmlDoc.getElementsByTagName("image_size");
         var size_middle_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
         var size_middle_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

         this.size_middle.width = size_middle_width;
         this.size_middle.height = size_middle_height;
         this.img0.style.top = 0;
         this.img0.style.left = 0;
         this.img0.style.width=this.size_middle.width;
         this.img0.style.height=this.size_middle.height;
      }
   }
   catch(e)
   {
      //alert(i_url.replace(arrayURL(arrayURL.lenght))+ "info.xml");
   }

   this.verify_all_image_loaded();

   this.m_layer_ptr.m_div.appendChild(this.img0);	
}
function owk_pattern_decorator_load(i_url, i_repeat_middle)
{  
   this.m_mode = 1;   
   
   this.img0 = document.createElement("div");	
   this.img1 = document.createElement("div");	
	this.img2 = document.createElement("div");	
   
   if(i_repeat_middle == true)
	{
	   this.img3 = document.createElement("div");	
	}
	else
	{
	   this.img3 = document.createElement("img");	
      this.img3.src = i_url + "left.png";
	}

   if(i_repeat_middle == true)
	{
	   this.img4 = document.createElement("div");	
	}
	else
	{
	   this.img4 = document.createElement("img");	
      this.img4.src = i_url + "middle.png";
	}

   if(i_repeat_middle == true)
	{
	   this.img5 = document.createElement("div");	
	}
	else
	{
	   this.img5 = document.createElement("img");	
      this.img5.src = i_url + "right.png";
	}
	
	this.img6 = document.createElement("div");	
	this.img7 = document.createElement("div");	
	this.img8 = document.createElement("div");
	
	var mypd = this;
   this.img0.onload = function(){mypd.verify_all_image_loaded();};	
   this.img1.onload = function(){mypd.verify_all_image_loaded();};	
   this.img2.onload = function(){mypd.verify_all_image_loaded();};	
   this.img3.onload = function(){mypd.verify_all_image_loaded();};	
   this.img4.onload = function(){mypd.verify_all_image_loaded();};	
   this.img5.onload = function(){mypd.verify_all_image_loaded();};	
   this.img6.onload = function(){mypd.verify_all_image_loaded();};	
   this.img7.onload = function(){mypd.verify_all_image_loaded();};	
   this.img8.onload = function(){mypd.verify_all_image_loaded();};	  

	this.img0.style.position = 'absolute';
   this.img1.style.position = 'absolute';
   this.img2.style.position = 'absolute';
   this.img3.style.position = 'absolute';
   this.img4.style.position = 'absolute';
   this.img5.style.position = 'absolute';
   this.img6.style.position = 'absolute';
   this.img7.style.position = 'absolute';
   this.img8.style.position = 'absolute';
  
   
   var top_right_width;
   var top_right_height;
   var top_left_width;
   var top_left_height;
   var bottom_right_width;  
   var bottom_right_height;  
   var bottom_left_width;  
   var bottom_left_height;
   var left_width;  
   var left_height;
   var right_width;  
   var right_height;

   var xmlDoc = null;

   if (window.ActiveXObject) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   else if (window.XMLHttpRequest) {
       var xmlDoc2 = new window.XMLHttpRequest();
       xmlDoc2.open("GET", i_url + "info.xml", false);
       xmlDoc2.send("");
       xmlDoc = xmlDoc2.responseXML;
   }
   else if (ActiveXObject("Microsoft.XMLDOM")) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
    
   if (xmlDoc!=null)
   {       
      var x=xmlDoc.getElementsByTagName("top_right");
      var top_right_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var top_right_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_top_right.width = top_right_width*1;
      this.size_top_right.height = top_right_height*1;

      x=xmlDoc.getElementsByTagName("top_left");
      var top_left_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var top_left_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_top_left.width = top_left_width*1;
      this.size_top_left.height = top_left_height*1;

      x=xmlDoc.getElementsByTagName("bottom_right");
      var bottom_right_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var bottom_right_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_bottom_right.width = bottom_right_width*1;
      this.size_bottom_right.height = bottom_right_height*1;

      x=xmlDoc.getElementsByTagName("bottom_left");
      var bottom_left_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var bottom_left_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_bottom_left.width = bottom_left_width*1;
      this.size_bottom_left.height = bottom_left_height*1;     

      x=xmlDoc.getElementsByTagName("left");
      var left_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var left_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_left.width = left_width*1;
      this.size_left.height = left_height*1;  

      x=xmlDoc.getElementsByTagName("right");
      var right_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      var right_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_right.width = right_width*1;
      this.size_right.height = right_height*1;      

      //Vieux code
      this.m_mode = 1;  

      var middleWidth = this.m_layer_ptr.m_region.width() - this.size_bottom_right.width-this.size_bottom_left.width;
      var middleHeight = this.m_layer_ptr.m_region.height() - this.size_top_right.height-this.size_bottom_left.height;
     
      this.size_middle.width = middleWidth*1;
      this.size_middle.height = middleHeight*1;    

      this.img0.style.top=0;
      this.img0.style.left=0;	   
      this.img0.style.width=this.size_top_left.width;	  
      this.img0.style.height=this.size_top_left.height;	   

      this.img1.style.top=0;
      this.img1.style.left=this.size_top_left.width;	
      this.img1.style.width = middleWidth;   	
      this.img1.style.height = this.size_top_left.height;
      	
      this.img2.style.top=0;	   
      this.img2.style.left=this.size_top_left.width*1 + middleWidth*1;	  
      this.img2.style.width=this.size_top_right.width;
      this.img2.style.height=this.size_top_right.height;
      
      this.img3.style.left=0;	  
      this.img3.style.top=this.size_top_left.height;
      this.img3.style.width   = this.size_left.width;
      this.img3.style.height  = middleHeight;

      this.img4.style.top=this.size_top_left.height;
      this.img4.style.left=this.size_left.width;		    
      this.img4.style.width =  middleWidth;
      this.img4.style.height = middleHeight;	 
      
      this.img5.style.top=this.size_top_left.height;
      this.img5.style.left=this.size_left.width*1 + middleWidth*1;
      this.img5.style.width  = this.size_top_right.width;
      this.img5.style.height = middleHeight;

      this.img6.style.top=this.size_top_left.height*1 + middleHeight*1;
      this.img6.style.left=0;	   
      this.img6.style.width=this.size_bottom_left.width;
      this.img6.style.height=this.size_bottom_left.height;
      
      this.img7.style.top=this.size_top_left.height*1 + middleHeight*1;
      this.img7.style.left=this.size_top_left.width;		 
      this.img7.style.width = middleWidth;
      this.img7.style.height = this.size_bottom_left.height;

      this.img8.style.top=this.size_top_right.height*1 + middleHeight*1;   
      this.img8.style.left=this.size_bottom_left.width*1 + middleWidth*1;	
      this.img8.style.width=this.size_bottom_right.width;
      this.img8.style.height=this.size_bottom_right.height;
      
      this.img0.style.backgroundRepeat = 'no-repeat';
      this.img0.style.backgroundImage	= "url("+i_url + "top_left.png"+")";

      this.img1.style.backgroundRepeat = 'repeat-x';
      this.img1.style.backgroundImage	= "url("+i_url + "top.png"+")";

      this.img2.style.backgroundRepeat = 'no-repeat';
      this.img2.style.backgroundImage	= "url("+i_url + "top_right.png"+")";
      this.img3.style.backgroundPosition = 'right top';
      this.img3.style.backgroundRepeat = 'repeat-y';
      this.img3.style.backgroundImage	= "url("+i_url + "left.png"+")";      
      this.img4.style.backgroundPosition = 'right top';
      this.img4.style.backgroundRepeat = 'repeat';
      this.img4.style.backgroundImage	= "url("+i_url + "middle.png"+")";
      this.img5.style.backgroundPosition = 'right top';
      this.img5.style.backgroundRepeat = 'repeat-y'; 
      this.img5.style.backgroundImage	= "url("+i_url + "right.png"+")";
      this.img6.style.backgroundRepeat = 'no-repeat';
      this.img6.style.backgroundImage	= "url("+i_url + "bottom_left.png"+")";
      this.img7.style.backgroundRepeat = 'repeat-x';
      this.img7.style.backgroundImage	= "url("+i_url + "bottom.png"+")";
      this.img8.style.backgroundRepeat = 'no-repeat';
      this.img8.style.backgroundImage	= "url("+i_url + "bottom_right.png"+")";

      if(isIE())
      {     
         if(navigator.appVersion.split(";")[1] == " MSIE 6.0")
         {         
            this.img0.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "top_left.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img0.style.backgroundImage = "none";
            this.img1.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "top.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img1.style.backgroundImage = "none";
            this.img2.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "top_right.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img2.style.backgroundImage = "none";
            this.img3.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "left.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img3.style.backgroundImage = "none";
            this.img4.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "middle.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img4.style.backgroundImage = "none";
            this.img5.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "right.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img5.style.backgroundImage = "none";
            this.img6.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "bottom_left.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img6.style.backgroundImage = "none";
            this.img7.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "bottom.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img7.style.backgroundImage = "none";
            this.img8.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "bottom_right.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img8.style.backgroundImage = "none";
         }
      }

      this.m_layer_ptr.m_div.appendChild(this.img0);	
      this.m_layer_ptr.m_div.appendChild(this.img1);	
      this.m_layer_ptr.m_div.appendChild(this.img2);	
      this.m_layer_ptr.m_div.appendChild(this.img3);	
      this.m_layer_ptr.m_div.appendChild(this.img4);	
      this.m_layer_ptr.m_div.appendChild(this.img5);	
      this.m_layer_ptr.m_div.appendChild(this.img6);	
      this.m_layer_ptr.m_div.appendChild(this.img7);	
      this.m_layer_ptr.m_div.appendChild(this.img8);	

      this.verify_all_image_loaded();
   }
}

function owk_pattern_decorator_verify_all_image_loaded()
{   
   try
   {
      this.m_numberofimage+=1;
      if(this.m_mode == 1)
      {   
         if(this.m_numberofimage == 9)
         {                  
            this.m_layer_ptr.on_loaded();
         }   
      }
      else if(this.m_mode == 2)
      {   
         if(this.m_numberofimage == 3)
         {
            this.m_layer_ptr.on_loaded();      
         }   
      }   
      else if(this.m_mode == 3)
      {   
         if(this.m_numberofimage == 3)
         {      
            this.m_layer_ptr.on_loaded();      
         }   
      }   
      else if(this.m_mode == 4)
      {   
         if(this.m_numberofimage == 1)
         {
            this.m_layer_ptr.on_loaded();      
         }   
      }   
   }
   catch(e){}
}

function owk_pattern_decorator_load_hori(i_url, i_repeat_middle)
{    
   var right_width;
   var right_height;
   var left_width;
   var left_height;

   var xmlDoc = null;

   if (window.ActiveXObject) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   else if (window.XMLHttpRequest) {
       var xmlDoc2 = new window.XMLHttpRequest();
       xmlDoc2.open("GET", i_url + "info.xml", false);
       xmlDoc2.send("");
       xmlDoc = xmlDoc2.responseXML;
   }
   else if (ActiveXObject("Microsoft.XMLDOM")) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   
   if (xmlDoc!=null)
   {       
      var x=xmlDoc.getElementsByTagName("right");
      right_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      right_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      x=xmlDoc.getElementsByTagName("left");
      left_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      left_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_right.width = right_width*1;
      this.size_right.height = right_height*1;
      
      this.size_middle.width = this.m_layer_ptr.m_region.width()- left_width - right_width*1;
      this.size_middle.height = right_height*1;    
      
      this.size_left.width = left_width*1; 
      this.size_left.height = left_height*1;     
      //Vieux code
      this.m_mode = 2;  
      
      this.img3 = document.createElement("div");	

      if(i_repeat_middle == true)
	   {
	      this.img4 = document.createElement("div");	
	   }
	   else
	   {
	      this.img4 = document.createElement("img");	
	   }

	   this.img5 = document.createElement("div");

	   this.img3.style.position = 'absolute';
      this.img4.style.position = 'absolute';
      this.img5.style.position = 'absolute';
      
	   var mypd = this;
	   this.img3.onload = function(){ mypd.verify_all_image_loaded();};	
      this.img5.onload = function(){ mypd.verify_all_image_loaded();};	 
   	
   	this.img3.style.backgroundRepeat = 'no-repeat';
      this.img3.style.backgroundImage	= "url("+i_url + "left.png"+")";

	   if(i_repeat_middle == true)
	   {
	      this.img4.style.backgroundRepeat = 'repeat-x';
	      this.img4.style.backgroundImage	= "url("+i_url + "middle.png"+")";
	      this.verify_all_image_loaded();
	   }
	   else
	   {
	      this.img4.src = i_url + "/middle.png";
	      this.img4.onload = function(){ mypd.verify_all_image_loaded();};	
	   }	

   	this.img5.style.backgroundRepeat = 'no-repeat';
      this.img5.style.backgroundImage	= "url("+i_url + "right.png"+")";
      
      if(isIE())
      {     
         if(navigator.appVersion.split(";")[1] == " MSIE 6.0")
         {   
            this.img3.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "left.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img3.style.backgroundImage = "none";
            this.img4.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "middle.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img4.style.backgroundImage = "none";
            this.img5.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "right.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img5.style.backgroundImage = "none";
         }
      }

      
      this.img3.style.top=0;
      this.img3.style.left=0;         
      this.img3.style.width=this.size_left.width; 
      this.img3.style.height=this.size_left.height; 
           
      this.img4.style.left=this.size_left.width;
      this.img4.style.top=0;
      this.img4.style.width=this.size_middle.width;
      this.img4.style.height=this.size_left.height;   

      this.img5.style.top=0;
      this.img5.style.left=this.size_left.width*1+this.size_middle.width*1;  
      this.img5.style.width=this.size_right.width;   
      this.img5.style.height=this.size_right.height;   

	   this.m_layer_ptr.m_div.appendChild(this.img3);	
      this.m_layer_ptr.m_div.appendChild(this.img4);	
      this.m_layer_ptr.m_div.appendChild(this.img5);	  
      this.verify_all_image_loaded();
   } 
}

function owk_pattern_decorator_load_vert(i_url, i_repeat_middle)
{   
   var bottom_height;
   var bottom_width;
   var top_width;
   var top_height;

   var xmlDoc = null;

   if (window.ActiveXObject) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   else if (window.XMLHttpRequest) {
       var xmlDoc2 = new window.XMLHttpRequest();
       xmlDoc2.open("GET", i_url + "info.xml", false);
       xmlDoc2.send("");
       xmlDoc = xmlDoc2.responseXML;
   }
   else if (ActiveXObject("Microsoft.XMLDOM")) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   
   if (xmlDoc!=null) {
      
      var x=xmlDoc.getElementsByTagName("bottom");
      bottom_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      bottom_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;
   
      x=xmlDoc.getElementsByTagName("top");
      top_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      top_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.size_top.width = top_width*1;
      this.size_top.height = top_height*1;
      
      this.size_middle.width = bottom_width*1;
      this.size_middle.height = this.m_layer_ptr.m_region.height()- top_height - bottom_height*1;      
      
      this.size_bottom.width = bottom_width*1; 
      this.size_bottom.height = bottom_height*1;     

      this.m_mode = 3;   
      
      this.img1 = document.createElement("div");	   
      
      if(i_repeat_middle == true)
	   {
	      this.img4 = document.createElement("div");	
	   }
	   else
	   {
	      this.img4 = document.createElement("img");	
	   }
   	
	   this.img7 = document.createElement("div");
   	
	   this.img1.style.position = 'absolute';
      this.img4.style.position = 'absolute';
      this.img7.style.position = 'absolute';
            
      this.img1.style.left=0;
      this.img1.style.width=this.size_top.width;;
      this.img1.style.height=this.size_top.height;
      this.img1.style.top=0;
   
      this.img4.style.left = 0;
      this.img4.style.top = this.size_top.height;
      this.img4.style.height = this.size_middle.height;
      this.img4.style.width = this.size_middle.width;
      
      this.img7.style.left=0;
      this.img7.style.top = (this.size_top.height*1+this.size_middle.height*1);   
      this.img7.style.width = this.size_bottom.width;          
      this.img7.style.height = this.size_bottom.height;          
            
      this.img1.style.zIndex = '-99';
      this.img4.style.zIndex = '-99';
      this.img7.style.zIndex = '-99';
      

	   var mypd = this;
	   this.img1.onload = function(){ mypd.verify_all_image_loaded();};	   
       this.img7.onload = function(){ mypd.verify_all_image_loaded();};	 
   	
      this.img1.style.backgroundRepeat = 'no-repeat';
	   this.img1.style.backgroundImage	= "url("+i_url + "top.png"+")";

	   if(i_repeat_middle == true)
	   {
	      this.img4.style.backgroundRepeat = 'repeat-y';
	      this.img4.style.backgroundImage	= "url("+i_url + "middle.png"+")";
	      this.verify_all_image_loaded();
	   }
	   else
	   {
	      this.img4.src = i_url + "middle.png";
	      this.img4.onload = function(){ mypd.verify_all_image_loaded();};	
	   }
   	
      this.img7.style.backgroundRepeat = 'no-repeat';
      this.img7.style.backgroundImage	= "url("+i_url + "bottom.png"+")";
     
      if(isIE())
      {     
         if(navigator.appVersion.split(";")[1] == " MSIE 6.0") {
             
            this.img1.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "top.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img1.style.backgroundImage = "none";
            this.img4.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "middle.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img4.style.backgroundImage = "none";
            this.img7.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ i_url + "bottom.png" + "', sizingMethod='scale', enabled=true)";
   	      this.img7.style.backgroundImage = "none";
         }
     } 

	  this.m_layer_ptr.m_div.appendChild(this.img1);	
      this.m_layer_ptr.m_div.appendChild(this.img4);	
      this.m_layer_ptr.m_div.appendChild(this.img7);
     
      this.verify_all_image_loaded();

   }
}

function owk_pattern_decorator_draw()
{    
   if(this.m_mode==1)
   {
      this.size_middle.height = this.m_layer_ptr.m_region.height()- this.size_top_right.height - this.size_bottom_right.height; 
      this.size_middle.width = this.m_layer_ptr.m_region.width() - this.size_top_right.width - this.size_top_left.width;
     
      this.img0.style.top=0;
      this.img0.style.left=0;	   
      this.img0.style.width=this.size_top_left.width;	  
      this.img0.style.height=this.size_top_left.height;	   

      this.img1.style.top=0;
      this.img1.style.left=this.size_top_left.width;	
      this.img1.style.width =  this.size_middle.width*1;   	
      this.img1.style.height = this.size_top_left.height;

      this.img2.style.top=0;	   
      this.img2.style.left=this.size_top_left.width*1 + this.size_middle.width*1;	  
      this.img2.style.width=this.size_top_right.width;
      this.img2.style.height=this.size_top_right.height;

      this.img3.style.left=0;	  
      this.img3.style.top=this.size_top_left.height;
      this.img3.style.width   = this.size_left.width;
      this.img3.style.height  = this.size_middle.height;

      this.img4.style.top=this.size_top_left.height;
      this.img4.style.left=this.size_left.width;		    
      this.img4.style.width =  this.size_middle.width;
      this.img4.style.height = this.size_middle.height;	 

      this.img5.style.top=this.size_top_left.height;
      this.img5.style.left=this.size_left.width*1 + this.size_middle.width*1;
      this.img5.style.width  = this.size_top_right.width;
      this.img5.style.height = this.size_middle.height;

      this.img6.style.top=this.size_top_left.height*1 + this.size_middle.height*1;
      this.img6.style.left=0;	   
      this.img6.style.width=this.size_bottom_left.width;
      this.img6.style.height=this.size_bottom_left.height;
   
      this.img7.style.top=this.size_top_left.height*1 + this.size_middle.height*1;
      this.img7.style.left=this.size_top_left.width;		 
      this.img7.style.width = this.size_middle.width;
      this.img7.style.height = this.size_bottom_left.height;

      this.img8.style.top=this.size_top_right.height*1 + this.size_middle.height*1;   
      this.img8.style.left=this.size_bottom_left.width*1 + this.size_middle.width*1;	
      this.img8.style.width=this.size_bottom_right.width;
      this.img8.style.height=this.size_bottom_right.height;
   }
   else if(this.m_mode==3)
   {
      this.size_middle.height = this.m_layer_ptr.m_region.height()- this.size_top.height - this.size_bottom.height; 
      this.img1.style.left=0;
      this.img1.style.width=this.size_top.width;;
      this.img1.style.height=this.size_top.height;
      this.img1.style.top=0;
   
      this.img4.style.left = 0;
      this.img4.style.top = this.size_top.height;
      this.img4.style.height = this.size_middle.height;
      this.img4.style.width = this.size_middle.width;
      
      this.img7.style.left=0;
      this.img7.style.top = (this.size_top.height*1+this.size_middle.height*1);   
      this.img7.style.width = this.size_bottom.width;          
      this.img7.style.height = this.size_bottom.height;          
            
      this.img1.style.zIndex = '-99';
      this.img4.style.zIndex = '-99';
      this.img7.style.zIndex = '-99';
   }
   else if(m_mode==4)
   {
      this.size_middle.width = this.m_layer_ptr.m_region.width() - this.size_right.width - this.size_left.width;

      this.img3.style.top=0;
      this.img3.style.left=0;         
      this.img3.style.width=this.size_left.width; 
      this.img3.style.height=this.size_left.height; 
           
      this.img4.style.left=this.size_left.width;
      this.img4.style.top=0;
      this.img4.style.width=middleWidth;
      this.img4.style.height=this.size_left.height;   

      this.img5.style.top=0;
      this.img5.style.left=this.size_left.width+middleWidth;  
      this.img5.style.width=this.size_right.height;   
      this.img5.style.height=this.size_right.height;   
   }
}

function owk_pattern_decorator_top_left()
{
   return this.size_top_left;
}

function owk_pattern_top()
{
   return this.size_top;
}

function owk_pattern_decorator_top_right()
{
   return this.size_top_right;
}

function owk_pattern_bottom_left()
{
   return this.size_bottom_left;
}

function owk_pattern_decorator_bottom()
{
   return this.size_bottom;
}

function owk_pattern_decorator_bottom_right()
{
   return this.size_bottom_right;
}

function owk_pattern_decorator_left()
{
   return this.size_left;
}

function owk_pattern_decorator_right()
{
   return this.size_right;
}

function owk_pattern_decorator_middle()
{
   return this.size_middle;
}

function owk_pattern_decorator_top()
{
   return this.size_top;
}

function owk_pattern_decorator_has_top_left()
{
   if(this.img0)
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_top()
{
   if(this.img1.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_top_has_right()
{
   if(this.img2.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_bottom_left()
{
   if(this.img3.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_bottom()
{
   if(this.img4.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_bottom_right()
{
   if(this.img5.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_left()
{
   if(this.img6.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_middle()
{
   if(this.img7.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

function owk_pattern_decorator_has_right()
{
   if(this.img8.style.display=='')
   {
      return true;
   }
   else
   {
      return false;
   }
}

pattern_decorator.prototype.create = owk_pattern_decorator_create;
pattern_decorator.prototype.load_image = owk_pattern_decorator_load_image;
pattern_decorator.prototype.load = owk_pattern_decorator_load;
pattern_decorator.prototype.load_hori = owk_pattern_decorator_load_hori;
pattern_decorator.prototype.load_vert = owk_pattern_decorator_load_vert;
pattern_decorator.prototype.draw = owk_pattern_decorator_draw;
pattern_decorator.prototype.verify_all_image_loaded = owk_pattern_decorator_verify_all_image_loaded;
pattern_decorator.prototype.top_left_size = owk_pattern_decorator_top_left;
pattern_decorator.prototype.top_size = owk_pattern_decorator_top;
pattern_decorator.prototype.top_right_size = owk_pattern_decorator_top_right;
pattern_decorator.prototype.bottom_left_size = owk_pattern_bottom_left;
pattern_decorator.prototype.bottom_size = owk_pattern_decorator_bottom;
pattern_decorator.prototype.bottom_right_size = owk_pattern_decorator_bottom_right;
pattern_decorator.prototype.left_size = owk_pattern_decorator_left;
pattern_decorator.prototype.middle_size = owk_pattern_decorator_middle;
pattern_decorator.prototype.right_size = owk_pattern_decorator_right;     
pattern_decorator.prototype.has_top_left = owk_pattern_decorator_has_top_left;
pattern_decorator.prototype.has_top = owk_pattern_decorator_has_top;
pattern_decorator.prototype.has_top_right = owk_pattern_decorator_top_has_right;
pattern_decorator.prototype.has_bottom_left = owk_pattern_decorator_has_bottom_left;
pattern_decorator.prototype.has_bottom = owk_pattern_decorator_has_bottom;
pattern_decorator.prototype.has_bottom_right = owk_pattern_decorator_has_bottom_right;
pattern_decorator.prototype.has_left = owk_pattern_decorator_has_left;
pattern_decorator.prototype.has_middle = owk_pattern_decorator_has_middle;
pattern_decorator.prototype.has_right = owk_pattern_decorator_has_right;   
