
if (parent.lang!=0 && parent.lang!=1) top.location="/index.asp"

IE = false
NN5 = false
if (document.all) IE=true
if ((navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5) || navigator.userAgent.indexOf('Opera')>-1) NN5=true

if (parent.lang == 1) lang=1
else lang=0

demowait=parent.demowait
demoTimeOutId = 0
showMsgTimeOutId = 0
cssNum = 0

photos = new Array()
pageTitle = new Array()
pageOptions = new Array()
pageOptions[0] = new Array()
pageOptions[1] = new Array()
commentFoto = new Array()
commentSection = new Array()
clickBack = new Array()
markPhoto = new Array()

commentFoto[0] = "Comentar foto"
commentFoto[1] = "Comment photo"

commentSection[0] = "Comentar secção"
commentSection[1] = "Comment section"

clickBack[0] = "Clique para voltar"
clickBack[1] = "Click here to return"

markPhoto[0] = "Enviar Postal"
markPhoto[1] = "Send eCard"

messages = new Array()
messages[0] = new Array()
messages[1] = new Array()

msgtitles = new Array()
msgtitles[0] = new Array()
msgtitles[1] = new Array()

outmessage = 25
activethumb = -1

function showmsg(numMsg,demoflag) {
	clearTimeout(showMsgTimeOutId)
	bigthumb(numMsg)
	writemessage(numMsg)
	clearTimeout(demoTimeOutId)
	if (demoflag==0) demoTimeOutId = setTimeout("demo()",demowait)
	}

function writemessage(numMsg) {
	if (numMsg != outmessage) cssNum-=4
	else cssNum+=2
	if (cssNum < 15) showMsgTimeOutId = setTimeout("writemessage(" + numMsg + ")",20)
	if (cssNum>15) cssNum = 15
	if (cssNum <= 0) {
		cssNum = 0
		outmessage = numMsg
		}
	msgopen = "<table width='125' height='310'><tr><td align='center'><span class='c" + cssNum + "'><span class='tstyle'>" 
	msgmid = "</span></span></td></tr><tr><td align='center'><span class='c" + cssNum + "'><span class='mstyle'><br>" 
	msgref = "</span></span></td></tr><tr><td>&nbsp;</td></tr><tr><td align='right'><span class='c" + cssNum + "'><span class='rstyle'>" 
	msgclose = "</span></span></td></tr></table>"
	if (IE)
	   document.all["Dmessage"].innerHTML = msgopen + msgtitles[lang][outmessage] + msgmid + messages[lang][outmessage] + msgref + photos[outmessage][0] + msgclose
	else if (NN5)
	   document.getElementById("Dmessage").innerHTML = msgopen + msgtitles[lang][outmessage] + msgmid + messages[lang][outmessage] + msgref + photos[outmessage][0] + msgclose
	else {
	   document.layers["Dmessage"].document.open()
	   document.layers["Dmessage"].document.write(msgopen + msgtitles[lang][outmessage] + msgmid + messages[lang][outmessage] + msgref + photos[outmessage][0] + msgclose)
	   document.layers["Dmessage"].document.close()
	   }
	}

function bigthumb(num) {
	if (activethumb==num) return
	else {
		if (activethumb>=0) smallthumb(activethumb)
		activethumb = num
		}
	if (photos[num][1]>photos[num][2]) {width=150;height=100}
	else {width=100;height=150}
	strHTML = '<table '
	if (photos[num][4]==1) strHTML = strHTML + 'bordercolor="#00DD00"'
	else strHTML = strHTML + 'bordercolor="#c0c0c0"'
	strHTML = strHTML + ' bgcolor="#000000" border="1" width="170" height="170" cellspacing="0"><tr><td align="center">' +
			'<img src="/'+photos[num][3]+'/t'+photos[num][0]+'.jpg" width="'+width+'" height="'+height+'">' +
			'</td></tr></table>'
	thumby = parseInt(1 + num/4)-1
	thumbx = num % 4
	thumbtop = 43 + 157*thumby			// 43 = 49 - 6
	thumbleft = 143 + 157*thumbx		// 143 = 149 - 6
//	if (thumby==0) thumbtop +=5
//	if (thumby==2) thumbtop -=3
	if (thumbx==3) thumbleft -=3
	writethumb("thumb" + thumby + thumbx,strHTML,170,thumbtop,thumbleft,2)
	}

