/**
 * @class Libreria de funciones java script para BasLibFlash.
 *
 * Author: Jorge González <jorge@basgrani.com>
 * Created: 2009
 * Version: 1.0
 *
 * @static 
 */ 
BasLibJS = new function()
{
	// Vars.
	var NS = (navigator.appName=='Netscape')? true : false;
	var _isMouseWheel = true; // Activa o desactiva el MouseWheel.
	var _flashID = null; // Id del contenedor flash.
	var win = window;
	var doc = document;
	var isUrlHash = false; // Indica si existe una 'UrlHash'.
	var html = doc.getElementsByTagName('html')[0];
	
	/**
     * Id del contenedor flash.
     * @return
     * @static
     */
	this.setflashID = function(_ref)
	{
		_flashID = _ref;
	}
	
	
	/**
     * Añade la '#' si detecta parametros en 'UrlHash'.
     * @return
     * @static
     */
	this.setSWFAddressHash = function(_hash)
	{
		// Comprueba...
		if(_hash != "" && SWFAddress.getValue() == "/")
		{
			isUrlHash = true; // Indica si existe una 'UrlHash'.
			SWFAddress.setHistory(false); // Desactiva la historia.
			SWFAddress.setValue("/" + _hash);
			SWFAddress.setHistory(true); // Activa la historia.
		}
	}
	
	
	/**
     * Devuelve el estado del 'UrlHash'.
     * @return
     * @static
     */
	this.getSWFAddressHash = function()
	{
		return isUrlHash;
	}
	
	
	/**
     * Devuelve la url base.
     * @return
     * @static
     */
	this.getUrlBase = function()
	{
		var _url = doc.location.href;
		var _index = _url.indexOf('?');
		var _urlBase = _url.substr(0, _index);
		
		return _urlBase;
	}
	
	
	 /**
     * Codifica el texto en html.
     * @return {String}
     * @static
     */
    this.encodeHtml = function(value)
	{
		value = escape(value);
		return value;
	}
	
	
	 /**
     * Decodifica el texto en html.
     * @return {String}
     * @static
     */
	this.decodeHtml = function(value)
	{
		value = unescape(value);
		return value;
	}
	
	
	/**
     * Ajusta el alto y ancho de la ventana.
     * @return
     * @static
     */
	this.setScrollbarAt = function(mw, mh, xw, xh, hc, vc)
	{
		if(_flashID != null && swffit != null)
			swffit.fit(_flashID, mw, mh, xw, xh, hc, vc);
	}
	
	
	/**
     * Configura el scroll. (visible, hidden, scroll, auto)
     * @return
     * @static
     */
	this.setOverflowHtml = function(_x, _y)
	{
		if(this.getIEVersionNumber() == 6)
		{
			html.style.overflow = 'auto'; // Corrige error en IE6.
		}
		
		html.style.overflowX = _x;
		html.style.overflowY = _y;
	}
	
	
	 /**
     * Mueve las barras del scroll.
     * @return
     * @static
     */
	this.setScroll = function(_h, _v)
	{
		window.scroll(_h, _v);
	}
	
	
	/**
     * Configura.
     * @return
     * @static
     */
	this.setMouseWheel = function(value)
	{
		_isMouseWheel = value;
	}
	
	
	/**
     * Obtiene.
     * @return
     * @static
     */
	this.getMouseWheel = function()
	{
		return _isMouseWheel;
	}
	
	
	/**
     * Inicia el evento para controlar 'MouseWheel'.
     * @return
     * @static
     */
	this.iniDOMMouseScroll = function()
	{
		if (window.addEventListener)window.addEventListener('DOMMouseScroll', this.wheel, false);
		window.onmousewheel = document.onmousewheel = this.wheel;
	}
	
	
	/**
     * Evento 'MouseWheel'.
     * @return
     * @static
     */
	this.wheel = function(event)
	{
		if(_isMouseWheel)
			return;
		
		if (!event) event = window.event;
		
		if (event.preventDefault)
			event.preventDefault();
		
		event.returnValue = false;
	}
	
	//***********************************************************
	// UTIL.
	//
	//***********************************************************
	
	
	/**
     * Devuelve los parametros 'x', 'y', 'width', 'height' de la zona visible.
     * @return
     * @static
     */
	this.getWinClient = function(_pos)
	{
		var iw = (NS)? win.innerWidth : doc.body.clientWidth, 
			ih = (NS)? win.innerHeight : doc.body.clientHeight;
		var offset = 0;
		
		if(html == null)
			return offset;
		
		if(_pos == "x")
			offset = html.scrollLeft;
		if(_pos == "y")
			offset = html.scrollTop;
		if(_pos == "width")
			offset = iw;
		if(_pos == "height")
			offset = ih;
		
		return offset;
	}
	
	
	/**
     * Devuelve la version del IE.
     * @return
     * @static
     */
	this.getIEVersionNumber = function()
	{
		var version = 999;
		
		if (navigator.appVersion.indexOf("MSIE") != -1) 
			version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		//alert(version);
		return version;
	}
	
}