﻿function thumbView(_obj, _isstatic, _xPad, _yPad, _viewerclass, _usemag, _magurl, _magwidth, _magheight){	
	var obj = (_obj != "" && _obj != null) ? $("a." + _obj) : $("a.preview");var viewerclass = (_viewerclass != "" && _viewerclass != null) ? _viewerclass : "PreViewer";var isstatic = (_isstatic != "" && _isstatic != null) ? _isstatic : "true";var xPad = (_xPad != "" && _xPad != null) ? _xPad : 5;var yPad = (_yPad != "" && _yPad != null) ? _yPad : 5;var xPosi; var yPosi;var parenttag = "p";var childtag = "span";var targetelement =  parenttag + "." + viewerclass;var magurl = (_magurl != "" && _magurl != null) ? _magurl : "magnify.png";var magwidth = (_magwidth != "" && _magwidth != null) ? _magwidth : 15;var magheight = (_magheight != "" && _magheight != null) ? _magheight : 15;var utililty = "off";
	function addMagnify(obj,magurl,magwidth,magheight) {var img = $(obj).find("img");var magposy = 1;var magposx = 1;var offset = img.offset();	 $(obj).append("<div style='width:" + img.width() + "px;top:" + offset.top + "px;margin-top:" + (- magwidth - magposx) + "px;'><img src='" + magurl + "' style='margin-left:" + (img.width() - magwidth - magposx ) + "px;width:" + magwidth + "px;height:" + magheight + "px;' alt='" + img.width() + "' /></div>");}
	function autoPosi(e, obj, viewerwidth, viewerheight, coord) {if (isstatic == "true") {var img = $(obj).find("img");var offset = img.offset();var side;var xPosi_r;var xPosi_l;var childheight = $(obj).find(childtag).height();var timg = $(parenttag + "." + viewerclass).find("img");if(coord == "x") {if ($(window).width() >= (offset.left + viewerwidth + img.width() + xPad)){xPosi = (offset.left + img.width() + xPad);side = "right";xPosi_r = xPosi;}else {xPosi = (offset.left - viewerwidth - xPad);side = "left";xPosi_l = xPosi;} if(xPosi <= 0){otherw = (offset.left + img.width() + xPad);var avrspace = $(window).width() - otherw;timg.removeAttr('height');$(parenttag + "." + viewerclass).find("img").attr('width', avrspace - 40);xPosi = (offset.left + img.width() + xPad);}return xPosi;} else {var xtraspace = 80;var toffset = $(targetelement).offset();var telementtop = toffset.top - $(document).scrollTop();var telementtotalheight = telementtop + viewerheight + childheight + xtraspace;var dovtowindowbottom = $(document).scrollTop() + $(window).height();var defaultyPosi = offset.top - (viewerheight / 2);if ($(window).height() <= (telementtotalheight)){yPosi = dovtowindowbottom - (viewerheight + childheight + xtraspace);} else if (defaultyPosi <= ($(document).scrollTop())) {yPosi = $(document).scrollTop() + 30;}else {yPosi = defaultyPosi;}return yPosi;}} else {if ($(window).width() >= (e.pageX + viewerwidth + img.width() + xPad)){xPosi = (e.pageX + xPad);}else {xPosi = (e.pageX - viewerwidth - xPad);} if ($(window).height() >= (e.pageY + viewerheight + yPad)){yPosi = (e.pageY - yPad);}else {yPosi = (e.pageY - viewerheight);}if(coord == "x") {return xPosi;} else {return yPosi;}}    }if (_usemag == "on" && _usemag != null){obj.each(function(){addMagnify(this,magurl,magwidth,magheight);});}
    obj.hover(function(e){this.t = this.title;this.title = "";	var c = (this.t != "") ? "" + this.t : "";$("body").append("<" + parenttag + " class='" + viewerclass + "'><img src='"+ this.href +"' alt='" + c + "' /><" + childtag + ">" + "</" + childtag + "></" + parenttag + ">");var viewerwidth = $(targetelement + " img").width() + 10;var viewerheight = $(targetelement + " img").height() + 10;$(targetelement + " " + childtag).css("width", $(targetelement + " img").width() + "px").css("display", "block").append(c);$(targetelement).css("top",autoPosi(e, this, viewerwidth, viewerheight, "y") + "px").css("left",autoPosi(e, this, viewerwidth, viewerheight, "x")  + "px").fadeIn(300);},function(){this.title = this.t;$(targetelement).remove();if (utililty == "on"){$("#util").remove();}});obj.mousemove(function(e){var viewerwidth = $(targetelement + " img").width() + 10;var viewerheight = $(targetelement + " img").height() + 10;$(targetelement + " " + childtag).css("width", $(targetelement + " img").width() + "px");$(targetelement).css("top",autoPosi(e, this, viewerwidth, viewerheight, "y") + "px").css("left",autoPosi(e, this, viewerwidth, viewerheight, "x") + "px");
    if (utililty == "on"){var img = $(this).find("img");var offset = img.offset();var childheight = $(targetelement).find(childtag).height();var toffset = $(targetelement).offset();var calculation = offset.left + viewerwidth + img.width() + xPad;var telementtop = toffset.top - $(document).scrollTop();var telementtotalheight = telementtop + viewerheight + childheight + 30;var dovtowindowbottom = $(document).scrollTop() + $(window).height(); var yPosi = dovtowindowbottom - (viewerheight + childheight + 100);if ($(window).width() >= (calculation)){side = "right";}else {side = "left";} xPosi1 = (offset.left + img.width() + xPad);xPosi2 = (offset.left - viewerwidth - xPad);$("#util").remove();$(this).append("<div id='util' style='position:absolute;top:" + (e.pageY - 200) + "px;left:" + (e.pageX - 250) + "px;padding:10px;z-index:10000;background:#eeffff;color:#000000;'>" +"window width \t" + $(window).width() + "<br />window height \t" + $(window).height() + "<br /><br />\nyPosi l \t" + yPosi +"<br /><br />objectoffset" + offset.top +"<br /><br />toffset" + toffset.top +"<br /><br />viewerheight " + viewerheight +"<br />childheight " + childheight +"<br />documents scrolltop " +  $(document).scrollTop() + "<br /><br />telementtop " + telementtop + "<br />telementtotalheight " + telementtotalheight + "<br />dovtowindowbottom " + dovtowindowbottom +"</div>");}});};function eUtil(arr) {$.each(obj, function(key, val) {});};