/*
* thickbox 3.1 - one box to rule them all.
* by cody lindley (http://www.codylindley.com)
* copyright (c) 2007 cody lindley
* licensed under the mit license: http://www.opensource.org/licenses/mit-license.php
*/
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
//on page load call tb_init
$(document).ready(function(){
tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
imgloader = new image();// preload image
imgloader.src = tb_pathtoimage;
});
//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domchunk){
$(domchunk).click(function(){
var t = this.title || this.name || null;
var a = this.href || this.alt;
var g = this.rel || false;
tb_show(t,a,g);
this.blur();
return false;
});
}
function tb_show(caption, url, imagegroup) {//function called when the user clicks on a thickbox link
try {
if (typeof document.body.style.maxheight === "undefined") {//if ie 6
$("body","html").css({height: "100%", width: "100%"});
$("html").css("overflow","hidden");
if (document.getelementbyid("tb_hideselect") === null) {//iframe to hide select elements in ie6
$("body").append("
");
$("#tb_overlay").click(tb_remove);
}
}else{//all others
if(document.getelementbyid("tb_overlay") === null){
$("body").append("");
$("#tb_overlay").click(tb_remove);
}
}
if(tb_detectmacxff()){
$("#tb_overlay").addclass("tb_overlaymacffbghack");//use png overlay so hide flash
}else{
$("#tb_overlay").addclass("tb_overlaybg");//use background and opacity
}
if(caption===null){caption="";}
$("body").append("");//add loader to the page
$('#tb_load').show();//show loader
var baseurl;
if(url.indexof("?")!==-1){ //ff there is a query string involved
baseurl = url.substr(0, url.indexof("?"));
}else{
baseurl = url;
}
var urlstring = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
var urltype = baseurl.tolowercase().match(urlstring);
if(urltype == '.jpg' || urltype == '.jpeg' || urltype == '.png' || urltype == '.gif' || urltype == '.bmp'){//code to show images
tb_prevcaption = "";
tb_prevurl = "";
tb_prevhtml = "";
tb_nextcaption = "";
tb_nexturl = "";
tb_nexthtml = "";
tb_imagecount = "";
tb_foundurl = false;
if(imagegroup){
tb_temparray = $("a[rel="+imagegroup+"]").get();
for (tb_counter = 0; ((tb_counter < tb_temparray.length) && (tb_nexthtml === "")); tb_counter++) {
var urltypetemp = tb_temparray[tb_counter].href.tolowercase().match(urlstring);
if (!(tb_temparray[tb_counter].href == url)) {
if (tb_foundurl) {
tb_nextcaption = tb_temparray[tb_counter].title;
tb_nexturl = tb_temparray[tb_counter].href;
tb_nexthtml = " next >";
} else {
tb_prevcaption = tb_temparray[tb_counter].title;
tb_prevurl = tb_temparray[tb_counter].href;
tb_prevhtml = " < prev";
}
} else {
tb_foundurl = true;
tb_imagecount = "image " + (tb_counter + 1) +" of "+ (tb_temparray.length);
}
}
}
imgpreloader = new image();
imgpreloader.onload = function(){
imgpreloader.onload = null;
// resizing large images - orginal by christian montoya edited by me.
var pagesize = tb_getpagesize();
var x = pagesize[0] - 150;
var y = pagesize[1] - 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
tb_width = imagewidth + 30;
tb_height = imageheight + 60;
$("#tb_window").append("" + ""+caption+"
" + tb_imagecount + tb_prevhtml + tb_nexthtml + "
");
$("#tb_closewindowbutton").click(tb_remove);
if (!(tb_prevhtml === "")) {
function goprev(){
if($(document).unbind("click",goprev)){$(document).unbind("click",goprev);}
$("#tb_window").remove();
$("body").append("");
tb_show(tb_prevcaption, tb_prevurl, imagegroup);
return false;
}
$("#tb_prev").click(goprev);
}
if (!(tb_nexthtml === "")) {
function gonext(){
$("#tb_window").remove();
$("body").append("");
tb_show(tb_nextcaption, tb_nexturl, imagegroup);
return false;
}
$("#tb_next").click(gonext);
}
document.onkeydown = function(e){
if (e == null) { // ie
keycode = event.keycode;
} else { // mozilla
keycode = e.which;
}
if(keycode == 27){ // close
tb_remove();
} else if(keycode == 190){ // display previous image
if(!(tb_nexthtml == "")){
document.onkeydown = "";
gonext();
}
} else if(keycode == 188){ // display next image
if(!(tb_prevhtml == "")){
document.onkeydown = "";
goprev();
}
}
};
tb_position();
$("#tb_load").remove();
$("#tb_imageoff").click(tb_remove);
$("#tb_window").css({display:"block"}); //for safari using css instead of show
};
imgpreloader.src = url;
}else{//code to show html
var querystring = url.replace(/^[^\?]+\??/,'');
var params = tb_parsequery( querystring );
tb_width = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to url
tb_height = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to url
ajaxcontentw = tb_width - 30;
ajaxcontenth = tb_height - 45;
if(url.indexof('tb_iframe') != -1){// either iframe or ajax window
urlnoquery = url.split('tb_');
$("#tb_iframecontent").remove();
if(params['modal'] != "true"){//iframe no modal
$("#tb_window").append("");
}else{//iframe modal
$("#tb_overlay").unbind();
$("#tb_window").append("");
}
}else{// not an iframe, ajax
if($("#tb_window").css("display") != "block"){
if(params['modal'] != "true"){//ajax no modal
$("#tb_window").append("");
}else{//ajax modal
$("#tb_overlay").unbind();
$("#tb_window").append("");
}
}else{//this means the window is already up, we are just loading new content via ajax
$("#tb_ajaxcontent")[0].style.width = ajaxcontentw +"px";
$("#tb_ajaxcontent")[0].style.height = ajaxcontenth +"px";
$("#tb_ajaxcontent")[0].scrolltop = 0;
$("#tb_ajaxwindowtitle").html(caption);
}
}
$("#tb_closewindowbutton").click(tb_remove);
if(url.indexof('tb_inline') != -1){
$("#tb_ajaxcontent").append($('#' + params['inlineid']).children());
$("#tb_window").unload(function () {
$('#' + params['inlineid']).append( $("#tb_ajaxcontent").children() ); // move elements back when you're finished
});
tb_position();
$("#tb_load").remove();
$("#tb_window").css({display:"block"});
}else if(url.indexof('tb_iframe') != -1){
tb_position();
if($.browser.safari){//safari needs help because it will not fire iframe onload
$("#tb_load").remove();
$("#tb_window").css({display:"block"});
}
}else{
$("#tb_ajaxcontent").load(url += "&random=" + (new date().gettime()),function(){//to do a post change this load method
tb_position();
$("#tb_load").remove();
tb_init("#tb_ajaxcontent a.thickbox");
$("#tb_window").css({display:"block"});
});
}
}
if(!params['modal']){
document.onkeyup = function(e){
if (e == null) { // ie
keycode = event.keycode;
} else { // mozilla
keycode = e.which;
}
if(keycode == 27){ // close
tb_remove();
}
};
}
} catch(e) {
//nothing here
}
}
//helper functions below
function tb_showiframe(){
$("#tb_load").remove();
$("#tb_window").css({display:"block"});
}
function tb_remove() {
$("#tb_imageoff").unbind("click");
$("#tb_closewindowbutton").unbind("click");
$("#tb_window").fadeout("fast",function(){$('#tb_window,#tb_overlay,#tb_hideselect').trigger("unload").unbind().remove();});
$("#tb_load").remove();
if (typeof document.body.style.maxheight == "undefined") {//if ie 6
$("body","html").css({height: "auto", width: "auto"});
$("html").css("overflow","");
}
document.onkeydown = "";
document.onkeyup = "";
return false;
}
function tb_position() {
$("#tb_window").css({marginleft: '-' + parseint((tb_width / 2),10) + 'px', width: tb_width + 'px'});
if ( !(jquery.browser.msie && jquery.browser.version < 7)) { // take away ie6
$("#tb_window").css({margintop: '-' + parseint((tb_height / 2),10) + 'px'});
}
}
function tb_parsequery ( query ) {
var params = {};
if ( ! query ) {return params;}// return empty object
var pairs = query.split(/[;&]/);
for ( var i = 0; i < pairs.length; i++ ) {
var keyval = pairs[i].split('=');
if ( ! keyval || keyval.length != 2 ) {continue;}
var key = unescape( keyval[0] );
var val = unescape( keyval[1] );
val = val.replace(/\+/g, ' ');
params[key] = val;
}
return params;
}
function tb_getpagesize(){
var de = document.documentelement;
var w = window.innerwidth || self.innerwidth || (de&&de.clientwidth) || document.body.clientwidth;
var h = window.innerheight || self.innerheight || (de&&de.clientheight) || document.body.clientheight;
arraypagesize = [w,h];
return arraypagesize;
}
function tb_detectmacxff() {
var useragent = navigator.useragent.tolowercase();
if (useragent.indexof('mac') != -1 && useragent.indexof('firefox')!=-1) {
return true;
}
}