function BoldIn(Btn)
{
  eval (Btn + ".style.fontWeight = 'bold'");
}

function BoldOut(Btn)
{
  eval (Btn + ".style.fontWeight = 'normal'");
}

function changeLayout(NewLayout)
{
  if  (Layout>=0) {
    BoldOut("Layout"+Layout.toString()+"Button");
  }
  Layout=NewLayout;
	switch (Layout) {
		case 0: Slide.style.pixelLeft=354;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=334;
    		    Slide.style.pixelHeight=334;
      	    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset+344;
      	    Toc.style.pixelWidth=678;
      	    Toc.style.pixelHeight=100;
      	    Control.style.pixelWidth=678;
      	    PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=678;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+444;
    		    Video.style.pixelLeft=10;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=334;
    		    Video.style.pixelHeight=334;
    		    break;
    case 1: Slide.style.pixelLeft=10;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=334;
    		    Slide.style.pixelHeight=334;
      	    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset+344;
      	    Toc.style.pixelWidth=678;
      	    Toc.style.pixelHeight=100;
      	    Control.style.pixelWidth=678;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=678;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+444;
      	    Video.style.pixelLeft=354;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=334;
    		    Video.style.pixelHeight=334;
    		    break;
	  case 2: Slide.style.pixelLeft=354;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=654;
    		    Slide.style.pixelHeight=574;
      	    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset+344;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=230;
      	    Control.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+574;
      	    Video.style.pixelLeft=10;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=334;
    		    Video.style.pixelHeight=334;
    		    break;
    case 3: Slide.style.pixelLeft=10;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=334;
    		    Slide.style.pixelHeight=334;
      	    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset+344;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=230;
      	    Control.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+574;
      	    Video.style.pixelLeft=354;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=654;
    		    Video.style.pixelHeight=574;
    		    break;
    case 4: Slide.style.pixelLeft=-350;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=334;
    		    Slide.style.pixelHeight=334;
      	    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=574;
      	    Control.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+574;
      	    Video.style.pixelLeft=354;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=654;
    		    Video.style.pixelHeight=574;
    		    break;
    case 5: Slide.style.pixelLeft=354;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=654;
    		    Slide.style.pixelHeight=574;
    		    Toc.style.pixelLeft=10;
      	    Toc.style.pixelTop=ContentOffset;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=574;
      	    Control.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=998;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+574;
      	    Video.style.pixelLeft=-350;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=334;
    		    Video.style.pixelHeight=334;
      	    break;
    case 6: Slide.style.pixelLeft=-350;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=334;
    		    Slide.style.pixelHeight=334;
      	    Toc.style.pixelLeft=-350;
      	    Toc.style.pixelTop=ContentOffset;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=574;
      	    Control.style.pixelWidth=814;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=814;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+694;
      	    Video.style.pixelLeft=10;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=814;
    		    Video.style.pixelHeight=694;
    		    break;
    case 7: Slide.style.pixelLeft=10;
    		    Slide.style.pixelTop=ContentOffset;
    		    Slide.style.pixelWidth=814;
    		    Slide.style.pixelHeight=694;
    		    Toc.style.pixelLeft=-350;
      	    Toc.style.pixelTop=ContentOffset;
      	    Toc.style.pixelWidth=334;
      	    Toc.style.pixelHeight=574;
      	    Control.style.pixelWidth=814;
            PopupAlphaBackground.style.pixelTop=ContentOffset;
            PopupAlphaBackground.style.pixelWidth=814;
            PopupAlphaBackground.style.pixelHeight=ContentOffset+694;
      	    Video.style.pixelLeft=-350;
    		    Video.style.pixelTop=ContentOffset;
    		    Video.style.pixelWidth=334;
    		    Video.style.pixelHeight=334;
      	    break;
	}
  TocDiv.style.pixelWidth=Toc.style.pixelWidth-14;
  TocDiv.style.pixelHeight=Toc.style.pixelHeight-30;
  MiniControl.style.pixelWidth=Control.style.pixelWidth;
  MiniTitleOverflow.style.pixelWidth=MiniControl.style.pixelWidth-38;
  SetScrollTitle();
  changeImage();
  if (AutoLayout) {
    BoldIn("LayoutAutoButton");
  } else {
    BoldOut("LayoutAutoButton");
    BoldIn("Layout"+Layout.toString()+"Button");
  }
  Slide.style.visibility = 'visible';
  Video.style.visibility = 'visible';
  Toc.style.visibility = 'visible';
  TocTable.style.display = 'block';
  Control.style.visibility = 'visible';
  MiniControl.style.visibility = 'visible';
}

