/*
5digistar株式会社 [ActionBrowserサービス] 
Email： support@5digistar.co.jp 
URL： http://www.5digistar.co.jp/ 

Copyright (C) 2005 5digistar Inc. All Rights Reserved.
*/

function repositionBookmark(argSelectedPageNum, argWhichPage)
{
	if(AB.ViewerStatus!=0) return;
	
	var ObjLeft, ObjRight;
	var PageNum = argSelectedPageNum;
	var oLeft = getObj('lyLeftCanvas').style.visibility;
	var oRight = getObj('lyRightCanvas').style.visibility;	
	
	switch(AB.FlipDirection)
	{
	case 0:		
		if(argWhichPage == 0)
			PageNum = argSelectedPageNum - 1;
		else
			if(oRight == "hidden") return;		
		break;
	case 1:
		if(argWhichPage == 1)
			PageNum = argSelectedPageNum - 1;		
		else
			if(oLeft == "hidden") return;
		break;
	}

	if ( (PageNum < 0) || (PageNum > AB.PageCount) ) return;

	if (checkExistBookmark(PageNum)) return;
	
	for(var i=0; i < AB.BookmarkCount; i++)
	{
		ObjLeft = getObj('lyBookmarkLeft'+i);
		ObjRight = getObj('lyBookmarkRight'+i);

		if(ObjLeft.pagenum == ".")
		{
			setBookmark(ObjLeft, PageNum);
			setBookmark(ObjRight, PageNum);
			
			break;					
		}		
	}
	showBookmark();
}

function checkExistBookmark(argPageNum)
{
	var ObjLeft,ObjRight;

	for(var i=0; i < AB.BookmarkCount; i++)
	{
		ObjLeft = getObj('lyBookmarkLeft'+i);
		ObjRight = getObj('lyBookmarkRight'+i);
		
		if(ObjLeft.pagenum == argPageNum)
		{
			resetBookmark(ObjLeft);
			resetBookmark(ObjRight);
			return true;
		}
	}
	return false;
}

function showBookmark()
{
	var PageLeft, PageRight;
	var ObjLeft, ObjRight;

	switch(AB.FlipDirection)
	{
	case 0:
		PageRight = AB.IndexCurrentPage;
		PageLeft = PageRight - 1;
		
		for(var i=0; i < AB.BookmarkCount; i++)
		{
			ObjLeft = getObj('lyBookmarkLeft'+i);
			ObjRight = getObj('lyBookmarkRight'+i);
			hideBookmark(ObjLeft);
			hideBookmark(ObjRight);
			
			if( (ObjLeft.pagenum != ".") & (ObjLeft.pagenum == PageLeft) )
			{
				ObjLeft.style.visibility = "visible";
				ObjLeft.style.zIndex = 3;
			}
			else if(ObjLeft.pagenum == ".")
			{
				ObjLeft.style.visibility = "hidden";
				ObjLeft.style.zIndex = 1;
			}
			else if(ObjLeft.pagenum < PageLeft)
			{
				ObjLeft.style.visibility = "visible";
				ObjLeft.style.zIndex = 1;
			}		
			
			if( (ObjRight.pagenum != ".") & (ObjRight.pagenum == PageRight) )
			{
				ObjRight.style.visibility = "visible";
				ObjRight.style.zIndex = 3;
			}
			else if(ObjRight.pagenum == ".")
			{
				ObjRight.style.visibility = "hidden";
				ObjRight.style.zIndex = 1;	
			}		
			else if(ObjRight.pagenum > PageRight)
			{
				ObjRight.style.visibility = "visible";
				ObjRight.style.zIndex = 1;
			}
		}		
		break;
	case 1:
		PageLeft = AB.IndexCurrentPage;
		PageRight = PageLeft - 1;

		for(var i=0; i < AB.BookmarkCount; i++)
		{
			ObjLeft = getObj('lyBookmarkLeft'+i);
			ObjRight = getObj('lyBookmarkRight'+i);
			hideBookmark(ObjLeft);
			hideBookmark(ObjRight);
			
			if( (ObjLeft.pagenum !=".") & (ObjLeft.pagenum == PageLeft) )
			{
				ObjLeft.style.visibility = "visible";
				ObjLeft.style.zIndex = 3;
			}
			else if(ObjLeft.pagenum == ".")
			{
				ObjLeft.style.visibility = "hidden";
				ObjLeft.style.zIndex = 1;
			}
			else if(ObjLeft.pagenum > PageLeft)
			{
				ObjLeft.style.visibility = "visible";
				ObjLeft.style.zIndex = 1;
			}		
			
			if( (ObjRight.pagenum !=".") & (ObjRight.pagenum == PageRight) )
			{
				ObjRight.style.visibility = "visible";
				ObjRight.style.zIndex = 3;
			}
			else if(ObjRight.pagenum == ".")
			{
				ObjRight.style.visibility = "hidden";
				ObjRight.style.zIndex = 1;	
			}		
			else if(ObjRight.pagenum < PageRight)
			{
				ObjRight.style.visibility = "visible";
				ObjRight.style.zIndex = 1;
			}
		}			
		break;
	}
}

function hideBookmark(argObj)
{
	argObj.style.visibility = "hidden";
	argObj.style.zIndex = 1;
}

function hideBookmarks()
{
	var ObjLeft, ObjRight;
	
	for(var i=0; i < AB.BookmarkCount; i++)
	{
		ObjLeft = getObj('lyBookmarkLeft'+i);
		ObjRight = getObj('lyBookmarkRight'+i);
		hideBookmark(ObjLeft);
		hideBookmark(ObjRight);
	}
}

function setBookmark(argObj, argPagenum)
{
	argObj.pagenum = argPagenum;
	argObj.innerText = argPagenum;
}

function resetBookmark(argObj)
{
	hideBookmark(argObj);
	argObj.pagenum = ".";
	argObj.innerText = "";
}

function checkPageDirection(argId)
{
	if( argId.indexOf('Left')>0 )
		return 0;
	else
		return 1;
}

function gotoBookmark(Obj)
{
	GoToPageNum(Obj.pagenum);
}

function onAddBK()
{
	if (oSlideShow)	SlideShow();
		
	switch(arguments[0])
	{
	case 0:
		repositionBookmark(AB.IndexCurrentPage,0);
		break;
	case 1:
		repositionBookmark(AB.IndexCurrentPage,1);
		break;
	default:
		return;
		break;
	}
}

function onDelBK()
{
	if(AB.ViewerStatus!=0) return;
	
	if (oSlideShow)	SlideShow();
	
	if(confirm("全ブックマークを消去しますか？"))
	{
		for(var i=0; i < AB.BookmarkCount; i++)
		{
			resetBookmark(getObj('lyBookmarkLeft'+i));
			resetBookmark(getObj('lyBookmarkRight'+i));
		}
	}
	else
		return;	
}


var AB = new ABViewer();
AB.initializeLayout();
AB.oViewer = getObj('oViewer');
AB.oViewer.style.cssText = "margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;background-color:EEEEA7;background-image:URL("+AB.BackgroundImage+");background-repeat:repeat-x;";
