
var modePicInterest = true;

var win = $(window), winW, winH;

var resetWinSize = function() {
	winW = parseInt(win.width());
	winH = parseInt(win.height()) + parseInt(win.scrollTop());
};

var thumbViewer = {
	wrap	: null,
	wrapW	: null,
	wrapH	: null,
	img		: null,
	imgW	: null,
	imgH	: null,
	timer	: null,
	interest	: null,
	//detailsrc	: null,
	prod_desc : null,
	title: null,
	show	: function(e) {
		var data = $(this).parent().parent().parent().parent().parent().parent().parent().children('p');   
		var title		= $(data[0]).html();   
		var prod_desc	= $(data[1]).html();
	 
		var title	= title	? '<b>'+title  + '</b><br>'	: '';
		var prod_desc	= prod_desc	? prod_desc  + ''	: ''; 
	    
		thumbViewer.data.html( title + prod_desc);
		thumbViewer.data1.html('&nbsp;');
 
		if (thumbViewer.timer) clearTimeout(thumbViewer.timer);
		thumbViewer.wrap.hide();
		var large = this.getAttribute('longdesc');
 		if (!large) return;
		var img = large.split('|');
		 
		 
		thumbViewer.imgW = parseInt(img[1]);
		thumbViewer.imgH = parseInt(img[2]);
		thumbViewer.img.attr({ width:thumbViewer.imgW, height:thumbViewer.imgH, src:img[0] }); 
		 thumbViewer.data.css({ width:thumbViewer.imgW });
	 
		thumbViewer.wrap.css(thumbViewer.getPos(e));
		thumbViewer.timer = setTimeout("thumbViewer.wrap.fadeIn()", 500);
	},
	hide	: function(e) {
		thumbViewer.wrap.fadeOut();
		if (thumbViewer.timer) clearTimeout(thumbViewer.timer);
	},
	move	: function(e) {
		thumbViewer.wrap.css(thumbViewer.getPos(e));
	},
	getPos	: function(e) {
		var w = e.pageX,
			h = e.pageY;
	
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		if ((w + thumbViewer.imgW + thumbViewer.wrapW) > winW) w -= thumbViewer.imgW + thumbViewer.wrapW;
		if ((h + thumbViewer.imgH + thumbViewer.wrapH) > winH) h = winH - thumbViewer.imgH - thumbViewer.wrapH - 50  ;
		 
		return { top:h, left:w };
	}
};

$(function() {
	var thumb_list = $('img.thumb');

	if (thumb_list.size()) {
		win.resize(resetWinSize).scroll(resetWinSize);
		resetWinSize();
 
		thumbViewer.wrap = $(document.createElement('div'))
							.attr('id', 'thumbViewerWrap')
							.css({ position:'absolute',zIndex:100, top:0, left:0, margin:10, padding:10, border:'1px solid #FEEACF', background:'#fff' })
							.hide().appendTo('body');

		thumbViewer.img = $(document.createElement('img'))
							.attr({ id:'thumbViewerImage', src:'/images/space.gif' })
							.css({ display:'block', zIndex:100,margin:0, padding:0, border:'none' })
							.appendTo(thumbViewer.wrap);
		thumbViewer.data1 = $(document.createElement('div'))
							.attr('id1', 'thumbViewerData1')
							.css({ zIndex:100, background:'#fff' })
							.appendTo(thumbViewer.wrap);
		thumbViewer.data = $(document.createElement('div'))
		 					.attr('id', 'thumbViewerData')
		 					.css({ zIndex:100,  border:'1px solid #fff', background:'#fff',  fontSize:12, color:'#666'  })
		 					.appendTo(thumbViewer.wrap); 
		thumbViewer.wrapW   = parseInt(thumbViewer.wrap.css('marginLeft'))  + parseInt(thumbViewer.wrap.css('marginRight'))
							+ parseInt(thumbViewer.wrap.css('paddingLeft')) + parseInt(thumbViewer.wrap.css('paddingRight'))
							+ parseInt(thumbViewer.img.css('marginLeft'))   + parseInt(thumbViewer.img.css('marginRight'))
							+ parseInt(thumbViewer.img.css('paddingLeft'))  + parseInt(thumbViewer.img.css('paddingRight'));

		thumbViewer.wrapH   = parseInt(thumbViewer.wrap.css('marginTop'))  + parseInt(thumbViewer.wrap.css('marginBottom'))
							+ parseInt(thumbViewer.wrap.css('paddingTop')) + parseInt(thumbViewer.wrap.css('paddingBottom'))
							+ parseInt(thumbViewer.img.css('marginTop'))   + parseInt(thumbViewer.img.css('marginBottom'))
							+ parseInt(thumbViewer.img.css('paddingTop'))  + parseInt(thumbViewer.img.css('paddingBottom'))  ;

		thumb_list.mouseover(thumbViewer.show).mouseout(thumbViewer.hide).mousemove(thumbViewer.move);

		 
	}

});

