
var imgClose = null;
var imgLoader = null;
var tbfix_closeImage = tbfix_plugin + '/tb-close.png';
var tbfix_pathToImage = tbfix_plugin + '/tb-anime.gif';

//jQuery('a[href]:not([hash])') or
//jQuery('a[href]:not([href^=#])') 

jQuery.noConflict();
jQuery(function(){
	jQuery('head')
		.append('<link href="'+tbfix_plugin+'/thickbox.css" rel="stylesheet" media="screen" />')
		.append('<script src="'+tbfix_plugin+'/thickbox.js" type="text/javascript"></script>')
		.append('<link href="'+tbfix_plugin+'/thickboxfix.css" rel="stylesheet" media="screen" />');

	jQuery(document).ready(function(){/*preload image*/
		window.imgs = window.imgs||[];
		imgClose = new Image(); imgClose.src = tbfix_closeImage; imgs[imgs.length] = imgClose;
		imgLoader = new Image(); imgLoader.src = tbfix_pathToImage; imgs[imgs.length] = imgLoader;
	});
	
	jQuery(document).ready(function(){//on page load call tbfix_init
		tbfix_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	});

	jQuery(document).ready(function(){
		jQuery(tbfix_node+' a[@rel*=lightbox\\w+]').addClass('thickbox');//lightbox or lightbox[wp-smugmug-]...
	});

	jQuery(document).ready(function(){
		var urlBasename = function(url) {
			var pos = 0;
			var x = url.replace(/\\/, '/');//unify slashes
			pos = x.lastIndexOf('/'); if (pos >= 0) {x = x.substring(pos+1);}
			pos = x.lastIndexOf('.'); if (pos >= 0) {x = x.substring(0, pos);}
			return x;
		};
		var arr = jQuery(tbfix_node+' a[href]:not([href^=#])').get();
		for (var i=0; i<arr.length; i++) {
			var aHref = jQuery(arr[i]).attr('href');
			if (aHref && aHref.match(/.bmp|.gif|.png|.jpg|.jpeg/i)) {
				jQuery(arr[i]).removeClass('thickbox').addClass('thickbox');//.attr('rel', 'gallery');
				/*
				fix link-title*/
				var ha = jQuery(arr[i]);
				var title = '';
				/*
				use image [title] or [alt]*/
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', ha.attr('alt'));}/*use anchor [alt]*/
				/*
				use image [title] or [alt]*/
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', ha.find(':first').attr('title'));}
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', ha.find(':first').attr('alt'));}
				/*
				use image [title] or [alt]*/
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', ha.parent().attr('title'));}
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', ha.parent().attr('alt'));}
				/*
				use image [title] or [base-name]*/
				title = ha.attr('title'); if (!title||title=='') {ha.attr('title', urlBasename(ha.find(':first').attr('src')));}
				/*
				remove others*/
				ha.find(':first').attr('title', '');
				ha.find(':first').attr('alt', '');
				ha.attr('alt', '');//alert(title);
			}
		}
	});
});/*or:
jQuery("a:has(img)[href$='.jpg']").attr({'class':'thickbox'});//add [class] to links to image
jQuery("a:has(img)[href$='.gif']").attr({'class':'thickbox'});
jQuery("a:has(img)[href$='.png']").attr({'class':'thickbox'});
*/


