//********
var pageVer="2002.10.24.01"

//Browser identify set
function Is () {   
	var agt=navigator.userAgent.toLowerCase();
	this.ver = parseInt(navigator.appVersion);
	this.sub = parseFloat(navigator.appVersion);

	this.opera = (agt.indexOf("opera") != -1);

	this.nav  = ((agt.indexOf('mozilla') !=-1) && ((agt.indexOf('spoofer') ==-1) && (agt.indexOf('compatible') == -1)) && (!this.opera));
	this.nav2 = (this.nav && (this.ver == 2));
	this.nav3 = (this.nav && (this.ver == 3));
	this.nav4 = (this.nav && (this.ver == 4));
	this.nav4up = (this.nav && (this.ver >= 4) && (!document.getElementById));
	this.nav6up = (this.nav && (document.getElementById));

	this.ie   = ((agt.indexOf("msie") != -1) && (!this.opera));
	this.ie3  = (this.ie && (this.ver == 3));
	this.ie4  = (this.ie && (this.ver == 4));
	this.ie4up  = (this.ie  && (this.ver >= 4));

	this.mac=(agt.indexOf("mac") !=-1);
}
//Create browser identify object
var is = new Is();

//*******
//Bug fix Nav4 on resize
function ReLoadPage(init) {
	if (is.nav4up) {
		if (init==true) {
		    document.DW=innerWidth; 
		    document.DH=innerHeight; 
		    onresize=ReLoadPage;
		}
		else {
			if ((innerWidth!=document.DW) || (innerHeight!=document.DH)) { 
				location.reload();
			}
		}
	}	
}
ReLoadPage(true);


//********
//Set window place and size
function SetScreen(){
	
	if (is.nav4up) {
		window.moveTo(0,0);
		if (screen.width>=800) window.resizeTo(790,600-(window.outerHeight-window.innerHeight));
	}		
	else if (is.nav6up) {
		window.moveTo(0,0);
		if (screen.width>=800) window.resizeTo(800,600);
	}
	else if (is.ie4up) {
		window.moveTo(0,0);
		if (screen.width>=800) window.resizeTo(800,600);
	}
	else if (is.opera) {
		window.moveTo(0,0);
		if (screen.width>=800) window.resizeTo(800,600);
	}
}


//********
// Follow link after click
function ClickReturn() {
	if ((is.ie3) && (is.mac)) return false; 
	else return true; 
}

//Initialize page 
function InitPage() {
	if (is.nav6up) {
		//Fix the netscape 6 bug: show all div box
		window.resizeTo(window.outerWidth-5,window.outerHeight-5);
		window.resizeTo(window.outerWidth+5,window.outerHeight+5);
	}
	else if (is.nav4up) {
		//Fix the netscape 4 bug: call anchor from external page
		var ac=location.hash
		if (ac.length>0) {
			window.location=ac
		}
	}
}


//*********
//Find and get object in document or layer in navigator
//n: name (id) of object
//l: layer object (optional for netscape)
function getObject(n,l) { 
	if (is.ver < 4) return document[n];
	var cDoc = (l) ? l.document : document; 
	var cObj = cDoc[n];
	if (!cObj) {
		for (var i=0; i<cDoc.layers.length; i++) {
			cObj = getObject(n,cDoc.layers[i]);
			if (cObj) return cObj; 
		}
	}
	return cObj;
}

//Get image object
//iName: name of image
function getImage(iName) { 
	if (document.images) {
		if (is.ie) return document.images[iName]; 
		else if (is.nav6up) return document.images[iName];
		else	if (is.opera) return document.images[iName]; 
		else return getObject(iName,0); 
	}
	return null;
}

//Get style object
//s: ID of style
function getStyle(s) { 
	if (is.ie) return document.all.tags("div")[s].style; 
	else if (is.nav6up) return document.getElementById(s).style;
	else if (is.opera) return document.all.tags("div")[s].style; 
	else return getObject(s,0); 
}


//********
//Create images array
// images array: name,src,status
var iA = new Object(); 

