dim m_PicIndex
dim m_Timer
dim m_Transition 
dim m_TimerInterval
dim m_maxWidth, m_maxHeight

m_TimerInterval = 5000


function ShowMe()
	'--- מציג את התמונות
	
	StartPics()
	
	'--- מציג את הטקסט הראשון
	
	ShowFirstText()
	
	ShowChildren()
	
	'--- יוצר קישור לתגובה
	
	Send_Response()
	
	'--- נותן גובה לפריים
	
	SetFrameHeight()
end function

function StartPics()
	dim Pic
	m_PicIndex = 0
	
	
	'--- בדיקה שיש תמונות
	
	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 = cint(document.all.PIC1.width)
	m_maxHeight = cint(document.all.PIC1.height)
	
	if document.getElementsByName("PicList").length > 1 then
		'--- יש יותר מתמונה אחת
		
		set pic = document.all.PicList(0)
	else
		'--- יש רק תמונה אחת
		
		set pic = document.all.PicList
	end if
	
	'--- מקטין את התמונה
	
	call strechPic(pic.w,pic.h)
		
	document.all.PIC1.src = pic.src
	document.all.PIC1.original = pic.original
	document.all.PIC1.style.visibility = "visible"
	
	if (not(document.all("PIC_TITLE") is nothing)) then
		'--- אם יש אוביקט לכותרת
		
		document.all.PIC_TITLE.innerText = pic.tag
		document.all.PIC_TITLE.style.visibility = "visible"
	end if
	
	'if document.getElementsByName("PicList").length > 1 then
	'	'--- אם יש יותר מתמונה אחת
	'	m_Timer =  window.setTimeout( "ShowPic(1)", m_TimerInterval)
	'end if
end function

function ShowChildren()
	
	'--- בדיקה שיש ילדים
	
	if (( document.all("ChildList")) is nothing) then exit function
	
	'--- בדיקה שהאוביקט הראשי של הילדים קיים
	
	if (( document.all("CHILDREN")) is nothing) then 
		exit function
	end if
	
	dim tableStr
	tableStr = "<table dir=""rtl"">"
	tableStr = "<TABLE BORDER=""0"" cellspacing=""2"" cellpadding=""0"" align=""center"" width=""95%"" bgcolor=""#E7C373"">"			
	tableStr = tableStr & "<TR><td width=""1"" bgcolor=""#FFEA97""></td>"					

	dim i
	i=0
	dim Text1
		
	for i=0 to document.getElementsByName("ChildList").length-1
		
		if document.getElementsByName("ChildList").length > 1 then
		'--- יש יותר מטקסט אחד
	
			set Text1 = document.all.ChildList(i)
		else
		'--- יש רק טקסט אחד
	
			set Text1 = document.all.ChildList
		end if
		
		if i mod 4 = 0 then
			tableStr = tableStr & "<tr>"
			tableStr = tableStr & "<td width=""1"" bgcolor=""#FFEA97""></td>"
		end if
		
		tableStr = tableStr & "<TD style=""font-size:10pt;"" align=""center""><font color=""#FDD26D""><a class=""aChild"" href=""hi_show.aspx?id=" & text1.tag  & " "">" & text1.title & "</a></font></TD>"
		tableStr = tableStr & "<td width=""1"" bgcolor=""#FFEA97""></td>"
		
		if i mod 4 = 3 then 
			tableStr = tableStr & "</tr>"
			if i<>document.getElementsByName("ChildList").length-1 then
				tableStr = tableStr & "<TR><td></td><td bgcolor=""#FFEA97""></td>"
				tableStr = tableStr & "<td></td><td bgcolor=""#FFEA97""></td>"
				tableStr = tableStr & "<td></td><td bgcolor=""#FFEA97""></td>"
				tableStr = tableStr & "<td></td><td bgcolor=""#FFEA97""></td></TR>"
			end if
		end if 
	next
	
	i = i - 1
	do until i mod 4 = 3
		i = i + 1
		
		tableStr = tableStr & "<TD style=""font-size:10pt;"" align=""center""></TD>"
		tableStr = tableStr & "<td ></td>"
		
		if i mod 4 = 3 then
			tableStr = tableStr & "</tr>"
		end if
	loop
	
	tableStr = tableStr & "<tr><td height=""1"" bgcolor=""#FDD26D""></td></tr></table>"
	
	CHILDREN.innerHTML = tableStr
	
	document.all.CHILDREN.style.visibility = "visible"
	
end function

sub strechPic(width,height)
	dim pic
	set pic = document.all.PIC1
			
	'--- אין גדלים לתמונה
	
	if (width="" or height="") then
		exit sub
	end if
	
	'--- יש גדלים לתמונה
	
	dim h,w
	h=cint(height)
	w=cint(width)
		
	if h <= m_maxHeight and w <= m_maxWidth then
		'--- Enlarging Option - Disenabled
		
		document.all.PIC1.style.cursor = ""
		document.all.PIC1.onclick=""	
	else
		'--- Enlarging Option - Enabled
		
		document.all.PIC1.style.cursor = "hand"
		document.all.PIC1.onclick=GetRef("GrowPic")
	end if
	
	if h > m_maxHeight then
		w = w * (m_maxHeight / h)
		h=m_maxHeight
	end if
	
	if w > m_maxWidth then
		h = h * (m_maxWidth / w)
		w=m_maxWidth
	end if
	
	document.all.PIC1.style.height=h
	document.all.PIC1.style.width=w
end sub

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
	pic.original = picList(m_PicIndex).original
	
	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 ShowFirstText()
	dim text
	
	'--- בדיקה אם יש טקסטים
	
	if (( document.all("TextList")) is nothing) then exit function
	
	'--- בדיקה שקיים אוביקט ראשי של טקסט
	
	if (( document.all("TEXT1")) is nothing) then exit function
	
	if document.getElementsByName("TextList").length > 1 then
		'--- יש יותר מטקסט אחד
		
		set text = document.all.TextList(0)
		document.all.TextLink(0).color = "#E3951F"
	else
		'--- יש רק טקסט אחד
		
		set text = document.all.TextList
	end if
	
	'--- הכנסת הטקסט לאוביקט הטקסט הראשי
	
	document.all("TEXT1").innerHTML = MakeToolTipEnabled(text.innerText)
end function

function ShowText(index)
	document.all.TEXT1.innerHTML = MakeToolTipEnabled(document.all.TextList(index - 1).innerText)
	
	dim i
	
	for i = 0 to document.getElementsByName("TextLink").length - 1
		document.all.TextLink(i).color = "#996633"
	next
	document.all.TextLink(index-1).color = "#E3951F"
end function

function growPic()
	dim src
	src = document.all.Pic1.original
	call window.open("PicShow.aspx?src="&src&"&title="&document.all.PIC_TITLE.innerText,"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

function Send_Response()
	document.all.ResponseLink.href="send_mail.aspx?location=" & location.href & document.all.ResponseLink.title
end function

sub sendToFriend()
	location.href="mailto:?subject=" & replace(parent.location.href,"&","%26")
end sub

