//=======================================================\\
//                    13thparallel.org                   \\
//                   Copyright (c) 2002                  \\ 
//   see (13thparallel.org/?title=about) for more info   \\
//=======================================================\\

var px = document.layers || window.opera ? "" : "px";

// basic object constructor
function make (id) {
	this.elm = document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : null;
	if (!this.elm) return null;
	this.css = this.elm.style;
	this.obj = id + 'Obj';
	eval(this.obj + ' = this');
	this.x = this.elm.offsetLeft ? this.elm.offsetLeft : 0;
	this.y = this.elm.offsetTop ? this.elm.offsetTop : 0;
	this.w = this.elm.offsetWidth ? this.elm.offsetWidth : 0;
	this.h = this.elm.offsetHeight ? this.elm.offsetHeight : 0;
}

make.prototype.show = function() {
	this.css.visibility = "visible";
}

make.prototype.hide = function() {
	this.css.visibility = "hidden";
}

make.prototype.moveTo = function(x, y) {
	if (x != null) {
		x = Math.round(x);
		this.x = x;
		this.css.left = x + px;
	}
	if (y != null) {
		y = Math.round(y);
		this.y = y;
		this.css.top = y + px;
	}
}

make.prototype.moveBy = function(x, y) {
	this.moveTo(this.x + x, this.y + y);
}

make.prototype.getW = function() {
	if (this.elm.offsetWidth) return this.elm.offsetWidth;
	else if (parseInt(this.css.width)) return parseInt(this.css.width);
	else return 0;
}

make.prototype.setW = function(num) {
	this.css.width = num + px;
}

make.prototype.getH = function() {
	if (this.elm.offsetHeight) return this.elm.offsetHeight;
	else if (parseInt(this.css.height)) return parseInt(this.css.height);
	else return 0;
}

make.prototype.setH = function(num) {
	this.css.height = num + px;
}

getViewportWidth = function() {
	var width = 0;
	if( document.documentElement && document.documentElement.clientWidth ) {
		width = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth ) {
		width = document.body.clientWidth;
	}
	else if( window.innerWidth ) {
		width = window.innerWidth - 18;
	}
	return width;
};

getViewportHeight = function() {
	var height = 0;
	if( document.documentElement && document.documentElement.clientHeight ) {
		height = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		height = document.body.clientHeight;
	}
	else if( window.innerHeight ) {
		height = window.innerHeight - 18;
	}
	return height;
};


// measure the left position of an element, relative to the page
// note that the element does not need to have any css positioning
function getPageLeft(elm) {
	var x = 0;
	while (elm.offsetParent && typeof elm.offsetLeft != "undefined") {
		x += elm.offsetLeft;
		elm = elm.offsetParent;
	}
	return x;
}

// measure the top position of an element, relative to the page
// note that the element does not need to have any css positioning
function getPageTop(elm) {
	var y = 0;
	while (elm.offsetParent && typeof elm.offsetTop != "undefined") {
		y += elm.offsetTop;
		elm = elm.offsetParent;
	}
	return y;
}

// end


//=======================================================\\
//                  start meddle add-ons                 \\
//=======================================================\\

function doPop(where,w,h,t,l) {
if (!t) t=0;
if (!l) l=0;
window.open(where, 'popupwindow', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=no,resizable=no'); 
}

make.prototype.slideBolas = function(){
	this.timeSlide(aleat(10,360),aleat(10,160),aleat(3000,6000),aleat(-1.5,1.5),null,'this.slideBolas()');
}

make.prototype.bg = function(ref){	
	this.css.backgroundColor=ref;
}

make.prototype.bgi = function(ref){	
	this.css.backgroundImage="url("+ref+")";
}

aleat = function(min,max){
return (Math.round(Math.random()*(max-min)))+min;
}

// generic cookie check in javascript:
function getCookie(nombrecookie) {
var buscamos = nombrecookie + "=";
if (document.cookie.length > 0) {
    i = document.cookie.indexOf(buscamos);
    if (i != -1) {
      i += buscamos.length;
      j = document.cookie.indexOf(";", i);
      if (j == -1)
        j = document.cookie.length;
      return unescape(document.cookie.substring(i,j));
    }
  }
}

// ADD EVENTS method by Scott Andrew (www.scottandrew.com):
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    return false
  }
} 



// wrapper function: centers elements in page:
wrapElement = function()  {
	var wW = wrapperObj.getW();
	var wH = wrapperObj.getH();

	var setX = ( getViewportWidth() - wW ) / 2;
	var setY = ( getViewportHeight() - wH ) / 2;
	
	if( setX < 0 ) setX = 0;
	if( setY < 0 ) setY = 0;

	wrapperObj.moveTo(setX,setY);
	
}


//=======================================================\\
//                  end meddle add-ons                   \\
//=======================================================\\