/*****************************************************************************
This Script was written by me for steve.
*****************************************************************************/

/**
 * Constants
 * ==========================================================================
 * Placeholder for the handle to pop up windows.
 */
var F1 = null;

/**
 * The constants are used to set the colour for the selected menu items.
 * If a menu item is active, it should display white and not orange. The
 * constant reflects the items position in the array list for each item
 * on a per language basis. The active item is calculated from the Constant
 * less the '_CODE' index which will give the index in the array for each
 * menu / submenu. The _CODE indexes are:
 * 0 - 9: main menu items
 * 100 - 199: press submenu
 * 200 - 299: music menu items
 * 300 - 399: video / photo gallery menu items.
 * 400 - 499: photo gallery tabs.
 */
var MAIN_MENU_CODE = 0;
var MUSIC_SUB_CODE = 10;
var PRESS_SUB_CODE = 100;
var GALLERY_SUB_CODE = 300;
var PHOTOS_CODE = 400;

/**
 * Menu Items
 */
var HOME_MENU = 0;
var PRESS_MENU = 1;
var MUSIC_MENU = 2;
var VIDEO_PHOTO_MENU = 3;
var CONCERT_MENU = 4;
var TEACHING_MENU = 5;
var CONTACT_MENU = 6;

/**
 * Gallery Submenu
 */
var VIDEO_SUB_MENU = 300;
var PHOTO_SUB_MENU = 301;

/**
 * Photos tabs
 */
var PHOTOS_PAGE1 = 400;
var PHOTOS_PAGE2 = 401;
var PHOTOS_PAGE3 = 402;
/** 
 * Menu Items
 * ==========================================================================
 * create and open a new pop up window.
 */
function aufmachen(htmlFile, theHeight, theWidth){
	if (F1 != null){
		schliessen();
	}
	F1 = window.open(htmlFile, "_popup", "height="+theHeight+",width="+theWidth+",scrollbars=yes");
	F1.window.onload = function(){ getRefToElement("toBeHidden", null, F1.document).innerHTML = ""; }
}

/**
 * Close a pop up window.
 */
function schliessen(){
	if (F1 != null && F1.closed != true){
		F1.close();
	}
	F1 = null;
}



/**
 * Main Menu
 * =========
 */
function loadTheMenu(inx){
	var theMenuArray = getMenuItems();
	var theMenuString = "<div id='menu'>";
	for (var i = 0; i < theMenuArray.length; i++){
		var isGallery = theMenuArray[i].search(/gallery/);
		if (i == inx && (isGallery != -1)){
			theMenuString += "<div class='menuitem'>VIDEO/PHOTO<br /> "+theMenuArray[i].toUpperCase()+"</div>";
		}else if(i == inx){
			theMenuString += "<div class='menuitem'><br />"+theMenuArray[i].toUpperCase()+"</div>";
		}else if(isGallery != -1){
			theMenuString += "<div class='menuitem'><a href='../"+theMenuArray[i]+"/index.html'>VIDEO/PHOTO<br> "+theMenuArray[i].toUpperCase()+"</a></div>";
		}else{
			theMenuString += "<div class='menuitem'><br /><a href='../"+theMenuArray[i]+"/index.html'>"+theMenuArray[i].toUpperCase()+"</a></div>";
		}
	}
	theMenuString += "</div>";
	getRefToElement("header").innerHTML = theMenuString;
}


/**
 * Submenu items
 * =============
 */
function loadTheSubmenu(inx, code){
	var theSubmenuArray;
	if (code == GALLERY_SUB_CODE){
		theSubmenuArray = getPhotoVideoSubmenuItems();
		getRefToElement("gallerymenu").innerHTML = createSubmenuItems(theSubmenuArray, inx, code);
		return;
	}
}
 
function createSubmenuItems(submenuArray, inx, code){
	var theMenuString = "<div id='submenu'>";
    for (var i = 0; i < submenuArray.length; i++){
            theMenuString += "<div class='submenuitem'>";
            if(i == (inx - code)){
                    theMenuString += "> "+submenuArray[i]+"</div>";
            }else if (i == 0){
                            theMenuString += "<a href='index.html'>"+submenuArray[i]+"</div>";
            }else if (code == GALLERY_SUB_CODE){
            		if (i == (PHOTO_SUB_MENU - code)){
                            theMenuString += "<a href='photos.html'>"+submenuArray[i]+"</div>";
                    }
            }else if (code == MUSIC_SUB_CODE){
            }
    }
    theMenuString += "</div>";
    return theMenuString;
}

