// JavaScript Document based on sample from http://www.alistapart.com/articles/switchymclayout
// Used to establish framework for possible future switchable body style

 
window.onload   = prwfResize; 
window.onresize = prwfResize;  
 
   
/**
  Note that anything under 800x600 is rendered as 800x600 (min size) and could be replaced by ultralow later
*/
function setScreenClass(){  
	var imageWidth ; 
	var imageHeight ; 
	var fmt = document.documentElement.clientWidth;	
	var ht  = document.documentElement.clientHeight;
 	var cls = (fmt<=240)?'low800x600':
	(fmt>240&&fmt<=320)?'low800x600':
	(fmt>320&&fmt<=640)?'low800x600':
	(fmt>640&&fmt<=800)?'low800x600': 
	(fmt>1024&&fmt<=1152)?'med1280x800':
	(fmt>1152&&fmt<=1280)?'med1280x800':
	(fmt>1280&&fmt<=1440)?'wide1440': 
	(fmt>1440)?'wide1920':'normal';
    // document.getElementById('count').innerHTML=fmt+'px x '+ht + '-> '+cls; 
	//display in browser  
	document.body.className=cls;     	
	//if      (cls == 'normal'     ){ imageWidth=466; imageHeight=350; }
	//else if (cls == 'med1280x800' || cls == 'wide1440'){ imageWidth=668; imageHeight=500; }
	//else if (cls == 'low800x600') { imageWidth=320; imageHeight=240; }
	//else{ imageWidth=133; imageHeight=100;	}
	//document.getElementById('image1').innerHTML=getTag(imageWidth, imageHeight); 
};


function prwfResize(){ 
     var imageWidth ; 
	var imageHeight ; 
	var fmt = document.documentElement.clientWidth;	
	var ht  = document.documentElement.clientHeight;
 	var cls = (fmt<=240)?'low800x600':
	(fmt>240&&fmt<=320)?'low800x600':
	(fmt>320&&fmt<=640)?'low800x600':
	(fmt>640&&fmt<=800)?'low800x600': 
	(fmt>1024&&fmt<=1152)?'med1280x800':
	(fmt>1152&&fmt<=1280)?'med1280x800':
	(fmt>1280&&fmt<=1440)?'wide1440':
	(fmt>1440)?'wide1920':'normal';
	// document.getElementById('count').innerHTML=fmt+'px x '+ht + '-> '+cls; 
	//display in browser   	
	document.body.className=cls;   
	/*
	if      (cls == 'normal'     ){ imageWidth=534; imageHeight=400; }
	else if (cls == 'med1280x800' || cls == 'wide1440' ||  cls == 'wide1920'){ 
		imageWidth=801; imageHeight=600; 
	}
	else if (cls == 'low800x600') { imageWidth=320; imageHeight=240; } 
	else{ imageWidth=133; imageHeight=100;	}
	setImageSize(imageWidth, imageHeight);
	*/
}
 

//Used to control flash menu

function next(){  
	if(currentImage < imageArray.length-1){
		currentImage++;
	    document.getElementById('desc').childNodes[0].nodeValue =  getTitle( currentImage ) ;
		imageNumStr = "";
		currentImage < 10 ? imageNumStr = "0" + currentImage :imageNumStr=""+currentImage; 
    	document.getElementById('currentImageNum').childNodes[0].nodeValue = imageNumStr;
		loadImage(imageArray[currentImage]);
	}	
}

function previous(){    
	if(currentImage > 1){
		currentImage--;
    	document.getElementById('desc').childNodes[0].nodeValue =   getTitle( currentImage ) ;
		imageNumStr = "";
		currentImage < 10 ? imageNumStr = "0" + currentImage :imageNumStr= ""+currentImage; 
    	document.getElementById('currentImageNum').childNodes[0].nodeValue = imageNumStr;
		
		
		loadImage(imageArray[currentImage]);
	}	
}

function loadImageNum( imageNum  ){ 
	currentImage = imageNum;  
	document.getElementById('desc').childNodes[0].nodeValue =  getTitle( currentImage ) ;
	imageNumStr = "";
	currentImage < 10 ? imageNumStr = "0" + currentImage :imageNumStr= ""+currentImage; 
	document.getElementById('currentImageNum').childNodes[0].nodeValue = imageNumStr;
	loadImage(imageArray[imageNum]);
}

 
// Inactive 
 
function showPic (whichpic) {
if (document.getElementById) {
	imgtag =  getObject('placeholder');
	imgtag.src = whichpic.href;
if (whichpic.title) {
    document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
  } 
  else {
    document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
  }
  return false;
}
else {
  return true;
}
}
 

function getObject( obj ) {
  var strObj
  if ( document.all ) {
    strObj = document.all.item( obj );
  } else if ( document.getElementById ) {
    strObj = document.getElementById( obj );
  }
  return strObj;
}
 
function popupSite(url, name, w, h ) { 
	var params = 'width=' + w + ',height=' + h; 
	window.open(url, name, params);
}

function getTitle(imageId){ 
	if(titleArray[imageId] == ''){
	   return imageId;	
	}
	else {
		return titleArray[imageId]; 
	}
}

/*
function popupStockSite(){
	var w = document.documentElement.clientWidth;	
	var h  = document.documentElement.clientHeight;
	var params = 'width=' + 800 + ',height=' + 600; 
	window.open('personalsite/personal.html', 'artsite', params);
}
*/
 
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}

//Flash proxy scripts
//my proxy interface
function loadImage(url){ 
   flashProxy.call('loadImage', url ); 
}

function setFile(fileName){
   flashProxy.call('loadXML', fileName);
} 

function setImageSize(w, h){   
  // alert("setting");
   flashProxy.call('setImageSize', w, h );
}
  
//utility method
function getTag(w, h){    
    var tag = new FlashTag('prwfslideshow1.2.swf', w, h); // last two arguments are height and width
	var initialImage = imageArray[currentImage];
	var flashVarString = 'lcId='+uid  + '&initialImage=' + initialImage + '&imageWidth=' + w + '&imageHeight=' + h ;
    tag.setFlashvars(flashVarString); 
	return tag ;
}
