// *** general functions

baseHref=location.href.substr(0,Math.max(
	location.href.substr(7,location.href.length-7).indexOf('/')+7+'/'.length,
	location.href.substr(7,location.href.length-7).indexOf('venda/')+7+'venda/'.length
	))

// *** submenus

function dispMenu(ds) {
	var txt='<table class=menu cellpadding=2 cellspacing=1 border=1>'
	while (ds.length) {
		var i=ds.indexOf(';')
		var itm=ds.substring(0,i)
		var ds=ds.substring(i+1,ds.length)
		i=ds.indexOf(';')
		var link=ds.substring(0,i)
		ds=ds.substring(i+1,ds.length)
		if (link.indexOf('$')!='-1') link="javascript:goTo('"+link+"')"
		txt+='<tr><td><a href="'+link+'">'+itm+'</a></td></tr>'
	}
	txt+='<tr><td align=center><a href="javascript:hideMenu()">.- x -.</a></td></tr></table>'
	var men=document.getElementById('menu')
	men.innerHTML=txt
	men.style.left=mouseX+10
	men.style.top=mouseY-40
	men.style.visibility='visible'
}

document.onmousemove=locateMouse
mouseX=0
mouseY=0
function locateMouse(e) {
	if (navigator.userAgent.indexOf('konq')!=-1) {
		var xo=0;
		var yo=0;
	}	else if (e || navigator.userAgent.indexOf('Mozilla')) {
		var xo=window.pageXOffset
		var yo=window.pageYOffset
	}	else {
		e=event
		var xo=document.body.scrollLeft
		var yo=document.body.scrollTop
	}
	mouseX=e.clientX+xo
	mouseY=e.clientY+yo
}

function hideMenu() {
	var men=document.getElementById('menu')
	men.style.visibility='hidden'
}

// *** tvsets

// SETTINGS

defaultDelay=3   // if not specified in addTvSet() or addStill()
stopOnMouseOver=1 // 1 = stops if the mouse is over the image

// object contruction

tvList=[] // global variable used to access different tv sets

/**
* Constructor: a TvSet is a place and a list of images to display
*/
function TvSet(name,index,delay) {
	this.name=name
	this.index=index
	this.delay=delay*10
	this.timer=-tvList.length*5
	this.runFlag=1
	this.stills=[]
	this.currentStill=0
	return this
}

/**
* Constructor: a Still an image and zoom properties
*/
function Still(url,zoomUrl,zoomWidth,zoomHeight,delay) {
	var newImage=new Image(1,1)
	newImage.src=url
	this.image=newImage
	this.delay=delay
	this.zoomUrl=zoomUrl
	this.zoomWidth=zoomWidth
	this.zoomHeight=zoomHeight
	return this
}

/**
* Adds a new TvSet to the global list of TvSets and sets the pointer 'base' to this TvSet.
* @param name - the name of the image on the web page
* @param delay - the delay between images
*/
function addTvSet(name,delay) {
	if (typeof(delay)=='undefined')	var delay=defaultDelay
	newTv=new TvSet(name,tvList.length,delay)
	tvList[tvList.length]=newTv
	base=newTv
}

/**
* Adds a new Still list of Stills of the current TvSet pointed by 'base'.
* @param url - the url of the image to display
* @param zoomUrl - the url of the zoomed image
* @param zoomWidth - the width of the zoomed image
* @param zoomHeight - the height of the zoomed image
* @param delay - the delay until next image is displayed, if not defined, the default is used
*/
function addStill(url,zoomUrl,zoomWidth,zoomHeight,delay) {
	if (typeof(delay)=='undefined')	var delay=base.delay
	base.stills[base.stills.length]=new Still(url,zoomUrl,zoomWidth,zoomHeight,delay)
}

/**
* Checks if any delays are outpassed and eventualy switches to next Stills in all TvSets.
*/
function tic() {
	for(var i=0;i<tvList.length;i++) {
		var tvSet=tvList[i]
		tvSet.timer+=tvSet.runFlag
		if (tvSet.timer>=tvSet.stills[tvSet.currentStill].delay) {
			tvSet.timer=0
			tvSet.currentStill++;
			if (tvSet.currentStill==tvSet.stills.length)
			tvSet.currentStill=0
			document[tvSet.name].src=tvSet.stills[tvSet.currentStill].image.src
		}
	}
}
document.onload=setInterval('tic()','100')

