
function timg(ID,call){this.img=jQuery('#'+ID);var img=this.img;this.param=new Object();this.param.width=new Number;this.param.height=new Number;if(call===false){}else{img.wrap('<div></div>');img.parent().css({'position':'relative','padding':'0px','margin':'0px'});}
img.css({'margin':'0px','padding':'0px'});var height=parseInt(jQuery(img)[0].height,10);var width=parseInt(jQuery(img)[0].width,10);if(height===0){height=parseInt(jQuery(img).css('height'),10);}
if(width===0){width=parseInt(jQuery(img).css('width'),10);}
this.param.height=height;this.param.width=width;}
function itag(){this.guid=new String;this.pos=new Object();this.pos.X=new Number;this.pos.Y=new Number;this.size=new Object();this.size.X=new Number;this.size.Y=new Number;this.text=new String;this.cssClass=new String;this.tooltipClass=new String;this.imgfade=new Object();this.imgfade.enabled=new Boolean;this.imgfade.enabled=false;this.imgfade.color=new String;this.imgfade.color='white';this.imgfade.opacity=new Number;this.imgfade.opacity=0.5;this.imgfade.divs=new Array();this.imgfade.jQuerydivs=jQuery([]);}
timg.prototype.GetGuid=function(){var fourChars=function(){return(((1+Math.random())*0x10000)|0).toString(16).substring(1).toUpperCase();}
return(fourChars()+fourChars()+"-"+fourChars()+"-"+fourChars()
+"-"+fourChars()+"-"+fourChars()+fourChars()+fourChars());}
timg.prototype.addTag=function(tag){var that=this;var img=that.img;tag.guid=that.GetGuid();img.after('<li id="'+tag.guid+'"></li>');var li=jQuery('#'+tag.guid);var cssStyle={'top':tag.pos.Y+'px','left':tag.pos.X+'px','height':tag.size.Y+'px','width':tag.size.X+'px','position':'absolute','display':'block','z-index':199,'background-image':'url("files/bgrep.gif")','padding':'0px','margin':'0px'}
li.css(cssStyle);if(tag.text!=''){var tempId=that.GetGuid();jQuery("body").append("<div id='"+tempId+"'><p>"+tag.text
+"</p></div>");var my_tooltip=jQuery("#"+tempId);var tooltipStyle={'position':'absolute','z-index':'199','left':'-9999px','background-color':'#dedede','padding':'5px','border':'1px solid #fff'}
my_tooltip.css(tooltipStyle);if(tag.tooltipClass){my_tooltip.addClass(tag.tooltipClass);}}
if(tag.cssClass){li.addClass(tag.cssClass);}
if(tag.imgfade.enabled){var commonStyle={'position':'absolute','display':'block','z-index':199,'background-color':tag.imgfade.color,'opacity':0}
var firstdiv=that.GetGuid();img.after('<div id="'+firstdiv+'"></div>');var jQueryfirstdiv=jQuery('#'+firstdiv);var firststyle={'top':0,'left':0,'height':that.param.height+'px','width':tag.pos.X+'px'}
jQueryfirstdiv.css(firststyle).css(commonStyle);tag.imgfade.divs[0]=jQueryfirstdiv[0];var seconddiv=that.GetGuid();img.after('<div id="'+seconddiv+'"></div>');var jQueryseconddiv=jQuery('#'+seconddiv);var secondstyle={'top':0,'left':tag.pos.X+'px','height':tag.pos.Y+'px','width':tag.size.X+'px'}
jQueryseconddiv.css(secondstyle).css(commonStyle);tag.imgfade.divs[1]=jQueryseconddiv[0];var thirddiv=that.GetGuid();img.after('<div id="'+thirddiv+'"></div>');var jQuerythirddiv=jQuery('#'+thirddiv);var thirdstyle={'top':(tag.pos.Y+tag.size.Y)+'px','left':tag.pos.X+'px','height':(that.param.height-(tag.pos.Y+tag.size.Y))+'px','width':tag.size.X+'px'}
jQuerythirddiv.css(thirdstyle).css(commonStyle);tag.imgfade.divs[2]=jQuerythirddiv[0];var fourthdiv=that.GetGuid();img.after('<div id="'+fourthdiv+'"></div>');var jQueryfourthdiv=jQuery('#'+fourthdiv);var fourthstyle={'top':0,'left':(tag.pos.X+tag.size.X)+'px','height':that.param.height+'px','width':(that.param.width-(tag.pos.X+tag.size.X))+'px'}
jQueryfourthdiv.css(fourthstyle).css(commonStyle);tag.imgfade.divs[3]=jQueryfourthdiv[0];tag.imgfade.jQuerydivs=jQuery(tag.imgfade.divs);}
li.mouseover(function(){if(my_tooltip){my_tooltip.css({opacity:0.8,display:"none"}).fadeIn(400);}
if(tag.imgfade.enabled){tag.imgfade.jQuerydivs.animate({opacity:tag.imgfade.opacity});}}).mousemove(function(kmouse){if(my_tooltip){my_tooltip.css({left:kmouse.pageX+15,top:kmouse.pageY+15});}}).mouseleave(function(kmouse){if(my_tooltip){my_tooltip.fadeOut(400);}
if(tag.imgfade.enabled){tag.imgfade.jQuerydivs.animate({opacity:0});}});}
timg.prototype.loadTags=function(url){var that=this;$.ajaxSetup({cache:false});$.getJSON(url,function(json){if(json){loadtags(json);}});function loadtags(json){if(json.file==='imgtag-json'){for(tag in json.tags){infotag=json.tags[tag];var newtag=new itag();newtag.pos.X=infotag.posX;newtag.pos.Y=infotag.posY
newtag.size.X=infotag.sizeX;newtag.size.Y=infotag.sizeY;newtag.text=infotag.text;newtag.cssClass=infotag.cssClass;newtag.tooltipClass=infotag.tooltipClass;if(infotag.imgfade.enabled===true){newtag.imgfade.enabled=true;newtag.imgfade.color=infotag.imgfade.color;newtag.imgfade.opacity=infotag.imgfade.opacity;}
if(infotag.linktag.element){newtag.linkTag(infotag.linktag.element,infotag.linktag.cssClass);}
that.addTag(newtag);}}else{}}}
itag.prototype.removeTag=function(){console.info(this.guid);}
itag.prototype.linkTag=function(link,style){var that=this;jQuery(link).live('mouseover mouseout',function(event){if(event.type==='mouseover'){jQuery('#'+that.guid).addClass(style);}else{jQuery('#'+that.guid).removeClass(style);}});}