function changeImage()
{
	var Container = document.getElementById('SlideImageContainer');
	if (Container) {
		var OldDiv = document.getElementById('SlideImageContainerDiv');
		if (OldDiv) {
			Container.removeChild(OldDiv);
		}
		if ((Layout!=4) && (Layout!=6)) {
			var NewDiv = document.createElement('div');
			NewDiv.id = 'SlideImageContainerDiv';
			switch (Layout) {
			case 0: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide320x240.png')"; 
					NewDiv.style.pixelWidth = 320;
					NewDiv.style.pixelHeight = 240;
					break;
			case 1: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide320x240.png')"; 
					NewDiv.style.pixelWidth = 320;
					NewDiv.style.pixelHeight = 240;
					break;
			case 2: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide640x480.png')"; 
					NewDiv.style.pixelWidth = 640;
					NewDiv.style.pixelHeight = 480;
					break;
			case 3: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide320x240.png')";  
					NewDiv.style.pixelWidth = 320;
					NewDiv.style.pixelHeight = 240;
					break;
			case 5: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide640x480.png')";  
					NewDiv.style.pixelWidth = 640;
					NewDiv.style.pixelHeight = 480;
					break;
			case 7: NewDiv.style.backgroundImage="url('"+CurrentImage+"/slide800x600.png')";  
					NewDiv.style.pixelWidth = 800;
					NewDiv.style.pixelHeight = 600;
					break;
			}
			Container.appendChild(NewDiv);
			window.setTimeout(DoubleBuffer,500);
		}
	}
}

function RealignPlayer()
{
  if (player.style.width!=(Video.style.pixelWidth-14).toString()+'px') {
    if (document.getElementById("imageplayer")) {
      player.style.width=(Video.style.pixelWidth-14).toString()+'px';
      player.style.height='64px';
      imageplayer.style.width=(Video.style.pixelWidth-14).toString()+'px';
      imageplayer.style.height=(Video.style.pixelHeight-94).toString()+'px';
    } else {
      player.style.width=(Video.style.pixelWidth-14).toString()+'px';
      player.style.height=(Video.style.pixelHeight-30).toString()+'px';
    }
  } 
  window.setTimeout(RealignPlayer,1);
}

function DoubleBuffer()
{
	var Div = document.getElementById('SlideImageContainerDiv');
	if (Div) {
		var Container = document.getElementById('SlideImageContainer');
		Container.style.backgroundImage = Div.style.backgroundImage;
	}
}

function ShowLayoutPopup()
{
  if (PopupAlphaBackground.style.display=="none") {
    LayoutPopup.style.pixelLeft=10+(PopupAlphaBackground.style.pixelWidth-LayoutPopup.style.pixelWidth)/2;
    LayoutPopup.style.pixelTop=ContentOffset+(PopupAlphaBackground.style.pixelHeight-LayoutPopup.style.pixelHeight)/2;
    if (player.playState == 3) {
      WasPlayingBeforePopup=true;
    } else {
      WasPlayingBeforePopup=false;
    }
    player.controls.pause();
    player.style.display="none";
    if (document.getElementById("imageplayer")) {
      imageplayer.style.display="none";
    }
    PopupAlphaBackground.style.display="block"; 
    LayoutPopup.style.display="block"; 
  }
}

function HideLayoutPopup()
{
  LayoutPopup.style.display="none";
  PopupAlphaBackground.style.display="none";
  player.style.display="block";
  if (document.getElementById("imageplayer")) {
    imageplayer.style.display="block";
  }
  if (WasPlayingBeforePopup) {
    player.controls.play();
  }
}

