﻿// common.js

//var	log = 1;
//var	pathChunks= document.URL.substring( 
//			document.URL.indexOf('://') + 3,  document.URL.lastIndexOf('.') ).split( '/' );

window.onload = load_images;


var Doc = { ver:'0.1',
//	path, pathChunks, dirDepth, host, name, docDir, docDir1

// if UA not IE
//if ( console typeof !== 'undefined' 
//	new_log: console ? console.log ( ' < Doc.new_log' ):0,

	new_log: ( typeof console !== 'undefined' ) ? console.log ( ' < Doc.new_log' ):0,

// document local/host path without the file type extension, assuming no query string etc
	//path: document.URL.slice();
	path: document.URL.substring( 
			document.URL.indexOf('://') + 3,  document.URL.lastIndexOf('.') ),

	pathChunks: document.URL.substring( 
			document.URL.indexOf('://') + 3,  document.URL.lastIndexOf('.') ).split( '/' ),

//	pathChunks: ( document.URL.substring( 
//			document.URL.indexOf('://') + 3,  document.URL.lastIndexOf('.') ) ).split( '/' ),

// •••••
//	host: ( pathChunks[ 0 ] == '' ) ? 'localhost' : pathChunks[ 0 ],
//	name: this.pathChunks[ this.pathChunks.length -1 ],
//	docDir: pathChunks[ pathChunks.length -2 ],
//	docDir1: pathChunks[ pathChunks.length -3 ],
//	dbg: ( pathChunks[ 0 ] == '' ) ? true : false,

	init: function( ) {  
			
			this.host = ( this.pathChunks[ 0 ] == '' ) ? 'localhost' : this.pathChunks[ 0 ];
			this.name = this.pathChunks[ this.pathChunks.length -1 ];
		
			this.docDir = this.pathChunks[ this.pathChunks.length -2 ];
			this.docDir1 = this.pathChunks[ this.pathChunks.length -3 ];
		
			this.dbg = ( this.host == '' ||
						this.host == 'localhost' ||
						this.host == 'b.mekano.net' ) ? true : false;

//			if ( this.dbg && console ) { this.log = 1 };	
			if ( this.dbg && ( typeof console !== 'undefined' ) ) { this.log = 1; }

			this.log ? console.log ( '< Doc.init()'
						+ ' Doc.ver:' + this.ver
						+ ' Doc.dbg: ' + this.dbg
					+ '	Doc.name: '  + this.name
					+ '\r'
				+ ' Doc.pathChunks: '  + this.pathChunks
				+ ' Doc.pathChunks.length: '  + this.pathChunks.length
				+ ' Doc.docDir: '  + this.docDir
				+ ' Doc.host:' + this.host
	 		):0;
// ••••••••••••••••••••••
//if ( host == docDir ) { isRoot = 1 }

			switch ( this.name )	{

				case 'localhost':
					break;
					
				case 'index':
					this.log ? console.log ( ' Doc.init - switch @ Doc.name: '  + this.name ):0;
//					break;

				default:
					this.log ? console.log ( ' Doc.init - default switch @ Doc.name: '  + this.name ):0;
			};
	},
	dbg: false, log: false
}

Doc.init();


// javascript1.1 image rollover functions used by all pages, by 'onLoad' event
var onImgArray = new Array(), offImgArray = new Array();

function load_images() {
	if (document.images) {
	
		var imgName = imgPath = imgType = '', imgHeight = imgWidth = 0;
		
		var numImages = document.images.length;

		for (i=0; i < numImages; i++) {

			imgName = document.images[i].name;
			
			// named img exceptions
			if ( !imgName || imgName.indexOf("arr_") != -1 || imgName.indexOf("sub_") != -1 ) { continue }
				 
			imgPath = document.images[i].src;

			imgHeight = document.images[i].height;
			imgWidth = document.images[i].width;

			offImgArray[imgName] = new Image(imgWidth,imgHeight);
			offImgArray[imgName].src = imgPath;
			
			imgType = imgPath.substring( imgPath.lastIndexOf("."), imgPath.length );
			imgPath = imgPath.substring( 0, imgPath.lastIndexOf(".") );			

			onImgArray[imgName] = new Image(imgWidth, imgHeight);
			onImgArray[imgName].src = imgPath + "_on" + imgType;
			
//	alert (imgPath );
		}
	}
}
function m_over(imgName) {
	if ( document.images && onImgArray[imgName] ) { document[imgName].src = onImgArray[imgName].src }
}
function m_out(imgName) {
	if ( document.images && offImgArray[imgName] ) { document[imgName].src = offImgArray[imgName].src }
}

// •••••••••••••••• 

function window_open( srcURL ) {
	if ( !srcURL ) { return }
	
	var winName = 'sorry';
	var paramString = 'scrollbars=no,width=205,height=200';

	window.open( srcURL, winName, paramString );
}

function window_openN ( pObj ) { if ( ! pObj ) { return false }
	
//	pObj.srcURL
//	pObj.width
//	pObj.height
//	pObj.name
	
// pObj.scrollbars ?  pObj.scrollbars = 'no';
pObj.scrollbars = 'no';

//		var winName = 'sorry';
	var paramString =	'width=' + pObj.width 
						+ ',height=' + pObj.height
						+ ',scrollbars=' + pObj.scrollbars;

	window.open( pObj.srcURL, pObj.winName, paramString );
}

//???•••••••••••••••• events evt_051203.htm
var a_window = null;

	function window_openB( srcURL ) {
	
		if ( !srcURL ) { return }
		
		var winName = 'review';
		var paramString = 'scrollbars=yes,resizable=1,width=436,height=500';
	
		a_window = window.open( srcURL, winName, paramString );
		a_window.focus();
	}
	// called by unload event, closes window when opener/self closes
	function close_window(){
			if ( a_window ) { a_window.close(); }
	}

// close window when opener closes?
var mov_window = null;

function open_mov_window( movie_file ) {

	if ( !movie_file ) { return false }

	var srcURL, winName, paramString;

	winName = 'QT_window';

	srcURL = '_sound.htm?' + movie_file;

	paramString = 'scrollbars=no,resizable=no,width=320,height=120,left=600,top=126';

	if ( mov_window == null || mov_window.closed ) {	
	
		mov_window = window.open( srcURL, winName, paramString );
		
	} else { 
// ??? reopens with different size 
//	 	mov_window.location.href = srcURL; mov_window.focus();

		mov_window.close();
		
		// delay opening?		
		mov_window = window.open( srcURL, winName, paramString );
	} 
}

function close_mov_window(){
		if ( mov_window ) { mov_window.close(); }
}
