/*

 Developed By Tim, Choi
 If you have any questions about this Code please Contact Tim
 JAN-7-2010

*/
//	Tim__extendedZoom			Module Value 0/1
//	Tim__animationKind			Module Value 0/1
//	Tim__effectTime				Module Value (eg.200)
//	Tim_ZoomImage__Width		Zoom Size
//	Tim_ZoomImage__Height		Zoom Size
//	Tim_NotZoomImage__Height	Not Zoom
//	Tim_NotZoomImage__Width		Not Zoom



var refreshTagTank = new Array()
var Tim__extendedZoom__Size_Html,Tim__extendedZoom__Size_CSS;
var debuggingMod = 0;	//Debug Mode

function refreshEnlarger(divID)
{
	document.getElementById(divID).innerHTML = refreshTagTank[divID];
}
$(document).ready(function(){
	//###############################################
	var default_Zoom_Window = {width:300,height:300};
	//###############################################
	$('div').livequery(function(){
		var divID = $(this).attr('id');
		var matchSTR = 'tim_imgEnlarger';
		if(divID.match(matchSTR))
		{
			divID = $(this).attr('id');
			var imgSRC = $('div#'+divID+' img').attr('src');
			$('div#'+divID+' a').attr('style','float:left;');
			if(Tim__extendedZoom == 0)
				imgSRC = imgSRC.replace(/[-][0-9a-zA-Z_]+[.]/,"-PRODUCT__MainImage.");
			else
				imgSRC = imgSRC.replace(/[-][0-9a-zA-Z_]+[.]/,"-ZOOM__AllProducts.");

			if(Tim__extendedZoom == 0)
			{
				Tim__extendedZoom__Size_Html = ' width="'+Tim_NotZoomImage__Width+'" height="'+Tim_NotZoomImage__Height+'"';
				Tim__extendedZoom__Size_CSS =  'width:'+Tim_NotZoomImage__Width+'px;height:'+Tim_NotZoomImage__Height+'px;';
			}
			
			zoomDIV__Tag = '<div style="z-index:100000;float:left;position:relative;display:block;"><div class="tim_showDivLargeBox" style="'+Tim__extendedZoom__Size_CSS+'"><img src="'+imgSRC+'" style="display:block;position:absolute;"'+Tim__extendedZoom__Size_Html+'></div></div>';
			if(debuggingMod == 1)
				zoomDIV__Tag += '<div style="float:left;position:relative;clear:both;border:1px solid black;width:30px; height:30px;background-color:black;color:white" id="timDebugging"></div>'


			divID = $(this).attr('id');
			$('#'+divID).append(zoomDIV__Tag);
			refreshTagTank[divID] = document.getElementById(divID).innerHTML;
		}
	});
	$('div img').livequery('mouseover',function(){
		var divID = $(this).parents().filter('div').attr('id');
		var matchSTR = 'tim_imgEnlarger';
		if(divID.match(matchSTR))
		{
			this__DivId = $(this).parents().filter('div').attr('id');
			var timHolder = $('div#'+this__DivId+' a img');
			var imgPosition = timHolder.position();

			if(Tim__extendedZoom == 1)
				$('div#'+this__DivId+' a img').mousemove(function (e) {
					var mousePos_OnImage = {x:e.pageX - imgPosition.left, y: e.pageY - imgPosition.top};
					xPos = -( Tim_ZoomImage__Width / timHolder.width() ) * mousePos_OnImage.x + 150;
					yPos = -( Tim_ZoomImage__Height / timHolder.height() ) * mousePos_OnImage.y +150;
					xPos = xPos.toFixed(0);
					yPos = yPos.toFixed(0);
					//document.getElementById('timDebugging').innerHTML = '['+xPos+']'+'['+yPos+']';
					$('div#'+this__DivId+' div div img').css({left:xPos+'px', top:yPos+'px'});	
				});

			if(Tim__animationKind == 1)
				$('div#'+this__DivId+' div div').show(parseInt(Tim__effectTime),function(){});
			else
				$('div#'+this__DivId+' div div').fadeIn(parseInt(Tim__effectTime),function(){});
		}
	});
	$('div img').livequery('mouseout',function(){
		var divID = $(this).parents().filter('div').attr('id');
		var matchSTR = 'tim_imgEnlarger';
		if(divID.match(matchSTR))
		{	
			this__DivID = $(this).parents().filter('div').attr('id');
			if(Tim__animationKind == 1)
				$('div#'+this__DivID+' div div').hide(parseInt(Tim__effectTime),function(){$('div#'+divID+' img').attr('onmouseout','refreshEnlarger("'+divID+'")');});
			else
				$('div#'+this__DivID+' div div').fadeOut(parseInt(Tim__effectTime),function(){$('div#'+divID+' img').attr('onmouseout','refreshEnlarger("'+divID+'")');});

		}
	});
});