dim m_PicIndex
dim m_Timer
dim m_Transition 
dim m_TimerInterval
dim m_maxWidth, m_maxHeight

m_TimerInterval = 5000


function ShowMe()
	'--- מציג את התמונות
	
	StartPics()
	
	
	'--- נותן גובה לפריים
	
	SetFrameHeight()
end function

function StartPics()
	dim Pic
	m_PicIndex = 0
	
	dim tableStr
	tableStr = "<table dir=""ltr"">"
		
	dim func, title
		
	'--- בדיקה שיש תמונות
	if (( document.all("PicList")) is nothing) then exit function
	
	'--- בדיקה שהאוביקט הראשי של תמונה קיים
	'if (( document.all("PIC1")) is nothing) then 
	'	msgbox "PIC1 NOT FOUND!!!! PLEASE GO TO THE LAST ROOM IN THE OFFICE :)"	
	'	exit function
	'end if
	
	'--- מידות מקסימום של תמונה
	
	m_maxWidth = 115
	m_maxHeight = 75
	
	dim i
	i=0
	dim width,height,larging
		
	for i=0 to document.getElementsByName("PicList").length-1
		if document.getElementsByName("PicList").length > 1 then
			'--- יש יותר מתמונה אחת
			set pic = document.all.PicList(i)
			
		else
			'--- יש רק תמונה אחת
			set pic = document.all.PicList
		end if
		
		'--- מקטין את התמונה
				
		width=pic.w
		height=pic.h
		larging = false
		
		if (width<>"" and height<>"") then
				
			'--- יש גדלים לתמונה
			dim h,w,hNew,wNew
			h=cint(height)
			w=cint(width)
			
			hNew=h
			hWidth=w
			
			if h > m_maxHeight then
				w = w * (m_maxHeight / h)
				h=m_maxHeight
				larging = true
			end if
			
			if w > m_maxWidth then
				h = h * (m_maxWidth / w)
				w=m_maxWidth
				larging = true
			end if
		else
			w=115
			h=75
			larging = false
		end if
			
		if i mod 5 = 0 then
			tableStr = tableStr & "<tr>"
		end if
		
		title = replace(replace(pic.tag,"'","\'"),"""","\'\'")
				
		if larging = true then
			func="javascript:growPic('" & pic.original & "','" & replace(title,vbnewline," ") & "')"
		else
			func=""
		end if
		
		tableStr = tableStr & "<td align=""right"" width=""130px"">"
		title = replace(pic.tag,"""","''")
		tableStr = tableStr & "<table cellpadding=""5"" cellspacing=""0"" border=""1"" bordercolor=""#9C331D"" width=""130px"" ><tr>"	
		tableStr = tableStr & "<td align=""center"" valign=""middle"" bgcolor=""4D190E"" height=""89px""><img src=" & pic.src & " original=" & pic.original & " alt=""" & title & """ width=" & w & " height=" & h & " style=""cursor:hand;"" onclick=""" & func & """></td>"
		tableStr = tableStr & "</tr></table></td>"	
		
		if i mod 5 = 4 then 
			tableStr = tableStr & "</tr>"
		end if 
	next
	
	i = i - 1
	do until i mod 5 = 4
		i = i + 1
		
		tableStr = tableStr & "<td align=""right"" width=""130px"">"
		tableStr = tableStr & "<table cellpadding=""5"" cellspacing=""0"" width=""130px"" ><tr>"	
		tableStr = tableStr & "<td height=""89px""></td>"
		tableStr = tableStr & "</tr></table></td>"	
		
		if i mod 5 = 4 then
			tableStr = tableStr & "</tr>"
		end if
	loop
	
	tableStr = tableStr & "</table>"
	
	document.all.AllPics.innerHTML = tableStr
		
	'alert("aaa")
end function

function MovePic(target)
	call ShowPic(target)
	
	if m_PicIndex <= 0 then 
		document.all.prev.style.visibility = "hidden"
	else
		document.all.prev.style.visibility = "visible"
	end if
	
	if m_PicIndex >= picList.length-1 then 
		document.all.next.style.visibility = "hidden"
	else
		document.all.next.style.visibility = "visible"
	end if
end function

function ShowPic(Target)
	dim picList, pic
	set picList = document.all.PicList
	
	m_PicIndex = m_PicIndex + target

	if m_PicIndex < 0 then m_PicIndex = (picList.length - 1)
	if m_PicIndex >= picList.length then m_PicIndex = 0

	m_Transition = m_Transition + 1
	if m_Transition > 23 then m_Transition = 0 

	set pic = document.all.PIC1
	
	pic.style.visibility = "hidden"
	pic.filters(0).Apply()
	pic.filters(0).transition = m_Transition
	
	pic.src = picList(m_PicIndex).src
	
	call strechPic(picList(m_PicIndex).w, picList(m_PicIndex).h)
	pic.style.visibility = "visible"
	pic.filters(0).Play()
	
	if (not(document.all("PIC_TITLE") is nothing)) then
		'--- אם יש אוביקט לכותרת
		document.all.PIC_TITLE.innerText = picList(m_PicIndex).tag
	end if

	'm_Timer =  window.setTimeout( "ShowPic(1)", m_TimerInterval + 3000)
end function

function growPic(Picsrc,title)
	dim src,i
	'i=instr(Picsrc,location.hostname)+len(location.hostname)
	'src=mid(Picsrc,i)
	src = Picsrc
	call window.open("PicShow.aspx?src="&src&"&title="&title,"Pic","scrollbars=no,fullscreen")
end function

function SetFrameHeight()
	if (parent.document.getElementsByName("ApplicationIFrame").length = 1) then
		parent.document.all.ApplicationIFrame.height = LastObject.offsetTop + 20
	end if
end function

sub sendToFriend()
	location.href="mailto:?subject=" & replace(parent.location.href,"&","%26")
end sub
