// Self-made analog of $() function in jQuery or Prototype (=
function by_id(b){return document.getElementById(b)}function by_tag(b,a){return(a?a:document).getElementsByTagName(b)}function by_class(b,a,d){a=by_tag(d?d:"*",a?a:document);d=[];for(var c=0,e=0;a[c];){if(a[c].className==b){d[e]=a[c];e++}c++}return d}function by(b,a,d){var c=0;c=b.substr(0,1);return c=c=="#"?by_id(b.substr(1)):c=="."?by_class(b.substr(1),a,d):by_tag(b,a)};

// Get styles
function getStyle(e,s){
  var v=null;
  if(document.defaultView && document.defaultView.getComputedStyle){
    var cs=document.defaultView.getComputedStyle(e,null);
    if(cs && cs.getPropertyValue) v=cs.getPropertyValue(s);
  }
  if(!v && e.currentStyle) v=e.currentStyle[s];
  return v;
}

// Bookmark =/
var urlAddress = document.location;
var pageName = document.title;

function bookmark_(){
 if (window.sidebar) // firefox
 window.sidebar.addPanel(pageName, urlAddress, "");
 else if(window.opera && window.print){ // opera
 var elem = document.createElement('a');
 elem.setAttribute('href',urlAddress);
 elem.setAttribute('title',pageName);
 elem.setAttribute('rel','sidebar');
 elem.click();
 } else if(document.all)// ie
 window.external.AddFavorite(urlAddress, pageName);
}

// Show or hide object
function show_hide (obj,dis_) {
	var dis = dis_?dis_:'block';
	obj.style.display = (obj.style.display!='none')?('none'):(dis);
}

// Dimentions of work area
function getClientWidth(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth}
function getClientHeight(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight}

// Return dimentions and position of element
function getElementPosition(elemId) {
    var elem = document.getElementById(elemId);
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    var l = 0;
    var t = 0;
    while (elem) {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }
    return {'left':l, 'top':t, 'width': w, 'height':h};
}

// Parameters for sort() method
function sortMin(a,b){return a - b}
function sortMax(a,b){return b - a}

// Exposes all the elements of height, width, or both, equal to the maximum of them
function getMax(obj_,par_) {
	var obj = by(obj_);
	var par = (par_)?(par_):('both');
	var w = Array(), h = Array();
	for (var i=0;i<obj.length;i++) {
		w[i] = obj[i].offsetWidth;
		h[i] = obj[i].offsetHeight;
	}
	var maxWidth = w.sort(sortMax)[0];
	var maxHeight = h.sort(sortMax)[0];
	switch (par) {
		case 'width': {return maxWidth} break;
		case 'height': {return maxHeight} break;
		case 'both': {return {'width':maxWidth, 'height':maxHeight}} break;
		default: {return false} break;
	}
}

// Centering element
var centerObj = function(obj,pos_) {
	var pos = (pos_)?(pos_):('fixed');
    obj.style.position = pos;
    obj.style.top = '50%';
    obj.style.left = '50%';
    obj.style.margin = '-'+(obj.offsetHeight/2)+'px 0 0 -'+(obj.offsetWidth/2)+'px';
}

function fixEvent(e) {
	e = e || window.event
	if ( e.pageX == null && e.clientX != null ) {
		var html = document.documentElement
		var body = document.body
		e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
		e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
	}
	if (!e.which && e.button) {
		e.which = e.button & 1 ? 1 : ( e.button & 2 ? 3 : ( e.button & 4 ? 2 : 0 ) )
	}
	return e
}

var tool_tip = function() {

	var tooltip = by('#tooltip');
	var toolbody = by('#tool_body');
	tooltip.onmouseover = function() {
		document.onmousemove = function(e){mouseMove(e)}
	}
	
	function mouseMove(event){
		event = fixEvent(event);
		tooltip.style.top=event.pageY+5+'px';
		tooltip.style.left=event.pageX+5+'px';
	}	

	var tmb = by('.mbox-img');
	for (var i=0;i<tmb.length;i++) {
		tmb[i].onmouseover = function(e) {
			tooltip.style.display='block';
			toolbody.innerHTML='<div class="tool_bg"></div>'+this.getElementsByTagName('span')[0].innerHTML;
			document.onmousemove = function(e){mouseMove(e)}
		}
		tmb[i].onmouseout = function(e) {
			tooltip.style.display='none';
			document.onmousemove = function(e){return false}
		}
	}
}

