/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Last updated Mar 15th, 04'. Added "End of Gallery" message.
* This copyright notice must stay intact for legal use
***********************************************/

var restwidth=100 //1) width of the "neutral" area in the center of the gallery in px
var restheight=50
var maxspeed=50 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed2= 30

var endofgallerymsg="<span style='font-size: 11px'>End of Menus</span>" //3) message to show at end of gallery. Enter "" to disable message.

function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to  default height
var winattributes="width="+actualWidth+",height="+actualHeight+",resizable=yes"
window.open(path,"", winattributes)
}

var iedom=document.all||document.getElementById
var scrollspeed=0
var scrollspeed2=0
var movestate=""
var movestate2=""

var actualwidth=''
var actualheight=''
//var singlemenuwidth=''
var cross_scroll, ns_scroll, cross_scroll2
var loadedyes=0

var scrollmenutoggle=1

var leftratio
var leftoffset1
var leftoffset2
var newoffset
var topoffset1
var topoffset2

var MouseChanged=1
var MouseLeft=0
var MouseUp=0
var MouseRight=1
var MouseDown=0

var mtype
var cpos

var MaxHeight
var ZoomMode = 1

function SetMouseType()
{
mtype='pointer'
}

function MouseChange(){

if (iedom)
{
if (document.getElementById("motioncontainer"))
{
	document.getElementById('motioncontainer').style.cursor = mtype;
}
}
}


function zoompage(pgNo,NumPgs){
var PageWidth
var ScollChange

	PageWidth = actualwidth/NumPgs
	ScrollChange = (menuwidth/2 - PageWidth/2) - (PageWidth * (pgNo-1))
	if(ScrollChange > 0)
		{
		ScrollChange=0
		}

	if(ScrollChange<menuwidth-actualwidth)
		{
		ScrollChange=menuwidth - actualwidth
		}
	cross_scroll.style.left = ScrollChange
}

function zoompoint(){

//alert('cross.scroll left: ' + parseInt(cross_scroll.style.left) + '\nactualwidth: ' + actualwidth + '\nactualheight: ' + actualheight + '\ncposy: ' + cposy)

leftoffset1 = cposy * actualwidth
MaxWidth = (MaxHeight/actualheight) * actualwidth

leftoffset2 = (MaxWidth/actualwidth) * leftoffset1
newoffset = leftoffset2 - leftoffset1
document.getElementById('motiongallery').style.left=parseInt(document.getElementById('motiongallery').style.left)-newoffset+"px"


topoffset1 = cposx * actualheight
topoffset2 = (MaxHeight/actualheight) * topoffset1
newoffset = topoffset2-topoffset1
document.getElementById('motiongallery').style.top=parseInt(document.getElementById('motiongallery').style.top)-newoffset+"px"




actualheight = MaxHeight
actualwidth = MaxWidth

//document.getElementById('motiongallery').style.left=0-newoffset+"px"

ZoomMode = 1
//actualheight = 1158


if (iedom&&parseInt(cross_scroll.style.left)<(menuwidth-actualwidth)){
	cross_scroll.style.left=menuwidth-actualwidth
	MouseRight=0
}

if (iedom&&parseInt(cross_scroll.style.left)>0){
	cross_scroll.style.left=0
	MouseLeft=0
}

//actualwidth=1680
//actualheight=579

if (document.getElementById('tc1')) { document.getElementById('tc1').height=actualheight }
if (document.getElementById('tc2')) {document.getElementById('tc2').height=actualheight }
if (document.getElementById('tc3')) { document.getElementById('tc3').height=actualheight }
if (document.getElementById('tc4')) { document.getElementById('tc4').height=actualheight }
if (document.getElementById('tc5')) { document.getElementById('tc5').height=actualheight }
if (document.getElementById('tc6')) { document.getElementById('tc6').height=actualheight }
if (document.getElementById('tc7')) { document.getElementById('tc7').height=actualheight }
if (document.getElementById('tc8')) { document.getElementById('tc8').height=actualheight }
//if (document.getElementById('tc1')) { document.getElementById('tc1').height+=0 }

if(MouseRight==0 && parseInt(cross_scroll.style.left)-menuwidth > 0-actualwidth-1){
MouseRight=1
}

MouseLeft=0
MouseUp=0
MouseDown=0
MouseChanged=1

//maxspeed=200

	stopmotion()
}

function speedchange(val)
{
	maxspeed = val

	maxspeed2 = val * 0.75
}

