$(document).ready(function() {
	var k = 0.20; // процент увеличения картинки
	var k_left = 12; // коэфф. сдвига влево
	
	var img_width = new Array;
	var img_height = new Array;
	
	// исходные размеры
	$("#magnify img, #magnify span:first-child").each(function(i) {
		img_width[i] = $(this).width();
		img_height[i] = $(this).height();
	});
	
	
	if (cmsBrowser.ie6) {
		$("#magnify span").bind("mouseover", function(e) {
		
			// ---- position ------ 
			$("#magnify td").each(function(i){
				$(this).css("position", "relative");
			});
			$(this).css("position", "absolute");
			// ----------
		
			var src = get_image_src($(this).attr('style'));

			// определяем индекс (номер п/п) картинки
			var index = 0;
			$("#magnify span").each(function(i){
				var current_src = get_image_src($(this).attr('style'));
				if (current_src == src) index = i;
				$(this).parents("td").eq(0).css("z-index", "0"); 
			});
			
			$(this).parents("td").eq(0).css("z-index", "999")	
					
			var w = img_width[index];
			var h = img_height[index];
			
			var w_new = Math.round(w + (w * k)); 
			var h_new = Math.round(h + (h * k)); 
	
			
			$(this).animate({
					width: w_new,
					height: h_new,			
					left: "-=" + (Math.round(img_width[index] / k_left)) + "px"
				}, 200, "swing", 
				function() {
					$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + banners_big[index] + "', sizingMethod='scale')");
			});
		});
		
		// ----------------------------------------------------------------- //
		$("#magnify span").bind("mouseout", function(e) {
			var src = get_image_src($(this).attr('style'));
			
			// определяем индекс картинки
			var index = 0;
			$("#magnify span").each(function(i){
				var current_src = get_image_src($(this).attr('style'));
				if (current_src == src) index = i;
			});
	
			var w_new = img_width[index]; 
			var h_new = img_height[index]; 
			
			$(this).animate({
					width: w_new,
					height: h_new,			
					left: "+=" + (Math.round(img_width[index] / k_left)) + "px"
				}, 200, "swing", 
				function() {
					$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + banners[index] + "', sizingMethod='scale')");
			});
			
		});
		
		// ----------------------------------------------------------------- //
	
	
	} else { // no ie6
	
		$("#magnify img").bind("mouseover", function(e) {
			var src = $(this).attr('src');
			
			// определяем индекс (номер п/п) картинки
			var index = 0;
			var myregexp = /^b([0-9]+)$/m;
			if (match = myregexp.exec($(this).parents("div").eq(0).attr("id"))) index = (match[1]);
			
			$("#magnify div").each(function(i){
				$(this).css("z-index", "0");
			});
			$(this).parents("div").eq(0).css("z-index", "999");	
			
			var w = img_width[index];
			var h = img_height[index];
			
			var w_new = Math.round(w + (w * k)); 
			var h_new = Math.round(h + (h * k)); 
	
			$(this).animate({
					width: w_new,
					height: h_new,			
					left: "-=" + (Math.round(w / k_left)) + "px"
				}, 200, "swing", 
				function() {
					$(this).attr("src", banners_big[index]); 
			});
			
		});
		
		// ----------------------------------------------------------------- //
		$("#magnify img").bind("mouseout", function(e) {
			var src = $(this).attr('src');
			
			// определяем индекс картинки в массиве
			var index = 0;
			var myregexp = /^b([0-9]+)$/m;
			if (match = myregexp.exec($(this).parents("div").eq(0).attr("id"))) index = (match[1]);

			var w_new = img_width[index]; 
			var h_new = img_height[index];
			
			
			$(this).animate({
					width: w_new,
					height: h_new,			
					left: "+=" + (Math.round(img_width[index] / k_left)) + "px"
				}, 200, "swing", 
				function() {
					$(this).attr("src", banners[index]); 
			});
			
		});
		
		// ----------------------------------------------------------------- //
	
	} // end no ie6
	
	
});



// ----------------------------------------------------------------- //
function get_image_src(subject) {
	var myregexp = /src=[\'\"]([a-zA-Z0-9.\/_\-]+)[\'\"]/;
	var match = myregexp.exec(subject);
	if (match != null && match.length > 1) {
		return (match[1]);
	} else {
		return false;
	}
}
// ----------------------------------------------------------------- //