/*
	Overview:	PipView is a JS object that controls the images and viewing
		of a PIP
	Usage:	An instance of this object needs to be instantiated on each
		pip page. The markup should be structured so that the main
		image has an id of "pip-main-image" and the thumbnails should
		be inside the pip-thumbs div. Each thumbnail should have a
		class name of pip-thumb and be wrapped with a link that has
		a class of thumb-control. The link should point to the large
		image URL for accessibility and parsing.
		NOTE:
		* The thumbnail anchors must have a class name of thumb-control
		* The path to the large images should be the href of the links
	Arguments:	NONE
	Methods:	Object is self-initializing so the constructor is built in.
			toggleImage: 	Switches the src for the main image
	Sample Use: var myPipViewer = new PipView();
*/
function PipView(){
	// Properties
	var t = this;
	t.image = '';
	t.thumb = '';
	// Self-Initialization
	if((document.getElementById) && (document.getElementsByTagName)){
		// Thumbnail Controls
		t.controlsParent = document.getElementById('pip-thumbs');
		if(t.controlsParent){
			t.controls = t.controlsParent.getElementsByTagName('a');
			for(var i=0, control; i<t.controls.length; i++){
				control=t.controls[i];
				if(control.className == 'thumb-control'){
				control.onclick = function(){t.toggleImage(this); return false;};
				}
			}
		}else{return false;}
		// Main Image
		t.image = document.getElementById('pip-main-image');
		if(!t.image){return false;}
	}else{return false;}
	// Methods
	t.toggleImage = function(link){
		t.image.src = link.href;
	};
}
// Onload Init
onloadHandlers[onloadHandlers.length] = 'PipViewer = new PipView();';
function openFeatureFlex(URL,title,winWidth,winHeight,resizable,scrollbars,location,toolbar,status,menubar) {
	var winY,winX = 0;
	if (screen.width>winWidth && screen.height>winHeight) {
		winX=(screen.width-winWidth)/2;
		winY=(screen.height-winHeight)/2;
	}
	var winOptions = "";
	if (resizable) {
		winOptions += ",resizable";
	}
	if (scrollbars) {
		winOptions += ",scrollbars";
	}
	if (location) {
		winOptions += ",location";
	}
	if (toolbar) {
		winOptions += ",toolbar";
	}
	if (status) {
		winOptions += ",status";
	}
	if (menubar) {
		winOptions += ",menubar";
	}
	if (winOptions.charAt(0) == ",") {
		winOptions = winOptions.substr(1);
	}
	winOptions  += ',top='+winY+',left='+winX + ',screenX=10,screenY=10,width='+winWidth+',height='+winHeight;
	var popupWin2 = window.open(URL, title, winOptions);
	window.top.name='opener';
	if (popupWin2) {
		popupWin2.focus();
	}
}