function zoomfit(){


//alert('Top2: ' + document.getElementById('showpin').style.top + '\nLeft: ' + document.getElementById('showpin').style.left)

if (ZoomMode == 1){
ZoomMode = 0

document.getElementById('showpin').style.top=parseInt(document.getElementById('showpin').style.top) * (menuheight / actualheight) - 12 + "px"
document.getElementById('showpin').style.left=parseInt(document.getElementById('showpin').style.left) * (menuheight / actualheight) - 5 + "px"

leftoffset1=menuwidth/2-parseInt(document.getElementById('motiongallery').style.left)
leftratio=leftoffset1/actualwidth

//actualwidth = document.getElementById('trueContainer').offsetWidth
actualwidth = menuheight / actualheight * actualwidth

leftoffset2=leftratio*actualwidth


//alert(document.getElementById('showpin').style.top)

newoffset=leftoffset2-menuwidth/2

//actualheight=document.getElementById('trueContainer').offsetHeight

document.getElementById('motiongallery').style.left=0-newoffset+"px"
document.getElementById('motiongallery').style.top=0+"px"

//widthratio = actualheight / menuheight

//actualwidth = menuheight / actualheight * actualwidth
//document.getElementById('motiongallery').style.left = parseInt(document.getElementById('motiongallery').style.left) * (menuheight / actualheight)
actualheight = menuheight
}
else
{
document.getElementById('showpin').style.top=parseInt(document.getElementById('showpin').style.top) * (MaxHeight / actualheight) + 26 + "px"
document.getElementById('showpin').style.left=parseInt(document.getElementById('showpin').style.left) * (MaxHeight / actualheight) + 15 + "px"

leftoffset1=menuwidth/2-parseInt(document.getElementById('motiongallery').style.left)
leftratio=leftoffset1/actualwidth

actualwidth = ((MaxHeight)/actualheight) * actualwidth
leftoffset2=leftratio*actualwidth

newoffset=leftoffset2-menuwidth/2
//actualwidth=actualwidth + 0.7
actualheight = MaxHeight

document.getElementById('motiongallery').style.left=0-newoffset+"px"

ZoomMode = 1
//actualheight = 1158
}

if (iedom&&parseInt(cross_scroll.style.left)<(menuwidth-actualwidth)){
	cross_scroll.style.left=menuwidth-actualwidth
	MouseRight=0
}

if (iedom&&parseInt(cross_scroll.style.left)>0){
	cross_scroll.style.left=0
	MouseLeft=0
}

//actualwidth=1680
//actualheight=579

if (document.getElementById('tc1')) { document.getElementById('tc1').height=actualheight }
if (document.getElementById('tc2')) {document.getElementById('tc2').height=actualheight }
if (document.getElementById('tc3')) { document.getElementById('tc3').height=actualheight }
if (document.getElementById('tc4')) { document.getElementById('tc4').height=actualheight }
if (document.getElementById('tc5')) { document.getElementById('tc5').height=actualheight }
if (document.getElementById('tc6')) { document.getElementById('tc6').height=actualheight }
if (document.getElementById('tc7')) { document.getElementById('tc7').height=actualheight }
if (document.getElementById('tc8')) { document.getElementById('tc8').height=actualheight }
//if (document.getElementById('tc1')) { document.getElementById('tc1').height+=0 }

if(MouseRight==0 && parseInt(cross_scroll.style.left)-menuwidth > 0-actualwidth-1){
MouseRight=1
}

MouseLeft=0
MouseUp=0
MouseDown=0
MouseChanged=1

//maxspeed=200

//document.getElementById('showpin').style.top=parseInt(document.getElementById('showpin').style.top) * (menuheight / actualheight) + "px"
//document.getElementById('showpin').style.left=parseInt(document.getElementById('showpin').style.left) * (menuheight / actualheight) + "px"

//alert('Top2: ' + document.getElementById('showpin').style.top + '\nLeft: ' + document.getElementById('showpin').style.left)

}

