/* See http://www.quirksmode.org/js/dom.html */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
DHTML = (document.getElementById || document.all || document.layers);
//
DOM_W3C_Level1 = (document.getElementById && document.createElement)? true:false;
DOM_Microsoft = (document.all)? true:false;
DOM_Netscape = (document.layers)? true:false;

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* var x = new getObj('objectID');  */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function getObj(objectID) {
    if(DHTML) {
        if (DOM_W3C_Level1) {
            this.obj = document.getElementById(objectID);
            if(this.obj) {
                this.style = document.getElementById(objectID).style;
            }
        } else if (DOM_Microsoft) {
            this.obj = document.all[objectID];
            if(this.obj) {
                this.style = document.all[objectID].style;
            }
        } else if (DOM_Netscape) {
            this.obj = document.layers[objectID];
            this.style = document.layers[objectID];
        } else {
            //No Supported DOM found
        }
        
        if(this.obj && this.style) {
            var xpos = findPosX(this.obj);
            var ypos = findPosY(this.obj);
            
            this.style.left = xpos + 'px';
            this.style.top = ypos + 'px';
            
            this.style.xpos = xpos;
            this.style.ypos = ypos;        
        } else {
            // DHTML object not found
        }
    } else {
        //DHTML not supported
    }
}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* See http://www.quirksmode.org/js/findpos.html */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
    }
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
//            alert("obj.offsetParent = " + obj.offsetParent + ", obj.offsetTop = " + obj.offsetTop);
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
    }
	return curtop;
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* See http://www.dansteinman.com/dynduo/en/moving.html */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function moveTo(obj, x, y) {
    if(DHTML && (obj != null)) {
        obj.style.xpos = x;
        obj.style.ypos = y;
        
        obj.style.left = obj.style.xpos + 'px';
        obj.style.top = obj.style.ypos  + 'px';
    }
}

function moveBy(obj, x, y) {
    if(DHTML && (obj != null)) {
        newX = obj.style.xpos + x;
        newY = obj.style.ypos + y;
        moveTo(obj, newX, newY);
    }
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* Show/Hide functions for pointer layer/objects */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function show(obj) {
    if(DHTML && (obj != null)) {
        if(DOM_W3C_Level1) obj.style.visibility = 'visible';
        else if (DOM_Microsoft) obj.style.visibility = 'visible';
        else if (DOM_Netscape) obj.stylevisibility = 'show';
    }
}

function hide(obj) {
    if(DHTML && (obj != null)) {
        if(DOM_W3C_Level1) obj.style.visibility = 'hidden';
        else if (DOM_Microsoft) obj.style.visibility = 'hidden';
        else if (DOM_Netscape) obj.style.visibility = 'hide';
    }
}

function isVisible(obj) {
    if(DHTML && (obj != null)) {
        if(DOM_W3C_Level1) return (obj.style.visibility == 'visible');
        else if (DOM_Microsoft) return (obj.style.visibility == 'visible');
        else if (DOM_Netscape) return (obj.style.visibility == 'show');
    } else {
        //alert("obj is null");
    }
    return true;
}

function toggleVisibility(obj) {
    if(isVisible(obj)) {
        //alert("hide");
        hide(obj);
    } else {
        //alert("show");
        show(obj);
    }
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* Wraps potentially non-supported   */
/* JavaScript functions. */
/* See: http://www.quirksmode.org/js/support.html */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

function setWindowFocus(focusWindow) {
    if(focusWindow.focus) { // is focus supported?
        focusWindow.focus(); 
    }
}

var menu;
var menubutton;

function toggleMenu(obj, objcontrol) {
    if(isVisible(obj)) {
		objcontrol.obj.innerHTML = '+';
        hide(obj);
        obj.style.display = "inline";		
    } else {
		objcontrol.obj.innerHTML = '--';
        show(obj);
        obj.style.display = "block";
    }
}


function toggleVideo(video) {
    /*
    hide(video1); video1.style.display = "inline";
    hide(video2); video2.style.display = "inline";
    hide(video3); video3.style.display = "inline";
    hide(video4); video4.style.display = "inline";
    */

    //    show(obj);
    //    obj.style.display = "block";

    videoScreen.obj.innerHTML = video.obj.innerHTML;
}


function playVideo(videoName) {
    var video = new getObj(videoName);
    videoScreen.obj.innerHTML = video.obj.innerHTML;
}

function hideVideo(videoName) {
   var video = new getObj(videoName);
   hide(video); video.style.display = "inline";
}

function showLyrics(lyricsName) {
    var lyrics = new getObj(lyricsName);
    lyricSheet.obj.innerHTML = lyrics.obj.innerHTML;
}

function hideLyrics(lyricsName) {
    hideVideo(lyricsName);
}


function init2() {	
    videoScreen = new getObj('videoScreen');
    lyricSheet = new getObj('lyricSheet');

    hideVideo('video2');
    hideVideo('video5');
    hideVideo('video8');

    hideLyrics('lyrics2');
    hideLyrics('lyrics3');
    hideLyrics('lyrics5');
    hideLyrics('lyrics7');
    hideLyrics('lyrics8');
    hideLyrics('lyrics11');
    hideLyrics('lyrics12');
}

function init() {	
    videoScreen = new getObj('videoScreen');
    video1 = new getObj('video1');
    video2 = new getObj('video2');
    video3 = new getObj('video3');
    video4 = new getObj('video4');

    hide(video1); video1.style.display = "inline";
    hide(video2); video2.style.display = "inline";
    hide(video3); video3.style.display = "inline";
    hide(video4); video4.style.display = "inline";

	var newX = videoScreen.style.xpos;
	var newY = videoScreen.style.ypos;
	moveTo(video1, newX, newY);
	moveTo(video2, newX, newY);
	moveTo(video3, newX, newY);
	moveTo(video4, newX, newY);
        
}



