var mySizeZoom = 2;


$(function() {
	startIndexMenu();	
	startZoomImg();
});

function startIndexMenu() {
	$('.indexCatalog a:has(img)').each(function() {
		$(this)
			.bind('mouseover',function() {
				//$('img',this)[0].attr('src','img/'+$(this).attr("rel")+'on.jpg');	
				if ($('img',this).size()) $($('img',this)[0]).attr('src','img/'+$(this).attr("rel")+'_on.jpg');	
			})	
			.bind('mouseout',function() {
				if ($('img',this).size()) $($('img',this)[0]).attr('src','img/'+$(this).attr("rel")+'.jpg');	
			});
	});
}


function startZoomImg() {
	$('body').bind('mouseover',function(event) {
		//alert("OK");
		removeBigZoom(event.target);
		if ($(event.target).attr('class') == 'zoom') doZoom(event.target);

	});
}

function removeBigZoom(myObj) {
	if (!$('.zoomPhoto').size()) return;
	var myOb = ($(myObj).attr('class') == 'zoomPhoto') ?  myObj : false;
	var	mySize = mySize2 = false;
	$('.zoomPhoto').each(function() {			
		if(this && this.parentNode && this !== myOb) {
			mySize = $(this).attr("rel").split('=');
			mySize2 = new Array($(this).width(),$(this).height());
			$(this)
				.animate({
					width: mySize[0],
					height:  mySize[1],
					top:  $(this).offset().top + ((mySize2[1] - mySize[1])/2),
					left:  $(this).offset().left + ((mySize2[0] - mySize[0])/2)
				},
				300,
				function() {
					$(this).remove();	
				});	
		}
	});
}

function doZoom(myObj) {
	var myNewPic = myObj.cloneNode(false);
	if (!myNewPic) return;	
	
	$(myNewPic)
		.css({	'margin' : 0,
				'position' : 'absolute'	,
				'top' : $(myObj).offset().top,
				'left' : $(myObj).offset().left,
				'cursor' : 'pointer',
				'zIndex': 1000000
			})
		.attr('class','')
		.attr('class','zoomPhoto')
		.attr('rel',$(myObj).width()+'='+$(myObj).height())		
		.bind('click',function() {
			if ( $(myObj.parentNode).attr('href')) location.href = $(myObj.parentNode).attr('href');	
		});
	document.body.appendChild(myNewPic);
	$(myNewPic)
		.animate({
			width: parseFloat($(myObj).width()*mySizeZoom),
			height: parseFloat($(myObj).height()*mySizeZoom),
			left :  parseFloat($(myNewPic).offset().left - (($(myObj).width()*mySizeZoom - $(myObj).width()) /2)),
			top :  parseFloat($(myNewPic).offset().top - (($(myObj).height()*mySizeZoom - $(myObj).height()) /2))
		},		
		300,
		function() {
		
		});	
}