function zoomin(){

if (iedom){
crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer

leftoffset1=menuwidth/2-parseInt(document.getElementById('motiongallery').style.left)
leftratio=leftoffset1/actualwidth

actualwidth = ((actualheight+50)/actualheight) * actualwidth
leftoffset2=leftratio*actualwidth

newoffset=leftoffset2-menuwidth/2
actualwidth=actualwidth + 0.7
actualheight = actualheight + 50

document.getElementById('motiongallery').style.left=0-newoffset+"px"

if (document.getElementById('tc1')) { document.getElementById('tc1').height+=50 }
if (document.getElementById('tc2')) { document.getElementById('tc2').height+=50 }
if (document.getElementById('tc3')) { document.getElementById('tc3').height+=50 }
if (document.getElementById('tc4')) { document.getElementById('tc4').height+=50 }
if (document.getElementById('tc5')) { document.getElementById('tc5').height+=50 }
if (document.getElementById('tc6')) { document.getElementById('tc6').height+=50 }
if (document.getElementById('tc7')) { document.getElementById('tc7').height+=50 }
if (document.getElementById('tc8')) { document.getElementById('tc8').height+=50 }
if (document.getElementById('tc1')) { document.getElementById('tc1').height+=0 }

if(MouseLeft==0 && newoffset>0){
MouseLeft=1
MouseChanged=1
}

if(MouseRight==0 && parseInt(cross_scroll.style.left)-menuwidth > 0-actualwidth-1){
MouseRight=1
MouseChanged=1
}

if(MouseDown==0 && actualheight>menuheight){
MouseDown=1
MouseChanged=1
}

//showhidediv("visible")

}
}

function zoomout(){

if (iedom){
crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer

leftoffset1=menuwidth/2-parseInt(document.getElementById('motiongallery').style.left)
leftratio=leftoffset1/actualwidth
actualwidth = ((actualheight-50)/actualheight) * actualwidth
leftoffset2=leftratio*actualwidth
newoffset=leftoffset2-menuwidth/2
actualwidth=actualwidth - 1
actualheight = actualheight - 50

document.getElementById('motiongallery').style.left=0-newoffset+"px"

if (document.getElementById('tc1')) { document.getElementById('tc1').height-=50 }
if (document.getElementById('tc2')) { document.getElementById('tc2').height-=50 }
if (document.getElementById('tc3')) { document.getElementById('tc3').height-=50 }
if (document.getElementById('tc4')) { document.getElementById('tc4').height-=50 }
if (document.getElementById('tc5')) { document.getElementById('tc5').height-=50 }
if (document.getElementById('tc6')) { document.getElementById('tc6').height-=50 }
if (document.getElementById('tc7')) { document.getElementById('tc7').height-=50 }
if (document.getElementById('tc8')) { document.getElementById('tc8').height-=50 }
if (document.getElementById('tc1')) { document.getElementById('tc1').height-=0 }

if(MouseLeft==1 && newoffset<=0){
MouseLeft=0
MouseChanged=1
//alert('Zoom Out Move Left')
}

//alert('Width: ' + parseInt(cross_scroll.style.left))
//alert('MenuWidth: ' + menuwidth)
//alert('ActualWidth: ' + actualwidth)

if(MouseRight==1 && parseInt(cross_scroll.style.left)-menuwidth <= 0-actualwidth+1){
MouseRight=0
MouseChanged=1
//alert('Zoom Out Move Right')
}

if(MouseDown==1 && actualheight<=menuheight){
MouseDown=0
MouseChanged=1
//alert('Zoom Out Move Down')
}

//showhidediv("visible")

}
}

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//function creatediv(){
//statusdiv=document.createElement("div")
//statusdiv.setAttribute("id","statusdiv")
//document.body.appendChild(statusdiv)
//statusdiv=document.getElementById("statusdiv")
//statusdiv.innerHTML=endofgallerymsg
//}

function positiondiv(){
//statusdiv.style.left=mainobjoffset+(menuwidth/2)-(statusdiv.offsetWidth/2)+"px"
//statusdiv.style.top=mainobjoffset2+(menuheight/2)-(statusdiv.offsetHeight/2)+"px"
//statusdiv.style.top=-500+"px"
}

//function showhidediv(what){


//if (endofgallerymsg!="")
//statusdiv.style.visibility=what
//}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function moveleft(){
//if (loadedyes){
//movestate="left"
//if (iedom&&parseInt(cross_scroll.style.left)-scrollspeed>(menuwidth-actualwidth)){
//cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
//if(MouseLeft==0){
//MouseChanged=1
//MouseLeft=1
//}
//lefttime=setTimeout("moveleft()",20)
//}
//else
//{
//cross_scroll.style.left=menuwidth-actualwidth
//if(MouseRight==1){
//MouseRight=0
//MouseChanged=1
//SetMouseType()
//MouseChange()
//}
//}
//}
}