function loadTheTabs(inx){
	var submenuArray = getPhotoTabs()
				
	var theMenuString = "<ul>";
    for (var i = 0; i < submenuArray.length; i++){
            theMenuString += "<li><div class='topline'></div><div class='midupper'></div><div class='midlower'></div><div class='bottomline'></div>";
            if(i == (inx - PHOTOS_CODE)){
                theMenuString += "<a href='' class='selected'>"+submenuArray[i]+"</a></li>";
            }else if (i == (PHOTOS_PAGE1 - PHOTOS_CODE)){
                theMenuString += "<a href='new_photo.html'>"+submenuArray[i]+"</a></li>";
            }else if (i == (PHOTOS_PAGE2 - PHOTOS_CODE)){
            	theMenuString += "<a href='mia.html'>"+submenuArray[i]+"</a></li>";
            }else if (i == (PHOTOS_PAGE3 - PHOTOS_CODE)){
            	theMenuString += "<a href='bremen.html'>"+submenuArray[i]+"</a></li>";
            }
    }
    theMenuString += "</ul>";
	getRefToElement("tabs").innerHTML = theMenuString;
}

function getPhotoTabs(){
	var theArray = new Array();
	theArray[theArray.length] = "CD's";
	theArray[theArray.length] = "Mia";
	theArray[theArray.length] = "Bremen 2004";
	return theArray;
}
/**
 * Email addresses.
 * ================
 * Function so that mail addresses do not have to be written into 
 * a page in clear text. This prevents mail harvesters getting 
 * the addresses from this site.
 */
function sendMailTo(who){
	var returns = "mailto:";
	var Title = "";
	var Domain = "";
	var Country = "com";
	if (who == "steve"){
		Title = "steveklinktrio";
		Domain = "gmail";
	}
	if (who == "bostjan"){
		Title = "bostjan.malus";
		Domain = "gmail";
	}
	if (who == "chris"){
		Title = "chris.h.meyer";
		Domain = "gmx";
		Country = "net";
	}
	if (who == "mia"){
		Title = "mia";
		Domain = "miaznidaric";
		Country = "eu";
	}
	returns += Title;
	returns += "@";
	returns += Domain;
	returns += ".";
	returns += Country;
	window.location.href = returns;
}

/**
 * Video calls
 * ===========
 *
 * Call to start a Flash video in the videoscreen <div> of the video gallery.
 */
function setFlash(theUrl){
	var ref = getRefToElement('videoscreen');
	var theWidth = ref.offsetWidth;
	var so = new SWFObject(theUrl, "TheThang", theWidth, theWidth, "9", "#000000");
	so.addParam("wmode", "opaque");
	so.addParam("width", theWidth);
	so.addVariable("id", getQueryParamValue("mayen"));
	so.write("videoscreen");
}

/**
 * Call to start a Quicktime video in the videoscreen <div> of the video gallery.
 */
function setQuicktime(theUrl){
	var ref = getRefToElement('videoscreen');
	var theWidth = ref.offsetWidth;
	getRefToElement("videoscreen").innerHTML = QT_GenerateOBJECTText( theUrl, theWidth, theWidth, "", "emb#bgcolor", "black", "hspace", "0", "vspace", "0");
}

function showPicture(theUrl, theLoadUrl, theTitle){
	getRefToElement("videoscreen").innerHTML = "<img class='displayimg' src='"+theUrl+"'><p><a href='"+theLoadUrl+"' target='newScreen'>"+theTitle+"</a></p>";
}
/* ================================ Utilities =================================== */

/**
 * getRefToElement()
 * =================
 */
function getRefToElement(elementID, oDoc, theDocument) {
	if (theDocument == null || theDocument == ""){
		theDocument = document;
	}
	
	if (typeof(elementID)=='string'){
		if( theDocument.getElementById ) {
			// DOM supported
			return theDocument.getElementById(elementID); 
		}
	
		if( theDocument.all ) {
			// proprietary DOM supported
			return theDocument.all[elementID]; 
		}
	
		if( !oDoc ) { 
			oDoc = theDocument; 
		}
	
		if( theDocument.layers ) {
			// layers support.
			if( oDoc.layers[elementID] ) { 
				return oDoc.layers[elementID]; 
			} else {
				//repeatedly run through all child layers
				for( x = 0, y; !y && x < oDoc.layers.length; x++ ) {
					//on success, return that layer, else return nothing
					y = getRefToElement(elementID,oDoc.layers[x].theDocument); 
				}
				return y; 
			} 
		}
	}
	return elementID;
}

