function CTransViewport(a_oTransManager, a_szItemClassName, a_szLeftButtonID, a_szRightButtonID, a_szItemBodyClassName)
{ var m_oTransManager = a_oTransManager; this.m_oTransManager = m_oTransManager; var m_szItemClassName = a_szItemClassName; this.m_szItemClassName = m_szItemClassName; var m_szLeftButtonID = a_szLeftButtonID; this.m_szLeftButtonID = m_szLeftButtonID; var m_oLeftButton = ei(m_szLeftButtonID); this.m_oLeftButton = m_oLeftButton; var m_szRightButtonID = a_szRightButtonID; this.m_szRightButtonID = m_szRightButtonID; var m_oRightButton = ei(m_szRightButtonID); this.m_oRightButton = m_oRightButton; var m_szItemBodyClassName = a_szItemBodyClassName; this.m_szItemBodyClassName = m_szItemBodyClassName; var m_arrImageStore = new Array(); this.m_arrImageStore = m_arrImageStore; var m_oItemCollection = null; var m_oItemBodyCollection = null; var m_iBaseZIndex = null; var m_iSlideLeftID = -1; var m_iSlideLeftInterval = 10; var m_iSlideRightID = -1; var m_iSlideRightInterval = 10; var m_oTransAccel = new CTransAccel(0); var m_oLeftItem = null; var m_oRightItem = null; if(m_szItemClassName && m_szItemBodyClassName&& m_oLeftButton && m_oLeftButton)
{ __preloadImages( { left_up: "images/portfolio/nav_left_up.gif", left_hover: "images/portfolio/nav_left_hover.gif", left_disabled: "images/portfolio/nav_left_disabled.gif", right_up: "images/portfolio/nav_right_up.gif", right_hover: "images/portfolio/nav_right_hover.gif", right_disabled: "images/portfolio/nav_right_disabled.gif"
} ); m_oItemCollection = etc("div", m_szItemClassName); m_oItemBodyCollection = etc("div", m_szItemBodyClassName); if( m_oItemCollection && (m_oItemCollection.length > 0) &&
m_oItemBodyCollection && (m_oItemBodyCollection.length > 0) &&
( m_oItemCollection.length == m_oItemBodyCollection.length )
)
{ m_oItemCollection.currentIndex = 0; if(m_oItemCollection[0].style.zIndex)
{ m_iBaseZIndex = parseInt(m_oItemCollection[0].style.zIndex); if(m_iBaseZIndex < 1)
{ m_iBaseZIndex = 100;}
}
else
{ m_iBaseZIndex = 100;}
for(var i = 0; i < m_oItemCollection.length; i++)
{ m_oItemCollection[i].style.zIndex = m_iBaseZIndex - i; if(i)
{ m_oItemCollection[i].style.left = m_oItemCollection[i].offsetWidth;}
m_oItemCollection[i].itemBody = m_oItemBodyCollection[i]; m_oItemCollection[i].itemBody.otransmultifade = new CTransMultiFade(m_oTransManager); m_oItemCollection[i].itemBody.otransmultifade.addElement(m_oItemCollection[i].itemBody); m_oItemCollection[i].itemBody.otranscontent = new CTransContent(m_oTransManager); m_oItemCollection[i].itemBody.otranscontent.addElement(m_oItemCollection[i].itemBody);}
m_oLeftButton.onclick = buttonClick; m_oLeftButton.onmouseover = leftbuttonMouseOver; m_oLeftButton.onmouseout = leftbuttonMouseOut; m_oRightButton.onclick = buttonClick; m_oRightButton.onmouseover = rightbuttonMouseOver; m_oRightButton.onmouseout = rightbuttonMouseOut;}
}
function getItemBody()
{ if(!m_oItemCollection) return null; if(null == m_oItemCollection.currentIndex) return null; return m_oItemCollection[m_oItemCollection.currentIndex].itemBody
}
this.getItemBody = getItemBody; function slideLeft()
{ if(!m_oItemCollection) return; stop(); __offsetItemsRight(); m_oLeftItem = m_oItemCollection[m_oItemCollection.currentIndex]; m_oItemCollection.currentIndex++; if(m_oItemCollection.currentIndex >= m_oItemCollection.length)
{ m_oItemCollection.currentIndex = 0;}
m_oRightItem = m_oItemCollection[m_oItemCollection.currentIndex]; var iWidth = m_oRightItem.offsetWidth; m_oRightItem.style.left = iWidth; m_oLeftItem.style.left = 0; __updateZIndex(); m_oLeftItem.startLeft = (m_oLeftItem.style.left)? parseInt(m_oLeftItem.style.left) : 0; m_oRightItem.startLeft = (m_oRightItem.style.left)? parseInt(m_oRightItem.style.left) : 0; m_oLeftItem.finalLeft = -iWidth; m_oRightItem.finalLeft = 0; m_oTransAccel.run(iWidth); m_iSlideLeftID = setTimeout(__slideLeft,m_iSlideLeftInterval);}
this.slideLeft = slideLeft; function slideRight()
{ if(!m_oItemCollection) return; stop(); __offsetItemsRight(); m_oRightItem = m_oItemCollection[m_oItemCollection.currentIndex]; m_oItemCollection.currentIndex--; if(m_oItemCollection.currentIndex < 0)
{ m_oItemCollection.currentIndex = m_oItemCollection.length - 1;}
m_oLeftItem = m_oItemCollection[m_oItemCollection.currentIndex]; var iWidth = m_oLeftItem.offsetWidth; m_oLeftItem.style.left = -iWidth; m_oRightItem.style.left = 0; __updateZIndex(); m_oLeftItem.startLeft = -iWidth; m_oRightItem.startLeft = (m_oRightItem.style.left)? parseInt(m_oRightItem.style.left) : 0; m_oLeftItem.finalLeft = 0; m_oRightItem.finalLeft = iWidth; m_oTransAccel.run(iWidth); m_iSlideRightID = setTimeout(__slideRight,m_iSlideRightInterval);}
this.slideRight = slideRight; function stop()
{ if(-1 != m_iSlideLeftID)
{ clearTimeout(m_iSlideLeftID); m_iSlideLeftID = -1;}
}
function __preloadImages(a_arrImagePairs)
{ for(szName in a_arrImagePairs)
{ preloadImage(a_arrImagePairs[szName]); m_arrImageStore[szName] = "url('"+a_arrImagePairs[szName]+"')";}
}
function buttonClick(a_e)
{ var oe = getElementFromEvent(a_e); if(!oe) return; if(m_oTransManager)
{ m_oTransManager.runSequence(oe.id + '_click');}
}
function leftbuttonMouseOver(a_e)
{ var oe = getElementFromEvent(a_e); if(!oe) return; oe.style.backgroundImage = m_arrImageStore['left_hover']; if(m_oTransManager)
{ m_oTransManager.runSequence(oe.id + '_mouseover');}
}
function rightbuttonMouseOver(a_e)
{ var oe = getElementFromEvent(a_e); if(!oe) return; oe.style.backgroundImage = m_arrImageStore['right_hover']; if(m_oTransManager)
{ m_oTransManager.runSequence(oe.id + '_mouseover');}
}
function leftbuttonMouseOut(a_e)
{ var oe = getElementFromEvent(a_e); if(!oe) return; oe.style.backgroundImage = m_arrImageStore['left_up'];}
function rightbuttonMouseOut(a_e)
{ var oe = getElementFromEvent(a_e); if(!oe) return; oe.style.backgroundImage = m_arrImageStore['right_up'];}
function __updateZIndex()
{ for(var i = 0; i < m_oItemCollection.length; i++)
{ if(i <= m_oItemCollection.currentIndex)
{ m_oItemCollection[i].style.zIndex = m_iBaseZIndex - m_oItemCollection.currentIndex-0 + i;}
else
{ m_oItemCollection[i].style.zIndex = m_iBaseZIndex - m_oItemCollection.currentIndex - (i - m_oItemCollection.currentIndex);}
}
}
function __slideLeft()
{ if(!m_oRightItem) return; if(!m_oLeftItem) return; var iDistanceTraveled = m_oTransAccel.getDistanceTraveled(); var iLeftLeft = m_oLeftItem.startLeft - iDistanceTraveled; var iRightLeft = m_oRightItem.startLeft - iDistanceTraveled; if(m_oTransAccel.isDone())
{ stop(); m_oLeftItem.style.left = m_oLeftItem.finalLeft; m_oRightItem.style.left = m_oRightItem.finalLeft; if(m_oTransManager)
{ m_oTransManager.continueSequence();}
return;}
if(iLeftLeft > m_oLeftItem.finalLeft)
{ m_oLeftItem.style.left = iLeftLeft;}
if(iRightLeft > m_oRightItem.finalLeft)
{ m_oRightItem.style.left = iRightLeft;}
m_iSlideLeftID = setTimeout(__slideLeft,m_iSlideLeftInterval);}
function __slideRight()
{ if(!m_oRightItem) return; if(!m_oLeftItem) return; var iDistanceTraveled = m_oTransAccel.getDistanceTraveled(); var iLeftLeft = m_oLeftItem.startLeft-0 + iDistanceTraveled; var iRightLeft = m_oRightItem.startLeft-0 + iDistanceTraveled; if(m_oTransAccel.isDone())
{ stop(); m_oLeftItem.style.left = m_oLeftItem.finalLeft; m_oRightItem.style.left = m_oRightItem.finalLeft; if(m_oTransManager)
{ m_oTransManager.continueSequence();}
return;}
if(iLeftLeft < m_oLeftItem.finalLeft)
{ m_oLeftItem.style.left = iLeftLeft;}
if(iRightLeft < m_oRightItem.finalLeft)
{ m_oRightItem.style.left = iRightLeft;}
m_iSlideRightID = setTimeout(__slideRight,m_iSlideRightInterval);}
function __offsetItemsRight()
{ for(var i = 0; i < m_oItemCollection.length; i++)
{ m_oItemCollection[i].style.zIndex = m_iBaseZIndex - i; if(i != m_oItemCollection.currentIndex)
{ m_oItemCollection[i].style.left = m_oItemCollection[i].offsetWidth;}
}
}
}
