// JavaScript Document

/*****************************************

  Round`ozer -- cornered design solution

  (c) 2005 Pixel-Apes.

  -----------------------------------

  Version 0.2

  Round`ozer is a simplifier for round-cornered design.

  See README.TXT and LICENSE.TXT for further details

  Call "Roundozer.auto()" to do the stuff.

******************************************/

Roundozer = 
{
   // customization of Roundozer: you could create any sequence
   // "something-CLASS-XX", provide "something-CLASS-pro", "something-CLASS-contra"
   patterns : {
      "roundozer" : { sequence : [ "00", "01", "10", "11" ] },
      "tabbed"    : { sequence : [ "00", "01" ],
                      noTable  : true }
              },
   _patternsReady : false,
   buildPatterns : function()
   {
     for( var i in this.patterns )
     {
       this.patterns[i].regExp        = new RegExp( "(\\s|^)("+i+"-\\S+)", "i" );
       this.patterns[i].regExpReplace = new RegExp( "\s?("+i+"-\\S+)\s?", "gi" );
     }
   },


   // rounds all tags with specified tagName and "roundozer-*" CSS className
   // default value of tagName is "div"
   auto : function( tagName )
   {
     if (!this._patternsReady) this.buildPatterns();

     if (tagName === this.undef()) tagName = "div";
     var _tags = document.getElementsByTagName( tagName );
     var tags = [];
     // see, we copying collection because original one would be changing thru time
     for( var i=0; i<_tags.length; i++) tags[i] = _tags[i];
     for( var i=0; i<tags.length; i++ )
       if (tags[i].className != this.undef())
         if (!tags[i].className.match( /\sroundozer-skip/i ))
           this.processElement( tags[i] );
   },

   // rounds corners of some HTML element specified by id
   processById : function( id )
   {
     var el = document.getElementById( id );
     if (el) this.processElement( el );
   },

   // rounds corners of some HTML element specified by reference
   processElement : function( el )
   {
     if (el.className.match( /\sroundozer-skip/i )) return;

     if (!this._patternsReady) this.buildPatterns();
     for( var i in this.patterns )
       this._processElement( el, i );

     el.className+= " roundozer-skip ";
   },
   _processElement : function( el, pattern )
   {
     var m = el.className.match( this.patterns[pattern].regExp );
     if (m == this.undef()) return;

     var _class = el.className.replace( this.patterns[pattern].regExpReplace, " ");
     var _type = m[2];


     var inner = document.createElement( "div" );
     inner.className = _class + " roundozer-nofloat roundozer-skip";
     inner.style.fontSize = "100%";
     inner.style.margin = "0";
     var prev = inner;

     if (!this.patterns[pattern].noTable)
     {
     var ta = document.createElement( "table" );
     var tr = ta.insertRow(0);
     var td = tr.insertCell(0);
     td.appendChild(inner);

     ta.className = "roundozer-tablet roundozer-skip";
     tr.className = "roundozer-tablet roundozer-skip";
       td.className = "roundozer-tablet roundozer-skip "+_type+"-pro";
     prev = ta;
     }

     for (var i=0; i<this.patterns[pattern].sequence.length; i++)
       {
         var next = document.createElement( "div" );
       next.className = _type + "-" + this.patterns[pattern].sequence[i] + 
                        " roundozer-skip";

       if (i+1 == this.patterns[pattern].sequence.length)
           next.className+= " "+_type+"-contra ";
         
         next.appendChild( prev );
         prev = next;
       }

     var next = document.createElement( "div" );
     next.appendChild( prev );

     // migrate dom childs from el to inner
     while( el.hasChildNodes() )
     {
       var removed = el.removeChild( el.childNodes[0] );
       inner.appendChild( removed );
     }

     // insert structure built in el
     el.appendChild( next );
   },

   
    // simple function to end the class definition.
    undef : function( param ) { return param; }
};











function pviiClassNew(obj, new_style) { //v2.7 by PVII
  obj.className=new_style;

}



/*
Скрипт, изменяющий теги title и alt
*/


window.onerror = null;

tooltip = {
attr_name: "tooltip",
blank_text: "",
newline_entity: "   ",
max_width:0,
delay: 300,


t: document.createElement("DIV"),
c: null,
g: false,

m: function(e){
if (tooltip.g){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
tooltip.a(x, y);
}
},

d: function(){
tooltip.t.setAttribute("id", "tooltip");
document.body.appendChild(tooltip.t);
a = document.all ? document.all : document.getElementsByTagName("*");
aLength = a.length;
for (var i = 0; i < aLength; i++){

if (!a[i]) continue;
tooltip_title = a[i].getAttribute("title");
if (tooltip_title && typeof tooltip_title != "string") tooltip_title = "";

tooltip_alt = a[i].getAttribute("alt");
tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip.blank_text;
if (tooltip_title || tooltip_blank){
a[i].setAttribute(tooltip.attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip.blank_text : tooltip.blank_text) : tooltip_title);
if (a[i].getAttribute(tooltip.attr_name)){
a[i].removeAttribute("title");
if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}else if (tooltip_alt && a[i].complete){
a[i].setAttribute(tooltip.attr_name, tooltip_alt);
if (a[i].getAttribute(tooltip.attr_name)){
a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}
if (!a[i].getAttribute(tooltip.attr_name) && tooltip_blank){
}
}
document.onmousemove = tooltip.m;
window.onscroll = tooltip.h;
tooltip.a(-99, -99);
},

s: function(e){
d = window.event ? window.event.srcElement : e.target;
if (!d.getAttribute(tooltip.attr_name)) return;
s = d.getAttribute(tooltip.attr_name);
if (tooltip.newline_entity){
s = s.replace(/\&/g,"&amp;");
s = s.replace(/\</g,"&lt;");
s = s.replace(/\>/g,"&gt;");
s = s.replace(eval("/" + tooltip.newline_entity + "/g"), "<br />");
tooltip.t.innerHTML = s;
}else{
if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
tooltip.t.appendChild(document.createTextNode(s));
}
tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", tooltip.delay);
tooltip.g = true;
},

h: function(e){
tooltip.t.style.visibility = "hidden";
if (!tooltip.newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
clearTimeout(tooltip.c);
tooltip.g = false;
tooltip.a(-99, -99);
},

l: function(o, e, a){
if (o.addEventListener) o.addEventListener(e, a, false);
else if (o.attachEvent) o.attachEvent("on" + e, a);
else return null;
},

a: function(x, y){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
)[0];

w_width = oCanvas.clientWidth ? oCanvas.clientWidth + oCanvas.scrollLeft : window.innerWidth + window.pageXOffset;
w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop; // should be vice verca since Opera 7 is crazy!

tooltip.t.style.width = ((tooltip.max_width) && (tooltip.t.offsetWidth > tooltip.max_width)) ? tooltip.max_width + "px" : "auto";

t_width = tooltip.t.offsetWidth;
t_height = tooltip.t.offsetHeight;

tooltip.t.style.left = x + 8 + "px";
tooltip.t.style.top = y + 8 + "px";

if (x + t_width > w_width) tooltip.t.style.left = w_width - t_width + "px";
if (y + t_height > w_height) tooltip.t.style.top = w_height - t_height + "px";
}
}

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
if (root.addEventListener) root.addEventListener("load", tooltip.d, false);
else if (root.attachEvent) root.attachEvent("onload", tooltip.d);
} 

