﻿$(document).ready(function () {
	$('.textureList div').click(
		function () {
			var p = $(this).parents('table.itemtbl');
			var gi = p.find('.glryImg');
			var ns = this.id.split('_')[1].toLowerCase();
			var s = gi.attr('src');
			gi.attr('src', s.substring(0, s.lastIndexOf("/")) + "/" + ns + ".jpg");
			var gs = p.find('.sole');
			if (gs.length > 0) {
				if ($(this).hasClass('noSole')) {
					gs.hide();
				}
				else {
					var t = gs.attr('src');
					gs.attr('src', t.substring(0, t.lastIndexOf("/")) + "/" + ns + "-2.jpg").show();
				}
			}
			p.find('a').not('.textureList a').attr('href', $(this).find('a').attr('href'));
			return false;
		}
	);
	$('img.sole').click(
		function () {
			var p = $(this).parents('table.itemtbl');
			var gi = p.find('.glryImg');
			var gs = p.find('.sole');
			var t = gs.attr('src');
			gs.attr('src', gi.attr('src').replace('220', 'thumb').replace('regular', 'thumb'));
			gi.attr('src', t.replace('thumb', '220'));
			return false;
		}
	);
	$('img.expand').click(
		function () {
			var ch = $(this).parent().height();
			if (ch > 24) {
				$(this).parent().animate({ height: "24px" }, 200);
				$(this).attr('src', $(this).attr('src').replace('-m', '-p'));
			}
			else {
				var h = $(this).parent().get(0).scrollHeight;
				var p = $(this).parents('table.itemtbl');
				p.css('position', 'absolute');
				p.css('z-index', '50');
				p.css('background-color', '#fff');
				$(this).parent().animate({ height: h + 2 + "px" }, 200);
				$(this).attr('src', $(this).attr('src').replace('-p', '-m'));
			}
		}
	);
});
