
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/*
/*IMAGE LOADER
*/

var m_aImages = {};
var m_bImagesLoaded = false;

function loadImages(p_sources, p_callback)
{
    var tmp_nLoadedImages = 0;
    var tmp_nNumImages = 0;

    for (var src in p_sources)
	{
        tmp_nNumImages++;
        m_aImages[src] = new Image();
        m_aImages[src].onload = function()
		{
            if (++tmp_nLoadedImages >= tmp_nNumImages)
			{
				m_bImagesLoaded = true;
                p_callback();
            }
        };
        m_aImages[src].src = p_sources[src];
    }
}

//CHECK BROWSER

function isBrowser(p_browsername)
{
	var tmp_sAgent = navigator.userAgent.toLowerCase(); 
	 
	if (tmp_sAgent.indexOf(p_browsername.toLowerCase()) > -1)
	{  
	     return true;  
	}  
	
	return false;
}

var m_aTweenRegister = new Array();
function registerTween(p_tween)
{
	p_tween.onMotionFinished = deleteTween;
	
	for(var i=0; i < m_aTweenRegister.length; i++)
	{
		if(m_aTweenRegister[i].obj == p_tween.obj && m_aTweenRegister[i].prop == p_tween.prop)
		{
			m_aTweenRegister[i].stop();
			m_aTweenRegister[i] = null;
			m_aTweenRegister[i] = p_tween;
			
			return m_aTweenRegister[i];
		}
	}
	m_aTweenRegister.push(p_tween);
	return p_tween;
}

function deleteTween(e)
{
	for(var i=0; i < m_aTweenRegister.length; i++)
	{
		if(m_aTweenRegister[i].obj == e.target.obj && m_aTweenRegister[i].prop == e.target.prop)
		{
			m_aTweenRegister.splice(i, 1);
		}
	}
}

function removeTween(p_object, p_property)
{
	for(var i=0; i < m_aTweenRegister.length; i++)
	{
		if(m_aTweenRegister[i].obj == p_object && m_aTweenRegister[i].prop == p_property)
		{
			m_aTweenRegister[i].stop();
			m_aTweenRegister.splice(i, 1);
		}
	}
}


//Get css property
function getNumber(p_value)
{
	Number(p_value.replace(/[^-\d\.]/g, ''));
}

function getstyle(obj, cAttribute)
{
    if (obj.currentStyle)
    {
        this.getstyle = function (obj, cAttribute) {return obj.currentStyle[cAttribute];};
    } else
    {
        this.getstyle = function (obj, cAttribute) {return document.defaultView.getComputedStyle(obj, null)[cAttribute];};
    }
    return getstyle(obj, cAttribute);
}

document.deepCss= function(who, css){
    var val= '', str= css.dasher(false);
    val= who.style[str];
    if(!val){
        if(who.currentStyle) val= who.currentStyle[str];
        else{
            var dv= document.defaultView || window;
            if(dv && dv.getComputedStyle){
                str= css.dasher(true);
                val= dv.getComputedStyle(who,'').getPropertyValue(css);
            }
        }
    }
    return val || '';
}

String.prototype.dasher=function(boo){
    var x= this;
    if(/^[A-Z]+$/.test(x) || /\-/.test(x)) x = x.toLowerCase();
    if(boo=== true ){
        if(/[a-z][A-Z]/.test(x)){
            x= x.replace(/[A-Z]/g, function(w){
                return '-' + w.toLowerCase();
            })
        }
    }
    else if(/\-/.test(x)){
        x= x.replace(/\-[a-z]/g, function(w){
            return w.charAt(1).toUpperCase() + w.substring(2);
        })
    }
    return x;
}