function smallthumb(num) {
	if (photos[num][1]>photos[num][2]) {width=135;height=90}
	else {width=90;height=135}
	strHTML = '<table '
	if (photos[num][4]==1) strHTML = strHTML + 'bordercolor="#00DD00"'
	else strHTML = strHTML + 'bordercolor="#c0c0c0"'
	strHTML = strHTML + ' border="1" width="156" height="156" cellspacing="0"><tr><td align="center">' +
			'<img src="/'+photos[num][3]+'/t'+photos[num][0]+'.jpg" width="'+width+'" height="'+height+'">' +
			'</td></tr></table>'
	thumby = parseInt(1 + num/4)-1
	thumbx = num % 4
	writethumb("thumb" + thumby + thumbx,strHTML,156,49 + 157*thumby,149 + 157*thumbx,1)
	}

function writethumb(thumbname,strHTML,clipsize,thumbtop,thumbleft,thumbzindex) {
	strclip = "rect(0px,"+clipsize+"px,"+clipsize+"px,0px)"
	if (IE) {
	   document.all[thumbname].innerHTML = strHTML
	   document.all[thumbname].style.clip = strclip
	   obj = document.all[thumbname].style
	   }
	else if (NN5) {
	   document.getElementById(thumbname).innerHTML = strHTML
	   document.getElementById(thumbname).style.clip = strclip
	   obj = document.getElementById(thumbname).style
	   }
	else {
	   document.layers[thumbname].document.open()
	   document.layers[thumbname].document.write(strHTML)
	   document.layers[thumbname].document.close()
	   document.layers[thumbname].clip.left = 0
	   document.layers[thumbname].clip.right = clipsize
	   document.layers[thumbname].clip.top = 0
	   document.layers[thumbname].clip.bottom = clipsize
	   obj = document.layers[thumbname]
	   }
	obj.zIndex = thumbzindex
	obj.top = thumbtop
	obj.left = thumbleft
	}
	
function showpic(num) {
	strHTML = '<table border="0" cellpadding="0" cellspacing="0" width="640" height="520"><tr><td align="center">' +
			'<table border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff" width="'+(photos[num][1]+20)+'" height="'+(photos[num][2]+18)+'"><tr><td align="center">' +
			'<table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="'+(photos[num][1]+4)+'" height="'+(photos[num][2]+4)+'"><tr><td align="center">' +
			'<a href="Javascript:hidepic()">' +
			'<img src="/' + photos[num][3] + '/' + photos[num][0] + '.jpg" border="1" width="'+photos[num][1]+'" height="'+photos[num][2]+'" alt="'+clickBack[lang]+'">' +
			'</a></td></tr></table></td></tr></table></td></tr></table>'
	strComment = '<a href="JavaScript:comment(\''+commentFoto[lang]+': '+msgtitles[lang][num]+" ("+photos[num][0]+')\')" class="rstyle">'+commentFoto[lang]+'</a>'
	if (IE)	{
		document.all["Dphoto"].innerHTML = strHTML
		document.all["Dcomment"].innerHTML = strComment
		document.all["Dphoto"].style.visibility = "visible"
		document.all["Dusephoto"].style.visibility = "visible"
		document.all["Dprevnext"].style.visibility = "visible"
		}
	else if (NN5) {
		document.getElementById("Dphoto").innerHTML = strHTML
		document.getElementById("Dcomment").innerHTML = strComment
		document.getElementById("Dphoto").style.visibility = "visible"
		document.getElementById("Dusephoto").style.visibility = "visible"
		document.getElementById("Dprevnext").style.visibility = "visible"
		}
	else {
		document.layers["Dphoto"].document.open()
		document.layers["Dphoto"].document.write(strHTML)
		document.layers["Dphoto"].document.close()
		document.layers["Dcomment"].document.open()
		document.layers["Dcomment"].document.write(strComment)
		document.layers["Dcomment"].document.close()
		document.layers["Dphoto"].visibility = "visible"
		document.layers["Dusephoto"].visibility = "visible"
		document.layers["Dprevnext"].visibility = "visible"
		}
	smallthumb(num)
	}