function ShowSendPopup()
{
  if (PopupAlphaBackground.style.display=="none") {
    SendPopup.style.pixelLeft=10+(PopupAlphaBackground.style.pixelWidth-SendPopup.style.pixelWidth)/2;
    SendPopup.style.pixelTop=ContentOffset+(PopupAlphaBackground.style.pixelHeight-SendPopup.style.pixelHeight)/2;
    if (player.playState == 3) {
      WasPlayingBeforePopup=true;
    } else {
      WasPlayingBeforePopup=false;
    }
    player.controls.pause();
    player.style.display="none";
    if (document.getElementById("imageplayer")) {
      imageplayer.style.display="none";
    }
    PopupAlphaBackground.style.display="block"; 
    SendPopup.style.display="block"; 
    UpdateLink();
  }
}

function HideSendPopup()
{
  SendPopup.style.display="none";
  PopupAlphaBackground.style.display="none";
  player.style.display="block";
  if (document.getElementById("imageplayer")) {
    imageplayer.style.display="block";
  }
  if (WasPlayingBeforePopup) {
    player.controls.play(); 
  }
}

function mousemove(e) 
{
  if (DragLayoutPopup) {
    if (event.clientX-DragLayoutInX>0) {
      LayoutPopup.style.pixelLeft=event.clientX-DragLayoutInX;
    } else {
      LayoutPopup.style.pixelLeft=0;
    }
    if (event.clientY-DragLayoutInY>0) {
      LayoutPopup.style.pixelTop=event.clientY-DragLayoutInY;
    } else {
      LayoutPopup.style.pixelTop=0;
    }
  } else if (DragSendPopup) {
    if (event.clientX-DragSendInX>0) {
      SendPopup.style.pixelLeft=event.clientX-DragSendInX;
    } else {
      SendPopup.style.pixelLeft=0;
    }
    if (event.clientY-DragSendInY>0) {
      SendPopup.style.pixelTop=event.clientY-DragSendInY;
    } else {
      SendPopup.style.pixelTop=0;
    }
  } else {
    DragLayoutInX=event.clientX-LayoutPopup.style.pixelLeft;
    DragLayoutInY=event.clientY-LayoutPopup.style.pixelTop;
    DragSendInX=event.clientX-SendPopup.style.pixelLeft;
    DragSendInY=event.clientY-SendPopup.style.pixelTop;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  if (title.indexOf("StyleButton")==-1) {
    var NewStyle=title;
 } else {
    var NewStyle=title.replace("StyleButton","");
  }
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      document.getElementById(a.getAttribute("title")+"StyleButton").style.border="none";
      if(a.getAttribute("title") == NewStyle) {
        a.disabled = false;
        document.getElementById(a.getAttribute("title")+"StyleButton").style.border="solid 1px #FFFFFF";
      }
    }
  }
}

function Minimize()
{
  ContentOffset=35 
  Control.style.display = "none";
  changeLayout(Layout);
  MiniControl.style.display = "block";
  SetScrollTitle();
}

function Maximize()
{
  ContentOffset=100; 
  MiniControl.style.display = "none";
  changeLayout(Layout);
  Control.style.display = "block";
  AnimatedMiniControlText = false;
  window.clearInterval(AnimatedMiniControlTextID);
}

function ScrollTitle()
{
  if (!AnimatedMiniControlTextPaused) {
    MiniTitle.style.pixelLeft -= 1;
    if (MiniTitle.style.pixelLeft + MiniTitle.scrollWidth < 0) {
      MiniTitle.style.pixelLeft = MiniTitleOverflow.style.pixelWidth;
    }
  }
}

function SetScrollTitle()
{
  if (MiniTitleOverflow.style.pixelWidth-50<MiniTitle.scrollWidth) {
    if (!AnimatedMiniControlText) {
      MiniTitle.style.pixelLeft=MiniTitleOverflow.style.pixelWidth;
      AnimatedMiniControlText = true;
      AnimatedMiniControlTextID=window.setInterval("ScrollTitle()", 15); 
    }
  } else {
    AnimatedMiniControlText = false;
    window.clearInterval(AnimatedMiniControlTextID);
    MiniTitle.style.pixelLeft = 5;
  } 
}

