///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// global.js
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

function getDocInfo()
{
	if (Ws_bNS)
	{
		if (document.documentElement && document.documentElement.clientHeight && document.body)
		{
			if (document.documentElement.clientHeight < document.body.clientHeight)
				return document.documentElement;
			else
				return document.body;
		}
		else
		{
			if (document.documentElement && document.documentElement.clientHeight)
				return document.documentElement;
			else if (document.body)
				return document.body;
		}
	}
	else
	{
		if (document.documentElement && document.documentElement.clientHeight)
			return document.documentElement;
		else if (document.body)
			return document.body;
	}
}

function debug(obj) 
{
	alert('debuggage');
	var tmp, c;
	tmp = name + '\n\n';
	c = 0;
	for (l in obj) 
	{
		tmp += (l + '=' + obj[l] + '\n');
		c++;
		if (c == 10) 
		{
			alert(tmp);
			tmp = name + '\n\n';
			c = 0;
		}
	}
	alert(tmp);
}

function disptime(v)
{
    var d = v % 10;
    var s = (v - d) / 10;
    if (s >= 60)
    {
        v = s;
        s = v % 60;
        m = (v - s) / 60;
        if (s < 10) s = '0' + s;
        r = m + 'm ' + s + 's ' + d + '0';
    }
    else
    {
        if (s < 10) s = '0' + s;
        r = '00m ' + s + 's ' + d + '0';
    }
    return r;
}

function trim(st) 
{
	st = ' ' + st;
	return st.replace(/(^\s*)|(\s*$)/g,'');
}

