 

currimage = 0;
maximage = 0;
var currzoom;
var imgArray = new Array();




function initlarge(){
  init("large");
}

function initmedium(){
  init("medium");
}

function zoomtoggle(){
  currzoom == "large" ? init("medium") : init("large");
  pageimg = document.getElementById("thepage");
  pageimg.src = imgArray[currimage].src;
}


function menutoggle(stylename){
  m = document.getElementById("leftmenuCell");
  if(stylename != null){
    m.className = stylename;
  }else{
    m.className == "hidden" ? m.className = "menuCell" : "hidden";  
  }
}


function init($size){  
  currzoom = $size;
  if($size == "medium"){    
    $imgbase = "/cspd/comics/2006/pages/medium/";
    imx = 500;
    imy = 646;
    menutoggle("menuCell"); 
  }else{
    $imgbase = "/cspd/comics/2006/pages/large/";   
    imx = 820;
    imy = 1061;
    menutoggle("hidden");    
  }


// All the images Should reflect flash xml
    imagesrc = new Array("" + $imgbase  +    "CSPDFrontCover.jpg", $imgbase  +          
"cspd001.jpg", $imgbase  + 
"cspd003.jpg", $imgbase  + 
"cspd004.jpg", $imgbase  + 
"cspd005.jpg", $imgbase  + 
"cspd006.jpg", $imgbase  + 
"cspd007.jpg", $imgbase  + 
"cspd008.jpg", $imgbase  + 
"cspd009.jpg", $imgbase  + 
"cspd010.jpg", $imgbase  + 
"cspd011.jpg", $imgbase  + 
"cspd012.jpg", $imgbase  + 
"cspd013.jpg", $imgbase  + 
"cspd014.jpg", $imgbase  + 
"cspd015.jpg", $imgbase  + 
"cspd016.jpg", $imgbase  + 
"cspd017.jpg", $imgbase  + 
"cspd018.jpg", $imgbase  + 
"cspd019.jpg", $imgbase  + 
"cspd020.jpg", $imgbase  + 
"cspd021.jpg", $imgbase  + 
"cspd022.jpg", $imgbase  + 
"cspd023.jpg", $imgbase  + 
"cspd024.jpg", $imgbase  + 
"cspd025.jpg", $imgbase  + 
"cspd026.jpg", $imgbase  + 
"cspd027.jpg", $imgbase  + 
"cspd028.jpg", $imgbase  + 
"cspd029.jpg", $imgbase  + 
"cspd030.jpg", $imgbase  + 
"cspd031.jpg", $imgbase  + 
"cspd032.jpg", $imgbase  + 
"cspd033.jpg", $imgbase  + 
"cspd034.jpg", $imgbase  + 
"cspd035.jpg", $imgbase  + 
"cspd036.jpg", $imgbase  + 
"cspd037.jpg", $imgbase  + 
"cspd038.jpg", $imgbase  + 
"cspd039.jpg", $imgbase  + 
"cspd040.jpg", $imgbase  + 
"cspd041.jpg", $imgbase  + 
"cspd042.jpg", $imgbase  + 
"cspd043.jpg", $imgbase  + 
"cspd044.jpg", $imgbase  + 
"cspd045.jpg", $imgbase  + 
"cspd046.jpg", $imgbase  + 
"cspd047.jpg", $imgbase  + 
"cspd048.jpg", $imgbase  + 
"cspd049.jpg", $imgbase  + 
"cspd050.jpg", $imgbase  + 
"cspd051.jpg", $imgbase  + 
"cspd052.jpg", $imgbase  + 
"cspd053.jpg", $imgbase  + 
"cspd054.jpg", $imgbase  + 
"cspd055.jpg", $imgbase  + 
"cspd056.jpg", $imgbase  + 
"cspd057.jpg", $imgbase  + 
"cspd058.jpg", $imgbase  + 
"cspd059.jpg", $imgbase  + 
"cspd060.jpg", $imgbase  + 
"cspd061.jpg", $imgbase  + 
"cspd062.jpg", $imgbase  + 
"cspd063.jpg", $imgbase  + 
"cspd064.jpg", $imgbase  + 
"cspd065.jpg", $imgbase  + 
"cspd066.jpg", $imgbase  + 
"cspd067.jpg", $imgbase  + 
"cspd068.jpg", $imgbase  + 
"cspd069.jpg", $imgbase  + 
"cspd070.jpg", $imgbase  + 
"cspd071.jpg", $imgbase  + 
"cspd072.jpg", $imgbase  + 
"cspd073.jpg", $imgbase  + 
"cspd074.jpg", $imgbase  + 
"cspd075.jpg", $imgbase  + 
"cspd076.jpg", $imgbase  + 
"CSPDBackCover.jpg");


  maximage = imagesrc.length - 1;

  for (var i in imagesrc){
    imgArray[i] = new Image(imx,imy);    
  }
  for (var i = currimage-1; i <= currimage+1 ; i++){      
    if(i >= -1 && i<=maximage){
      i >= 0 ? imgArray[i].src = imagesrc[i] : imgArray[maximage].src = imagesrc[maximage] ;  // pre-load first couple of images     
    }
  }  
}

function nextimg(){
  currimage < maximage ? currimage++ : currimage = 0;
 // alert('moving to ' + imagesrc[currimage]);
  pageimg = document.getElementById("thepage");
  pageimg.src = imgArray[currimage].src;
  if( currimage < maximage ) { // Load up next image in preparation
    imgArray[currimage + 1] = new Image(imx,imy);
    imgArray[currimage + 1].src = imagesrc[currimage + 1] ;
  }
  //pageimg.src = imagesrc[currimage];
}
function previmg(){
  currimage > 0 ? currimage-- : currimage = maximage;
  pageimg = document.getElementById("thepage");
  pageimg.src = imgArray[currimage].src;  
  if( currimage > 0 ) { // Load up next image in preparation
    imgArray[currimage - 1] = new Image(imx,imy);
    imgArray[currimage - 1].src = imagesrc[currimage - 1] ;
  }else{
    imgArray[maximage] = new Image(imx,imy);
    imgArray[maximage].src = imagesrc[maximage] ;
  }
}