function hidepic() {
	strComment = '<a href="JavaScript:comment(\''+commentSection[lang]+': '+pageTitle[lang]+'\')" class="rstyle">'+commentSection[lang]+'</a>'
	if (IE)	{
		document.all["Dphoto"].style.visibility = "hidden"
		document.all["Dusephoto"].style.visibility = "hidden"
		document.all["Dcomment"].innerHTML = strComment
		document.all["Dprevnext"].style.visibility = "hidden"
		}
	else if (NN5) {
		document.getElementById("Dphoto").style.visibility = "hidden"
		document.getElementById("Dusephoto").style.visibility = "hidden"
		document.getElementById("Dcomment").innerHTML = strComment
		document.getElementById("Dprevnext").style.visibility = "hidden"
		}
	else {
		document.layers["Dphoto"].visibility = "hidden"
		document.layers["Dusephoto"].visibility = "hidden"
		document.layers["Dcomment"].document.open()
		document.layers["Dcomment"].document.write(strComment)
		document.layers["Dcomment"].document.close()
		document.layers["Dprevnext"].visibility = "hidden"
		}
	}

function goPrevious() {
	for (x=activethumb-1;x>=0;x--)
		if (photos[x][0]!="") {changepic(x);return}
	}
	
function goNext() {
	for (x=activethumb+1;x<=11;x++)
		if (photos[x][0]!="") {changepic(x);return}
	}

function changepic(num) {
	activethumb = x
	showmsg(x,0)
	showpic(x)
	}

function initLayers() {
	for (x=0;x<3;x++)
	  for (y=0;y<4;y++)
	    if (photos[x*4+y][0]!="")
	      if (IE) {
			document.all["thumb"+x+y].onmousedown = eval("new Function('showpic("+(x*4+y)+")')")
			document.all["thumb"+x+y].onmouseover = eval("new Function('showmsg("+(x*4+y)+",0)')")
			}
		  else if (NN5) {
			document.getElementById("thumb"+x+y).onmousedown = eval("new Function('showpic("+(x*4+y)+")')")
			document.getElementById("thumb"+x+y).onmouseover = eval("new Function('showmsg("+(x*4+y)+",0)')")
			}
	      else {
			document.layers["thumb"+x+y].onmousedown = eval("new Function('showpic("+(x*4+y)+")')")
			document.layers["thumb"+x+y].captureEvents(Event.MOUSEDOWN|Event.MOUSEOVER)
			document.layers["thumb"+x+y].onmouseover = eval("new Function('showmsg("+(x*4+y)+",0)')")
			}
	    
	if (IE) document.all["Dphoto"].onmousedown = hidepic
	else if (NN5) document.getElementById("Dphoto").onmousedown = hidepic
	else {
		document.layers["Dphoto"].captureEvents(Event.MOUSEDOWN)
		document.layers["Dphoto"].onmousedown = hidepic
		}	
	}

function go(strURL) {
	if (lang == 0) location = "../" + strURL
	else location = "../" + "en_" + strURL
	}

function comment(strSubject) {
	open("../contacto.html?"+escape(strSubject),"contacto","width=400,height=500,scrollbars=no,toolbar=no,menubar=no,statusbar=no")
	}

function writeThumbs() {
	var str = ""
	for (x=0;x<3;x++)
		for (y=0;y<4;y++) {
		  if (photos[x*4+y][0] != "") {
			if (photos[x*4+y][1]>photos[x*4+y][2]) {width=135;height=90}
			else {width=90;height=135}
			str = str + '<div id="thumb' + x + y + '">\n' +
			'<table '
			if (photos[x*4+y][4]==1) str = str + 'bordercolor="#00DD00"'
			else str = str + 'bordercolor="#c0c0c0"'
			str = str + ' border width="156" height="156" cellspacing="0"><tr><td align="center">' +
			'<img src="/'+photos[x*4+y][3]+'/t'+photos[x*4+y][0]+'.jpg" width="'+width+'" height="'+height+'">' +
			'</td></tr></table>\n'+'</div>\n'
			}
		}
	document.write (str)
	}


demopos = 0
	
function usephoto() {
	window.open("/marketing/marcarphoto.asp?p=" + photos[activethumb][3] + "/" + photos[activethumb][0] + "&w=" +  photos[activethumb][1] + "&h=" +  photos[activethumb][2],"usephoto","width=250,height=200,scrollbars=no,toolbar=no,menubar=no,statusbar=no")
	}

function demo() {
//	demopos > 9 ? demopos=0 : demopos++
//	demoTimeOutId = setTimeout('demo()',12000)
	}