/**
* Zooms to the actual Still.
*/
function zoomStill(tvSetName) {
	var tvSet=tvSetName2tvSet(tvSetName)
	var still=tvSet.stills[tvSet.currentStill]
	zoom(still.zoomUrl,still.zoomWidth,still.zoomHeight)
}

/**
* Pauses the tvSet.
*/
function pauseTv(tvSetName) {
	var tvSet=tvSetName2tvSet(tvSetName)
	tvSet.runFlag=1-stopOnMouseOver
}

/**
* Upauses the tvSet.
*/
function unpauseTv(tvSetName) {
	var tvSet=tvSetName2tvSet(tvSetName)
	tvSet.runFlag=1
}

/**
* Returns the tvSet with taht name.
*/
function tvSetName2tvSet(tvSetName) {
	var i=0
	while (i<tvList.length) {
		if (tvList[i].name==tvSetName) {
			var tvSet=tvList[i]
			i=tvList.length
		}
		i++
	}
	return tvSet
}

/**
* Opens a new window with the specifed image.
*/
function zoom(url,width,height) {
	height+=18
	width+=18
	var options='height=' + height + ',width=' + width
	closeMe()
	zoomWindow=open('','zoomWindow',options)
	zoomWindow.document.write('<html><title>Zoom</title><style type="text/css">body {	background-color: #000000; margin: 9px; }</style></head><body><a href="javascript:generator.closeMe()" onmouseout="generator.closeMe()"><img src="' + url + '" border=0></a></body></html>')
	zoomWindow.generator=self
	zoomWindow.document.close()
}

/**
* Closes any zoom window opened.
*/
function closeMe() {
	if (typeof zoomWindow!='undefined') if (typeof zoomWindow.document!='undefined')
	zoomWindow.close()
}

// *** comments

function comment(sx,sy,dur,txt,chrset) {
	var dur=dur*1000
	var options='height='+sy+',width='+sx+',scrollbars=no,resizable'
	closeMe()
	zoomWindow=open('','zoomWindow',options)
	zoomWindow.document.clear()
	zoomWindow.document.write("<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"><TITLE>Comment</TITLE></HEAD><BODY BGCOLOR=A5D6A3 ONLOAD=\"setTimeout('generator.closeMe();','"+dur+"')\">"+txt+"<P><CENTER><FORM><FONT SIZE=0><INPUT TYPE=button VALUE=\" Ok \" ONCLICK=\"generator.closeMe()\"></FONT></FORM></BODY></HTML>");
	zoomWindow.generator=self
	zoomWindow.document.close()
}

// *** functions for activating buttons

function reduceButtonSrc(button) {
	var imSrc=document[button].src
	this.pre=imSrc.substring(0,imSrc.length-4)
	if (this.pre.substring(this.pre.length-2,this.pre.length-1)=='_')
	this.pre=this.pre.substring(0,this.pre.length-2)
	this.ext=imSrc.substring(imSrc.length-4,imSrc.length)
	return this
}

function oB(button) {
	var imSrc=new reduceButtonSrc(button)
	document[button].src=imSrc.pre+'_o'+imSrc.ext
}

function fB(button) {
	var imSrc=new reduceButtonSrc(button)
	document[button].src=imSrc.pre+imSrc.ext
}

// *** managing languages

// see content of language_changer.htm
// syntax of general cookie: en$fr$lan3$lan4$

function goTo(link) {
	var i=link.lastIndexOf('_')
	var linkPre=link.substring('0',i+1)
	var avalaibleLan=link.substring(i+1,link.length)
	location.href=linkPre+bestLanguage(avalaibleLan)+'.htm'
}

function setBestLanguage(lan) {
	open(baseHref+'language_changer.htm#'+lan,'lan','height=100,width=10')
}

function bestLanguage(avalaible) {
	var result=avalaible.substring(0,avalaible.indexOf('$'))
	var prefOrder=document.cookie
	if (prefOrder.indexOf(';')!='-1')
	prefOrder=prefOrder.substring(prefOrder.lastIndexOf(';')+2,prefOrder.length)
	while (prefOrder!='') {
		var sepIndex=prefOrder.indexOf('$')
		if (sepIndex!='-1') {
			var lan=prefOrder.substring(-1,sepIndex)
			prefOrder=prefOrder.substring(sepIndex+1,prefOrder.length)
		}
	else {
		var lan='noCookieSet'
		prefOrder=''
	}
	if (avalaible.indexOf(lan)!='-1') {
		result=lan
		prefOrder=''
	}
}
return result
}