//***
//Load button image component
//iName:	name of image
//iUrl:	URL array of phase
//iStatus:	Status array of phase (if don't defined, default value: '' )
function LoadImage(iName,iUrl,iStatus) {

	if (document.images) {
		iA[iName] = new Object();
		for(var i=0; i<iUrl.length;i++) {	
			var x = i*2;
			iA[iName][x] = new Image(); 
			iA[iName][x].src = (iUrl[i]) ? iUrl[i] : 0;
			iA[iName][x+1] = (iStatus) ? iStatus[i] : ' ';
		}
	}
}


//***
//Show image from image array (iA)
//iName:	name of image
//iPhase:	pahes of image (0,1,2...)
function ShowImage(iName,iPhase) {

	if (iA[iName]) {
		var img = getImage(iName);
		var x = (iPhase*2);
		if (img && typeof(iA[iName][x].src) != "undefined") {
			img.src = iA[iName][x].src;
			SetStatus(iA[iName][x+1]);
		}
	}		
	return true;
}

//***
//Set image (change) URL and status line message
//iName:	name of image
//iURL:	URL of image
//iStatus: status message
function SetImage(iName,iURL,iStatus) {

	var img = getImage(iName);
	if (img) {
		img.src = iURL;
		SetStatus(iStatus);
	}		
	return true;
}		


//***
//Set status message
//iStatus: status message
function SetStatus(iStatus) {
	var w = (iStatus) ? iStatus : ' ';
	if (is.nav6up) {
		window.defaultStatus = w;
	}
	else {
		window.status = w;
	}
	return true;
}		

//*******
//Set cookie
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
 	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


//Get cookie 
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) {
			return "";
		}
	} 
	else begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


//****
//Preload 
if (pageSet[2] == "en") {
	//Preload Englis menu images
	LoadImage('menu',	new Array(	'images/bg/menu0.jpg',
								'images/bg/menu1.gif',
								'images/bg/menu2.gif',
								'images/bg/menu3.gif',
								'images/bg/menu4.gif',
								'images/bg/menu5.gif',
								'images/bg/menu6.gif',
								'images/bg/menu7.gif',
								'images/bg/menu8.gif'),
					new Array(	'',
								'News, informations, events',
								'Albums and Recordings',
								'The History of Force Majeure',
								'Picture and Photo Gallery',
								'Creators and Guests',
								'Interviews, reviews, opinions',
								'The Studio of Force Majeure',
								'Links, connections'));
}
else if (pageSet[2] == "hu") {
	//Preload Hungarian menu images
	LoadImage('menu',	new Array(	'images/bg/_menu0.jpg',
								'images/bg/_menu1.gif',
								'images/bg/_menu2.gif',
								'images/bg/_menu3.gif',
								'images/bg/_menu4.gif',
								'images/bg/_menu5.gif',
								'images/bg/_menu6.gif',
								'images/bg/_menu7.gif',
								'images/bg/_menu8.gif'),
					new Array(	'',
								'Hírek, újdonságok, események',
								'Albumok és felvételek',
								'A Force Majeure története',
								'Képtár és fotógaléria',
								'Alkotók és közreműködők',
								'Interjúk, kritikák, vélemények',
								'A Force Majeure stúdió',
								'Linkek és kapcsolatok'));
}

//PreLoad other images
if (typeof(preImage)=="object") {
	for(var i=0; i<preImage.length; i++) {	
		//Preload predefined images
		LoadImage(preImage[i][0],preImage[i][1],preImage[i][2]);
	}
}


//***********
var IsLocal = (String(document.location.href).substr(0,4)=="file")
//Set Local or web URL for big images
if (typeof(bigDir)=="object") {
	bigDir = ((IsLocal) ? bigDir[0] : bigDir[1]);
}

//***********
//Set Local or web URL for audio files
if (typeof(aA)=="object") {
	aA.Url = ((IsLocal) ? aA.Url[0] : aA.Url[1]);
}

//***********
//Set Local or web URL for video files
if (typeof(vA)=="object") {
	vA.Url = ((IsLocal) ? vA.Url[0] : vA.Url[1]);
}


