﻿
var lightboxDefaultWidth = 970;
var lightboxDefaultHeight = 580;

/*
 * Open image in lightbox, or page in popup
 * scroll: auto, yes, no
 */
function lightboxDelegate(url, caption, width, height, scroll, group) {

    //TODO launch lightbox if an image, else popup
    //var ext = getExtOfUrl(url);
    //if( ext != "pdf" ){
    
	var objLink = document.createElement('a');
	objLink.setAttribute('href',url);
	if(group){
		objLink.setAttribute('rel','lightbox['+ group +']');
	}else{
		objLink.setAttribute('rel','lightbox');
	}
	if (!width) width = lightboxDefaultWidth;
	if (!height) height = lightboxDefaultHeight;
	if (!scroll) scroll = "no";
	
	objLink.setAttribute('width',width);
	objLink.setAttribute('height',height);
	objLink.setAttribute('title',caption);
	objLink.setAttribute('scrolling',scroll);
	Lightbox.prototype.start(objLink);
		
    /*}else{
        
        if(url.indexOf("?") > -1){
            url += "&chromeless=1";
        }else{
            url += "?chromeless=1";
        }
    
		try{
			NewWindow(url, name, width, height, scroll);
		}catch(e){
		}
    }*/
}

function showTooltip(text) {
    //will show tooltip
}
function hideTooltip() {
    //will hide tooltip
}

/**
 *Gets the file extension of a url
 */
function getExtOfUrl(url){
    url = url.toString();
    if( url.indexOf("?") > -1){
        url = url.substr(0, url.indexOf("?"));
    }    
    if( url.lastIndexOf(".") > -1){
        url = url.substr( url.lastIndexOf(".")+1 );
    }    
    return url.toLowerCase();
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes,location=no,directories=no,status=no,menubar=no,toolbar=no'
	
	win = window.open(mypage,myname,settings);
	
}