function htmlencode(st, nl2br) 
{
	if (typeof(st) == 'string')
	{
		st = st.replace(/&/g,'&amp;');
		st = st.replace(/"/g,'&quot;');
		st = st.replace(/'/g,'&#039;');
		st = st.replace(/</g,'&lt;');
		st = st.replace(/>/g,'&gt;');
		if (nl2br)
			st = st.replace(/\\n/g,'<br />');
	}
	return st;
}

function JSencode(st) 
{
	if (typeof(st) == 'string')
	{
		st = st.replace(/\\/g, "\\\\");
		st = st.replace(/'/g, "\\'");
	}
	return st;
}

function XMLencode(st) 
{
	return htmlencode(st);
}

function addtag(src, tag, classname, attribut, text)
{
	var obj = document.createElement(tag);
	var i;
	if (classname)
		obj.className = classname;
	
	for (i = 0 ; i < attribut.length ; i+=2)
	{
		var att = attribut[i];
		var val = attribut[i + 1];
		obj.setAttribute(att, val);
	}

	if (text)
	{
		var txt = document.createTextNode(text);
		obj.appendChild(txt);
	}

	src.appendChild(obj);
	return (obj);
}

function getBrowserZone() 
{
	var coord = new Array();
	if (document.all) 
	{
		coord[0] = document.body.clientWidth;
		coord[1] = document.body.clientHeight;
	}
	else 
	{
		coord[0] = window.innerWidth;
		coord[1] = window.innerHeight;
	}
	return coord;
}

function getPageZone() 
{
	var coord = new Array();
	if (document.all) 
	{
		coord[0] = document.body.scrollWidth;
		coord[1] = document.body.scrollHeight;
	}
	else 
	{
		coord[0] = window.innerWidth;
		coord[1] = window.innerHeight;
	}
	return coord;
}

window.tCacheObj = [];
function resetCObj() 
{
	window.tCacheObj = [];
}

function getCObj(obj) 
{
	if (!window.tCacheObj[obj])
		window.tCacheObj[obj] = getObj(obj);
	return (window.tCacheObj[obj]);
}

function getObj(obj) 
{
	if (document.all) 
		return document.all[obj];
	else 
		return document.getElementById(obj);
}

function cancelBubble(e, v)
{
	if (Ws_bNS)
//        e.stopPropagation();
        return;
	else
		event.cancelBubble = v;
		
	return false;
}

function nl2br(st) 
{
	st = '' + st;
	return st.replace(/\\n/g, '<br>');
}

window.ws_lastMD5 = '';

function getUI(key)
{
	var script = document.location.href;
	var str;
	var md5 = window.ws_lastMD5;
	while (md5 == window.ws_lastMD5)
	{
		var d = new Date();
   	str = key + script + '##' + d.getTime();
		md5 = hex_md5(str);
	}
	
	window.ws_lastMD5 = md5;
	return md5;
}

window.tCacheCss = [];
function getCCSSValue(cssclass, attrib)
{
	var csskey = cssclass + '..' + attrib;
	if (!window.tCacheCss[csskey])
		window.tCacheCss[csskey] = getCSSValue(cssclass, attrib);
	return (window.tCacheCss[csskey]);
}

function getCSSValue(cssclass, attrib)
{
	var c, s, r;
	var def;
	for (c = 0 ; c < document.styleSheets.length ; c++)
	{
		if (document.styleSheets[c].cssRules)
		{
			for (s = 0 ; s < document.styleSheets[c].cssRules.length ; s++)
			{
				def = document.styleSheets[c].cssRules[s].selectorText.toLowerCase();
				if (def == cssclass)
				{
				    r = eval('document.styleSheets[c].cssRules[s].style.' + attrib);
				    return (typeof(r) == 'undefined')?'':r;
				}
			}
		}
		else
		{
			for (s = 0 ; s < document.styleSheets[c].rules.length ; s++)
			{
				def = document.styleSheets[c].rules[s].selectorText.toLowerCase();
				if (def == cssclass)
				{
				    r = eval('document.styleSheets[c].rules[s].style.' + attrib);
				    return (typeof(r) == 'undefined')?'':r;
				}
			}
		}
	}
}

function getAbsoluteOffset(obj, use_scroll, dbg)
{
    var coord = new Array();
    var parent = obj.offsetParent;
    coord[0] = obj.offsetLeft;
    coord[1] = obj.offsetTop;
    while (parent) {
        coord[0] += parent.offsetLeft;
        coord[1] += parent.offsetTop;
        if ((use_scroll == true) && (parent.nodeName == 'DIV')) 
            coord[1] -= parent.scrollTop;
        if (dbg == 1) 
            alert(parent.id + ':' + parent.offsetTop + '--' + coord[1]);
        parent = parent.offsetParent;
        
    }
    return coord;
}

var Ws_bNS = (navigator.vendor == ('Netscape6') || navigator.product == ('Gecko'));

function init_lightbox(show) 
{
    v_nbSheet = 2;
    if ( bInitStoryEditor == "true")
    {
        v_nbSheet = 3;
    };
    
    var sheet = parseInt(getCookie('lb_sheet'), 10);
    if ((isNaN(sheet)) || (typeof(sheet) == 'undefined') || (sheet == null) || (sheet == 0))
        sheet = 1;
    
	window.oPropertySheet.nbSheet = v_nbSheet;
	window.oPropertySheet.Set(sheet);
	window.oLightBox.lbType = sheet;
	window.oLightBox.Init(show);

	var first_LB = window.oLightBox.LoadLightBoxList();
	if (first_LB)
		window.oLightBox.DisplayListDesc(first_LB);

}

function init_simple_vignbnk(aVignBnk)
{
	initVignBnk = eval(aVignBnk);
}

function init_vignbnk(aVignBnk)
{
	if (aVignBnk == null) {aVignBnk = initVignBnk;};
	
	initVignBnk = aVignBnk;
	window.oVignBnk.LoadVignette(aVignBnk);
	window.oVignBnk.InitDisplay(iStartDisplayMode);
	window.oVignBnk.StartScroll();
}

function init_player()
{
	if (window.oPlayer != null) {window.oPlayer.Init();}
}

function __wsonload() {


window.tAjaxInitLoad[1] = aInitLightboxList;
window.tAjaxInitLoad[2] = aInitStoryList;

    if (bInitLightbox) {
        init_lightbox(true);
    }
    if (bInitPlayer) {
        init_player();
    }
    if (bInitVignetteBnk) {
        init_vignbnk();
    }
}

window.tAjaxInitLoad = [];
window.tAjaxLBList = [];

window.onload=__wsonload;
/*
Event.onDOMReady(function() {
  __wsonload();
});
*/