function moveup()
{
//	if (loadedyes)
//		{
//		movestate2="up"
//		if(iedom&&parseInt(cross_scroll.style.top)-scrollspeed2>=(menuheight-actualheight))
//			{
//			cross_scroll.style.top=parseInt(cross_scroll.style.top)-scrollspeed2+"px"
//			if(MouseUp==0)
//				{
//				MouseChanged=1
//				MouseUp=1
//				}
//			uptime=setTimeout("moveup()",20)
//			}
//		else
//			{
//			cross_scroll.style.top=menuheight-actualheight
//			if(MouseDown==1)
//				{
//				MouseDown=0
//				MouseChanged=1
//				SetMouseType()
//				MouseChange()
//				}
//			if(MouseUp==0 && actualheight>menuheight)
//				{
//				MouseUp=1
//				MouseChanged=1
//				SetMouseType()
//				MouseChange()
//				}
//			}
//		}
}

function moveright(){
//if (loadedyes){
//movestate="right"
//if (iedom&&parseInt(cross_scroll.style.left)+scrollspeed<0){
//cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
//if(MouseRight==0){
//MouseChanged=1
//MouseRight=1
//}
//righttime=setTimeout("moveright()",20)
//showhidediv("hidden")
//}
//else
//{
//cross_scroll.style.left=0
//if(MouseLeft==1){
//MouseLeft=0
//MouseChanged=1
//SetMouseType()
//MouseChange()
//}
//showhidediv("visible")
//}
//}
}


function movedown()
{
//	if (loadedyes)
//		{
//		movestate2="down"
//		if (iedom&&parseInt(cross_scroll.style.top)+scrollspeed2<0)
//			{
//			cross_scroll.style.top=parseInt(cross_scroll.style.top)+scrollspeed2+"px"
//			if(MouseDown==0)
//				{
//				MouseChanged=1
//				MouseDown=1
//				}
//			downtime=setTimeout("movedown()",5)
//			}
//		else
//			{
//			cross_scroll.style.top=0
//			if(MouseUp==1)
//				{
//				MouseUp=0
//				MouseChanged=1
//				SetMouseType()
//				MouseChange()
//				}
//			if(MouseDown==0 && actualheight>menuheight)
//				{
//				MouseDown=1
//				MouseChanged=1
//				SetMouseType()
//				MouseChange()
//				}
//			}
//		}
}

var curposx
var curposy

