
function getMovie(movieName)
{
    if(navigator.appName.indexOf("Microsoft") != -1)
    {
        return window[movieName];
    }
    else
    {
        if(document[movieName].length != undefined)
        {
            return document[movieName][1];
        }
        return document[movieName];
    }
}

function handle(delta) {
        getMovie("flashq").sendMouse(delta);
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}
function keyDown(e)
{ 
	if(e==null)
	  e=BrowserCompatible.getEvent(e);
	var keycode=BrowserCompatible.getKeyCodeEx(e);
	if ( (keycode[0] >=112 && keycode[0] <=123) || keycode[0] == 9 || keycode[0] == 8)
	{
		if(navigator.appName.indexOf("Microsoft") != -1){
			e.keyCode = 0;
			e.cancelBubble = true;
			e.returnvalue = false;
		}
		getMovie("flashq").sendKey(keycode[0],keycode[1],keycode[2],keycode[3]);
		return false;
	}
	
	getMovie("flashq").sendKey(keycode[0],keycode[1],keycode[2],keycode[3]);
	
	return false;
}

function htmlFocus() {
	
	document.body.focus();
}

function BroswerisOpera()
{
	if(navigator.userAgent.indexOf("Opera") > -1)
		return 1;
	return 0;
}

function setBackgroundColor(bgColor)
{
	if(parseInt(bgColor)==0) bgColor="#000000";
	if(bgColor.indexOf("#") < 0) bgColor = "#"+bgColor;
	var bodyObj = document.getElementsByTagName("body")[0];
	bodyObj.style.background=bgColor;
}

function initflash()
{
	/** DOMMouseScroll is for mozilla. */
	if (window.addEventListener)
			window.addEventListener('DOMMouseScroll', wheel, false);
	/** IE/Opera. */
	window.onmousewheel = document.onmousewheel = wheel;
	document.onkeydown=keyDown;
}


