/*
* Smoothbox v20070814 by Boris Popoff (http://gueschla.com)
*
* Based on Cody Lindley's Thickbox, MIT License
*
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
// on page load call TB_init
window.addEvent('domready', TB_init);
// prevent javascript error before the content has loaded
TB_WIDTH = 0;
TB_HEIGHT = 0;
var TB_doneOnce = 0 ;
// add smoothbox to href elements that have a class of .smoothbox
function TB_init(){
$$("a.smoothbox").each(function(el){el.onclick=TB_bind});
}
function TB_bind(event) {
var event = new Event(event);
// stop default behaviour
event.preventDefault();
// remove click border
this.blur();
// get caption: either title or name attribute
var caption = this.title || this.name || "";
// get rel attribute for image groups
var group = this.rel || false;
// display the box for the elements href
TB_show(caption, this.href, group);
this.onclick=TB_bind;
return false;
}
//creates xmlhttp object - written by David Boon
function createXMLHttp()
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
return xmlhttp;
}
//Pass the web service a reference to the function to call when it returns
//Callback must be a function accepting a single argument, which will be the response text
//Written by David Boon
function MakeAjaxCall(url, callback) {
var ajaxObj=createXMLHttp();
ajaxObj.open("GET", url,true);
ajaxObj.onreadystatechange=function() {
if (ajaxObj.readyState==4) {
callback(ajaxObj.responseText);
}
}
ajaxObj.send(null);
}
// this version of TB_show built for the christmas wrapper version (different layout, rounded corners)
// called when the user clicks on a smoothbox link
function TB_show_empty(url) {
if ( !$("TB_overlay") )
{
new Element('iframe').setProperty('id', 'TB_HideSelect').injectInside(document.body);
$('TB_HideSelect').setOpacity(0);
new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
$('TB_overlay').setOpacity(0);
TB_overlaySize();
new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
//$('TB_load').innerHTML = "
"; // edited for location of "loading.gif"
TB_load_position();
new Fx.Style('TB_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);
}
if ( !$("TB_load") )
{
new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
$('TB_load').innerHTML = "
"; // edited for location of "loading.gif"
TB_load_position();
}
if ( !$("TB_window") )
{
new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
$('TB_window').setOpacity(0);
$('TB_window').style.border="none";
$('TB_window').style.background="transparent";
}
//window.onscroll=TB_positionEffect;
// check if a query string is involved
var baseURL = url.match(/(.+)?/)[1] || url;
//$("TB_closeWindowButton").onclick = TB_remove;
/* if(url.indexOf('TB_inline') != -1){
$("TB_ajaxContent").innerHTML = ($(params['inlineId']).innerHTML);
TB_position();
TB_showWindow();
}else if(url.indexOf('TB_iframe') != -1){
TB_position();
if(frames['TB_iframeContent'] == undefined){//be nice to safari
$(document).keyup( function(e){ var key = e.keyCode; if(key == 27){TB_remove()} });
TB_showWindow();
}
}else{
var handlerFunc = function(){
TB_position();
TB_showWindow();
};
var myRequest = new Ajax(url, {method: 'get',update: $("TB_ajaxContent"),onComplete: handlerFunc}).request();
}
*/
MakeAjaxCall(url,function(e){
$('TB_window').innerHTML=e;
TB_position();
//TB_showWindow();
new Fx.Style('TB_window', 'opacity',{duration: 1000, transition: Fx.Transitions.sineInOut}).start(0,1);
$('TB_load').style.display="none";
});
window.onresize=function(){ TB_position(); TB_load_position(); TB_overlaySize();}
window.onscroll=function(){ TB_overlaySize(); }
document.onkeyup = function(event){
var event = new Event(event);
if(event.code == 27){ // close
TB_remove();
}
}
}
// called when the user clicks on a smoothbox link
function TB_show(caption, url, rel) {
// create iframe, overlay and box if non-existent
if ( !$("TB_overlay") )
{
new Element('iframe').setProperty('id', 'TB_HideSelect').injectInside(document.body);
$('TB_HideSelect').setOpacity(0);
new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
$('TB_overlay').setOpacity(0);
TB_overlaySize();
new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
$('TB_load').innerHTML = "
"; // edited for location of "loading.gif"
TB_load_position();
new Fx.Style('TB_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);
}
if ( !$("TB_load") )
{
new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
$('TB_load').innerHTML = "
"; // edited for location of "loading.gif"
TB_load_position();
}
if ( !$("TB_window") )
{
new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
$('TB_window').setOpacity(0);
}
$("TB_overlay").onclick=TB_remove;
//window.onscroll=TB_positionEffect;
// check if a query string is involved
var baseURL = url.match(/(.+)?/)[1] || url;
// regex to check if a href refers to an image
var imageURL = /\.(jpe?g|png|gif|bmp)/gi;
// check for images
if ( baseURL.match(imageURL) ) {
var dummy = { caption: "", url: "", html: "" };
var prev = dummy,
next = dummy,
imageCount = "";
// if an image group is given
if ( rel ) {
function getInfo(image, id, label) {
return {
caption: image.title,
url: image.href,
html: " " + label + ""
}
}
// find the anchors that point to the group
var imageGroup = [] ;
$$("a.smoothbox").each(function(el){
if (el.rel==rel) {imageGroup[imageGroup.length] = el ;}
})
var foundSelf = false;
// loop through the anchors, looking for ourself, saving information about previous and next image
for (var i = 0; i < imageGroup.length; i++) {
var image = imageGroup[i];
var urlTypeTemp = image.href.match(imageURL);
// look for ourself
if ( image.href == url ) {
foundSelf = true;
imageCount = "Image " + (i + 1) + " of "+ (imageGroup.length);
} else {
// when we found ourself, the current is the next image
if ( foundSelf ) {
next = getInfo(image, "next", "Next >");
// stop searching
break;
} else {
// didn't find ourself yet, so this may be the one before ourself
prev = getInfo(image, "prev", "< Prev");
}
}
}
}
imgPreloader = new Image();
imgPreloader.onload = function() {
imgPreloader.onload = null;
// Resizing large images
var x = window.getWidth() - 150;
var y = window.getHeight() - 150;
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
if (imageWidth > x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight > y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight > y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth > x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}
// End Resizing
// TODO don't use globals
TB_WIDTH = imageWidth + 30;
TB_HEIGHT = imageHeight + 60;
// TODO empty window content instead
$("TB_window").innerHTML += "" + "