var gLoadSpinnerUrl	= t_imageset_path + '/lightbox/lightbox-ico-loading.gif';
var gFailImage 		= t_imageset_path + '/lightbox/lightbox-btn-close.gif';

function mc_boxes() {
	var slider = $(".slide-message");
	
	var nxt = slider.parent().next('.mc-default-info');
	
	slider.empty().append(function() {
		//var s_title = '<h3>' + $(this).parentattr('title') + '</h3>';
		var s_con_got = $(this).parent().next('.mc-default-info');
		var s_title = '<h3>' + s_con_got.find('.mc-def-title').attr('title') + '</h3>';
		
		return s_title +  s_con_got.html();
	});//.append(nxt.find('.mc-author'));
}

/*
jQuery(function() {
	jQuery.support.borderRadius = false;
	jQuery.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
		if(document.body.style[this] !== undefined) jQuery.support.borderRadius = true;
		return (!jQuery.support.borderRadius);
	});
});
*/

$(document).ready(function(){
	
	// Check images are loaded and set some stuff
	
	$('<img src="http://www.google.com/intl/en_ALL/images/logo.gif' + '#' +
			Math.random() + '"/>').load(function() {
				//var imagesOn = 1;
				var mcBit = $('.slide-opts').find('dt').find('a.mc-icon');
				if($('body').css('background-color') != 'transparent') {
					// It's safe to turn off the text
					
					// Set up our sliding things
					/*
					var lb = $('.image-opts').find('a.lightbox').parent().next('dd').prepend(function() {
						var optI = $(this).parents('.image-opts');
						var pId = optI.attr('id').replace('opt-', '');
						
						//optI.find('.slide-opts').prepend('<dl><dt><a href="/phpBB3/download/file.php?id=' + pId + '" class="lightbox mc-icon mc-zoom" title="Zoom">Zoom</a></dt><dd title="Zoom">Open this image in a lightbox</dd></dl>');
						
					});
					*/
					
					$('.slide-opts').find('a.lightbox').each(function(i) {
						var ddn = $(this).parent().next('dd');
						$(this).addClass('mc-icon mc-zoom');
						ddn.attr('title', $(this).attr('title')).text($(this).next('input').attr('value'));
						$(this).attr('title', '');
					});
					
					//var lbText = lb.next('input').attr('value');
					
					//alert(lbText);
					
					mcBit.text('');
					
					$('.mc-hidden-info').hide();
					
					mc_boxes();
					
					$('.slide-opts').find('a').hover(function() {
							var tx = $(this).parent().next('dd').attr('title');
							var tt = $(this).parent().next('dd').text();
							
							$(this).parents('.slide-opts').next(".slide-message").empty();
							
							$(this).parents('.slide-opts').next(".slide-message").append('<h3>' + tx + '</h3>').append(tt);
							//$(this).parents('.slide-opts').next(".slide-message").find("span").text(tt);
						}, function(){
							//var tt = $(this).parents('.slide-opts').next(".slide-message").find("span").text();
							
							//$(this).parents('.slide-opts').next(".slide-message").empty();
							
							//$(this).parents('.slide-opts').next(".slide-message").append(function() {
							//	return '<h3>' + $(this).attr('title') + '</h3>';
							//});
							//$(this).parents('.slide-opts').next(".slide-message").find("span").text(function());
							
							mc_boxes();
						});
					
				}
				
			});
	
	$('.mc-slide-opts').find('dt').find('a.mc-icon').css('text-indent', '0px').attr('title', '');
	//$('.slide-opts').css('left', '-60px');
	
	$('.mc-slide-opts').css('opacity', '0.4');
	$('.slide-message').hide();
	
	$('.mc-image-opts').hover(function(){
		$(this).find(".slide-opts").animate({opacity: "0.8"}, "fast");
		}, function() {
		$(this).find(".slide-opts").animate({opacity: "0.4"}, "fast");
		});
	
	$('.mc-image-opts').hover(function(){
		$(this).find(".slide-message").animate({opacity: "show", right: "0"}, "fast");
		}, function() {
		$(this).find(".slide-message").animate({opacity: "hide", right: "-140px"}, "fast");
		});
	
	
	// Make our nifty round corners where possible
	/*
	if($.support.borderRadius)
	{
		var rad = '6px';
		var makeroundtop = $('.corners-top').parents('.panel, .forumbg, .forabg, .tabslist > li, .second-bar, .navbar, .post');
		var makeroundbot = $('.corners-bottom').parents('.panel, .forumbg, .forabg, .tabslist > li, .second-bar, .navbar, .post');
		
		makeroundtop.css({'-moz-border-radius-topright' : rad, '-moz-border-radius-topleft' : rad, '-khtml-border-top-right-radius' : rad});
		makeroundbot.css({'-moz-border-radius-bottomright' : rad, '-moz-border-radius-bottomleft' : rad});
		
		$('.corners-top, .corners-top span').not('.inverted-corners-top, .inverted-corners-top span, .special-corners-top, .special-corners-top span').css('background-image', 'none');
		$('.corners-bottom, .corners-bottom span').not('.special-corners-bottom, .headerbar .corners-bottom, .headerbar .corners-bottom span').css('background-image', 'none');
	}
	*/
	
	// Attachment expanders
	/*
	$('dl.thumbnail').find('dd').hide();
	$('dl.thumbnail').find('dt').append(
			'<div class="attachment-slider" style="left:260px;">Hi</div>'
			);
	$('.thumbnail').find('dt').hover(function() {
			$(this).find('.attachment-slider').animate({
				opacity: 	"show",
				left:		"200px",
				bottom:		"0",
				
			}, "slow");	
		}, function() {
			$(this).find('.attachment-slider').animate({
				opacity: 	"hide",
				left:		"260px",
				bottom:		"-60px",
			}, "slow");
		});
	*/
	
	$('dl.thumbnail').find('dd').css('width', function(){
		return $(this).prev('dt').find('a').width() + 'px';
	});
	$('dl.thumbnail').find('dt').find('a').attr('onclick', 'return false;');
	$('dl.thumbnail').find('dt').find('a').find('img').addClass('expandable');
	
	
	
	// Expander click
	$('dl.thumbnail').find('dt').find('a').click(function() {
		//var src = $(this).attr("src").replace("t=1", "mode=view");
		//$(this).attr("src", src);
		var cl = $(this).find('img');
		//var cc = $(this).find('img');
		
		if(cl.attr('class') == 'expanded') {
			//cl.addClass('expandable').removeClass('expanded');
			cl.addClass('expandable').removeClass('expanded');
			var src = cl.attr("src").replace("mode=view", "t=1");
			cl.attr("src", src); //.parents('dt').next('dd').css('width', 'auto');
			//$(this).parent().next('dd').hide();
			//$(this).parent().next('dd').css('width', 'auto');
			
			
		} else {
			cl.addClass('expanded').removeClass('expandable');
			 //.parents('dt').next('dd'); //.css('width', cl.parent().width() + 'px');
			//$(this).parent().next('dd').css('width', cl.parent().width() + 'px').show();
			
			
			//cl.addClass('expanded').removeClass('expandable');
			var src = cl.attr("src").replace("t=1", "mode=view");
			cl.attr("src", src);
			
		}
		
		cl.load(function() {
			if($(this).attr('class') == 'expanded') {
				
				$(this).parents('dt').next('dd').css('width', cl.parent().width() + 'px');
				//$(this).parents('dt').next('dd').show().css('width', cl.parent().width() + 'px');
			} else {
				$(this).parents('dt').next('dd').css('width', cl.parent().width() + 'px');
				//$(this).parents('dt').next('dd').hide();
				//$(this).parents('dt').next('dd').css('width', 'auto');
			}
		});
		
		
		//$(this).addClass('expanded').removeClass('expandable');
		//alert($(this).attr('class'));

	});
	
	
	/*
	$('dl.thumbnail').find('dt').find('a').find('.expanded').click(function() {
		var src = $(this).attr("src").replace("mode=view", "t=1");
		$(this).attr("src", src);
		//$(this).addClass('expandable').removeClass('expanded');

	});
	*/
	// Lightbox?
	//$('a[@rel*=lightbox]').lightBox();
	$('a.lightbox').lightBox({
			imageLoading:			t_imageset_path + '/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			t_imageset_path + '/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			t_imageset_path + '/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			t_imageset_path + '/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				t_imageset_path + '/lightbox/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)		
	});
	
	$('a.lightbox2').lightBox({
		imageLoading:			t_imageset_path + '/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			t_imageset_path + '/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			t_imageset_path + '/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			t_imageset_path + '/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				t_imageset_path + '/lightbox/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)		
	});
});




