
var siteBaseUrl = '10-4-08/';


function closePopup() {
	e = document.getElementById('imgPopup');
	if (e){
		e.parentNode.removeChild(e);
	} 
}

function attachOnClickImage(id, imgPath , altText, imgWidth, imgHeight){
	element = document.getElementById(id);
	element.style.cursor = 'pointer';
	var imageText = altText || '';		
	var imgWidth = Number(imgWidth);
	var imgHeight = Number(imgHeight);		
	element.removeAttribute("href");
	element.onclick = function (){
		//check if this element exists.
		e = document.getElementById('imgPopup');
		if (!e){
			popupKeyListener();
			var myDiv = document.createElement("DIV");
			myDiv.id = "imgPopup";
			myIframe = document.createElement('iframe');
			myIframe.src = siteBaseUrl+'blank.php?image='+encodeURIComponent(imgPath)+'&altText='+encodeURIComponent(imageText);			
			myIframe.scrolling = 'no';
			myIframe.width = imgWidth;
			myIframe.height = imgHeight+45;					
			myIframe.frameBorder = "0";
			//Append
			myDiv.appendChild(myIframe);
			myDimensions = getWindowDimensions();
			myWidth = myDimensions[0];
			myDiv.style.width = imgWidth+'px';
			myDiv.style.left = (myWidth / 2) - (imgWidth / 2)-18 + "px";
			document.body.appendChild(myDiv);
		}
		return false;
	}
}

/**
 * Caption Formater for the Gallery
 */
var CaptionFormat = {
	init : function(total){
		
		var styleChange = function (){this.parentNode.style.cursor ='default';};
		
		for(var i = 1; i <= total ; i++){
			var elementName = "caption"+ i;
			var ImageName = "Image"+ i;
			//First get the parent and cancel the onhover cursor
			img = document.getElementById(ImageName);
			img.parentNode.onmouseover  = styleChange;
			//Now format the caption if its length is > 30
			e = document.getElementById(elementName);
			if (e){
				if (e.innerHTML.length > 20) CaptionFormat.attachFormatting(e, i);				
			}
		}
	},
	/**
	 * @param element e - the element we wish to format
	 * @param int i - the id of that element
	 */
	attachFormatting : function (e, i){
		var caption = CaptionFormat.removeHtmlChar(e.innerHTML);
		e.innerHTML = '';
		
		startString = caption.slice(0,12) + '...';
		var mySpan = document.createElement('span');		
		mySpan.appendChild(document.createTextNode(startString));
		//mySpan.className = 'captionText';
		var toggle = document.createElement('img');
		toggle.src = siteBaseUrl + 'images/togglePlus.gif';
		toggle.setAttribute('align','right');
		toggle.className = 'togglePlus';
		
		toggle.onclick = CaptionFormat.getToggleFunc(caption);
		toggle.onmouseover = CaptionFormat.cursorPointerFunc();
		
		e.appendChild(toggle);
		e.appendChild(mySpan);
	},
	/**
	 * Returns the toogle func
	 * @param {Object} caption
	 */
	getToggleFunc :  function (caption){
		return(function (e){
			if (!e) var e = window.event;
				e.cancelBubble = true;
							
			if (e.stopPropagation) e.stopPropagation();
			CaptionFormat.toggleCaption(this, caption);
		});
	},
	cursorPointerFunc  : function (){
		return(function(){this.style.cursor = 'pointer';});
	},
	/**
	 * 
	 * @param {string} string
	 */
	removeHtmlChar : function (string){
		return string.replace(new RegExp("&amp;"),'&');		
	},
	
	/**
	 * 
	 * @param {element} e
	 */
	toggleCaption: function(e, caption){
		if (e.className == 'togglePlus'){
			e.src = siteBaseUrl + 'images/toggleMinus.gif';
			e.className = 'toggleMinus'; 
			//previousSibling  nextSibling
			e.nextSibling.innerHTML = caption;			
		} else {
			e.className = 'togglePlus';
			e.src = siteBaseUrl + 'images/togglePlus.gif';
			e.nextSibling.innerHTML = caption.slice(0,12)+ '...';
		}
	},
	fixIECaption : function (e){
		if (document.all && !window.opera && window.XMLHttpRequest){
			e.style.height = 'auto';
		}
	}
};

function processKeyPress(e){
	var e = window.event  || e;
	try {
		var key = e.keyCode || e.which;
	} catch (e){
		var key = 0;
	}
	//Esc or x (lowercase)
	if (key == 27 || key == 120) closePopup();
}

function popupKeyListener() {document.onkeypress = processKeyPress; }

function getWindowDimensions(){
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

if (window.top.location != window.location) {
	window.top.location.href = window.document.location.href ;
}