function motionengine(e){
var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
curposy=window.event? event.clientX : e.clientX? e.clientX: ""
curposx=window.event? event.clientY : e.clientY? e.clientY: ""

curposy-=mainobjoffset-dsocx
curposx-=mainobjoffset2-dsocy

if(scrollmenutoggle)
{
var leftbound=(menuwidth-restwidth)/2
var rightbound=(menuwidth+restwidth)/2

var upbound=(menuheight-restheight)/2
var downbound=(menuheight+restheight)/2

if (curposy>rightbound){
scrollspeed=(curposy-rightbound)/((menuwidth-restwidth)/2) * maxspeed
if (window.righttime) clearTimeout(righttime)
if (movestate!="left") moveleft()
}
else if (curposy<leftbound){
scrollspeed=(leftbound-curposy)/((menuwidth-restwidth)/2) * maxspeed
if (window.lefttime) clearTimeout(lefttime)
if (movestate!="right") moveright()
}
else
scrollspeed=0

if (curposx>downbound){
scrollspeed2=(curposx-downbound)/((menuheight-restheight)/2) * maxspeed2
if (window.downtime) clearTimeout(downtime)
if (movestate2!="up") moveup()
}
else if (curposx<upbound){
scrollspeed2=(upbound-curposx)/((menuheight-restheight)/2) * maxspeed2
if (window.uptime) clearTimeout(uptime)
if (movestate2!="down") movedown()
}
else
scrollspeed2=0

if(MouseChanged){
MouseChanged=0
SetMouseType()
MouseChange()
}
}
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion(e){
//if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
if (window.lefttime) clearTimeout(lefttime)
if (window.righttime) clearTimeout(righttime)
if (window.uptime) clearTimeout(uptime)
if (window.downtime) clearTimeout(downtime)
movestate=""
movestate2=""
//}
}

var flashct=0;
var flashcol='red'
var CurrentHint

function flashhint(){
//document.getElementById('hintcontainer').innerHTML = '<font size="2" face="Arial"><font color=' + hintcol + '>&nbsp;&nbsp;&nbsp;&nbsp;Hint:</font><font color="#008000"> Click again to Unfreeze menus. Count:' + flashct + '</font></font>';

//alert('Flash Count: ' + flashct)

//if(flashct==2){
//document.getElementById('hintcontainer').innerHTML = '<font size="2" face="Arial"><font color="' + hintcol + '#7E011B">&nbsp;&nbsp;&nbsp;&nbsp;Hint:</font><font color="red"> Click again to Unfreeze menus. Count:' + flashct + '</font></font>';
//alert('Flash 1')
//}
//else if(flashct){
//document.getElementById('hintcontainer').innerHTML = '<font size="2" face="Arial"><font color="#7E011B">&nbsp;&nbsp;&nbsp;&nbsp;Hint:</font><font color=> Click again to Unfreeze menus. Count:' + flashct + '</font></font>';
//alert('Flash 2')
//}

if(flashcol=='red'){
flashcol='#008000'
}
else
{
flashcol='red'
}

if(flashct > 0){
document.getElementById('hintcontainer').innerHTML = '<font size="1" face="Arial"><font color="#7E011B">&nbsp;&nbsp;&nbsp;&nbsp;Hint:</font><font color="' + flashcol + '">' + CurrentHint + '</font></font>';
hinttime=setTimeout("flashhint()",500)
flashct=flashct - 1;
}
}

function fillup(){
if (iedom){

//alert('Initialize')
crossmain=document.getElementById? document.getElementById('motioncontainer') : document.all.motioncontainer
menuwidth=parseInt(crossmain.style.width)
mainobjoffset=getposOffset(crossmain, 'left')
cross_scroll=document.getElementById? document.getElementById('motiongallery') : document.all.motiongallery
//actualwidth=document.all? cross_scroll.offsetWidth : document.getElementById('trueContainer').offsetWidth
actualwidth=document.getElementById('trueContainer').offsetWidth
menuheight=parseInt(crossmain.style.height)
//menuheight=document.getElementById('tc1').height + 40
//crossmain.style.height = parseInt(menuheight)+'px'
//crossmain.style.width = parseInt(menuheight)+'px'
mainobjoffset2=getposOffset(crossmain, 'top')
//actualheight=document.all? cross_scroll.offsetHeight : document.getElementById('trueContainer').offsetHeight
//actualheight=document.getElementById('trueContainer').offsetHeight
actualheight=document.getElementById('tc1').height
//singlemenuwidth=document.getElementById('tc1').width
MaxHeight=actualheight
//alert('ActualHeight: ' + actualheight)


//actualheight=menuheight
restwidth = menuwidth / 2
restheight = menuheight / 2
//alert('Menu Width: ' + menuwidth + '\nActual Width: ' + actualwidth + '\nMenuHeight: ' +menuheight + '\nActualHeight: ' + actualheight)

//loadMenu(1)
//showButton(1)

crossmain.onmousemove=function(e){
motionengine(e)
}


crossmain.onmouseout=function(e){
stopmotion(e)
//showhidediv("hidden")
}

function openwindow(url)
{
  NewWindow=window.open(url,'newWin','alwaysRaised=1; width=800,height=600,left=20,top=20,toolbar=No,location=No,scrollbars=no,status=No,resizable=yes,fullscreen=No');  NewWindow.focus(); void(0);  
}

crossmain.onmousedown=function(e)
{
//	alert('ActualHeight: ' + actualheight)
//	alert('curposx: ' + curposx)

if(showingMenus == 1)
	{

	if (curposy < actualwidth)
	{
//	alert('curposx: ' + curposx + '\nTopScroll: ' + parseInt(document.getElementById('motioncontainer').scrollTop))
//	alert('curposx: ' + curposx + '\nTop2: ' + parseInt(document.getElementById('motiongallery').scrollTop) +  '\nTop3: ' + parseInt(document.getElementById('motioncontainer').scrollTop) +  '\nTop2: ' + parseInt(document.getElementById('trueContainer').scrollTop) + '\nTop: ' + parseInt(document.getElementById('motioncontainer').style.top) + '\nTop: ' + parseInt(document.getElementById('motiongallery').style.top) + '\nTop Offset: ' + getposOffset(crossmain, 'top') + '\n1: ' + document.getElementById('trueContainer').offsetHeight)
//	if(parent.document.getElementById('PopUpDiv').style.visibility=='hidden')
//		{
			cposx = (curposx - parseInt(document.getElementById('motiongallery').style.top))/actualheight
			
//			alert('cposx: ' + cposx)
//			alert('cposy: ' + cposy)

			cposx = (curposx + parseInt(document.getElementById('motioncontainer').scrollTop))/actualheight
			cposy = MenuNum - 1 + (curposy/actualwidth)
			if (cposx <= 1)
				{
				parent.frames['iframe4'].location.replace('../menu_wishlist_kasturi.asp?action=ADDDISH&toppos=' + cposx + '&rightpos=' + cposy + '&skin=' + 1);
				}
	}
}
loadedyes=1
}
}
}
//window.onload=fillup