	/*  2/09/10  CPE   File Created  */

var cycleInterval = 3000;
  
function linkToProgram( programImg )
{
   var string = programImg+","+0;
   createCookie( "currentImageCookie", string  ); 
   document.href = "htmldocs/asprogspJ.html";
}

function createCookie(name,value) 
 {
    var string = name+"="+value+"; path=/";
    document.cookie = name+"="+value+"; path=/"; /* Expires on exit of program */
 }


function readCookie(cookie_name) 
 {
    /* alert ("Cookie read: " + document.cookie);  */
    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

    if ( results )
       return ( unescape ( results[2] ) );
    else
      return null;
}

function deleteCookie(name)
 {
    document.cookie = name + '=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;';
 }


var maxWidth = 1600
var maxHeight = 1200;

var currentIndex = -1;
var t;
var timer_is_on = 0;
var savedCookie;
var imageElement, iframe, hiddenimage, PPbutton, PPbuttonState;

function Cstartup() {
   /* P7_CycleMenu(); */
   savedCookie = readCookie('cycleCookie') ;
   if ( savedCookie ) deleteCookie ( 'cycleCookie' );  
   imageElement = document.getElementById("imageElement"); 
   hiddenimage = document.getElementById('hiddenimage');
   PPbutton = document.getElementById('PPbutton'); 
   PPbuttonState = "paused"; 
   
   iframe = document.getElementById("iframe1");   
   for (var i = 0; i < vImage.length; i++ ) {
      pages[i] = vImage[i];
   }  
   if ( savedCookie && savedCookie == "SITE2" ) CreOrder();   
   currentIndex = -1;  
   timer_is_on = 0; 
   CstartCycle();
}

function CsetInterval( interval ) {
    Cpause();
    cycleInterval = interval * 1000;
    CstartCycle();
}

function CstartCycle() {
   if ( PPbuttonState == "playing" ) {      
      Cpause();
   } else {  
      PPbuttonState = "playing";
      var source = "../styles/p7exp/images/pause.gif";
      PPbutton.src = source;
      if ( !timer_is_on ) {
         timer_is_on = 1; 
         clearInterval(t);
         CdisplayProg();   
         t=setInterval("CdisplayProg()", cycleInterval);       
      } 
   }   
}

function CdisplayProg() {
   ++currentIndex;
   if (currentIndex >= vImage.length) {
      if ( savedCookie ) { 
          Cpause();
          nextPage();              
      } else {    
          CreOrder();
          currentIndex = 1;   // wrap around
      }
   }    
   putOnPage();
}

function Cnext() {
    Cpause();
    CdisplayProg();
}

function Cprevious() {
    Cpause();
    currentIndex = currentIndex - 2;
    if ( currentIndex < -1 ) currentIndex = vImage.length - 2;  // wrap around
    CdisplayProg();
}

function Cpause()
{
   var source = "../styles/p7exp/images/play.gif";   
   PPbutton.src = source;
   PPbuttonState = "paused";
   clearInterval(t);
   timer_is_on=0;
}

function Cexit()
{
   clearInterval(t);
   history.go(-1);       // Back button
}


function CdoResize()
{
    var availWidth = document.body.clientWidth - 60;
    var availHeight = document.body.clientHeight - 80;
    var maxW = (availWidth < maxWidth) ? availWidth : maxWidth;
    var maxH = (availHeight < maxHeight ) ? availHeight : maxHeight;

    var cx = pages[currentIndex][1];
    var cy = pages[currentIndex][2];

    cx = cx * maxH / cy ;
    cy = maxH ;
    if ( cx > maxW ) {
        cy = cy * maxW / cx ;
        cx = maxW ; 
    } 
    imageElement.width = cx;
    imageElement.height = cy; 
}


function CreOrder() {
   var row, temp;
   for (var i = 0; i < vImage.length; i++ ) {
      row = i + Math.floor(Math.random() * (vImage.length - i) ) ; 
      temp = pages[i];    
      pages[i] = pages[row];
      pages[row] = temp;
   }
}