var AdIm=window.AdIm||{};var AdImListingLayer=AdIm.AdImListingLayer=Y.extend(Y.ListingLayer,function(a){a=a||{};Y.ListingLayer.apply(this,["IM",a]);this.source=a.source||"";this.$=Y.useJQuery();this.url="http://map.yahooapis.jp/ab/overturequery_im_flashapi";this.imUrl="http://rd.yahoo.co.jp/bzc/sds/82289/evt=82289/*http://business.yahoo.co.jp/int/";this.targetWindow="__vc_window_target__";this.logurl="http://map.yahooapis.jp/OpenLocalPlatform/V1/jsapi/ads/notice";this.logparam={adt:0,lmv:0};this.log;this.position=a.position||null;this.firstDisplay=true;this.ssid=a.ssid||null;this.maxCount=a.maxCount||null});AdIm.AdImListingLayer.prototype.setSource=function(a){this.source=a};AdIm.AdImListingLayer.prototype.getApiRequest=function(b,a){var d=this.$.extend(true,{},a);var c=this.map.getCenter();d.pid=this.source;d.lat=c.lat();d.lon=c.lng();d.o="json";d.maxCount=this.checkPosition()?parseInt(this.listing.container.height()/130):1;if(this.maxCount){d.maxCount=this.maxCount}if(d.bbox){d.bbox=""}return d};AdIm.AdImListingLayer.prototype.errorResponse=function(){this.drawYDFToList(new Y.YDF(new Object()))};AdIm.AdImListingLayer.prototype.drawYDFToList=function(a){if(a.result.count<=0&&!this.firstDisplay){return}this.firstDisplay=false;this.__super__.drawYDFToList.apply(this,arguments)};AdIm.AdImListingLayer.prototype.drawYDFToMap=function(a){};AdIm.AdImListingLayer.prototype.createResultHtml=function(e,d,a){var b=this.$('<div class="yolp-pos-map-ss"></div>');b.append(this.createHeaderHtml(e,d,a));b.append(this.createHeaderAdHtml(e,d,a));b.append(this.createListHtml(e,d,a));b.append(this.createFooterAdHtml(e,d,a));b.append(this.createFooterHtml(e,d,a));var c=e.result.count||0;if(c>0){this.logparam.adt++}return b};AdIm.AdImListingLayer.prototype.createHeaderHtml=function(g){var h=this;var d=this.$('<div class="yolp-list-header"></div>');this.sstxt=this.$('<p class="sstxt"></p>');var c=this.imUrl;if(!this.checkPosition()&&g.result.count>0){var f=this.createItemHtml(0,g.features[0]);var e=this.listing.container.width()-23-100;f.css({position:"absolute",top:"0px",left:"23px",width:e+"px"});this.sstxt.append(f);this.sstxt.mouseover(function(a){h.sstxt.css({"background-color":"#99CBFF",cursor:"pointer","background-position":"5px -81px"});h.$("a:first-child",f).css("color","white");h.logparam.lmv++});this.sstxt.mouseout(function(a){h.sstxt.css({"background-color":"",cursor:"","background-position":"5px 6px"});h.$("a:first-child",f).css("color","")});c=g.features[0].property.Link}var b=this.$('<a href="javascript:void(0);" class="ssttl">インタレストマッチ</a>');b.click(function(a){window.open(h.imUrl,h.targetWindow);a.stopPropagation()});this.sstxt.append(b);this.sstxt.click(function(a){window.open(c,h.targetWindow);a.stopPropagation()});d.append(this.sstxt);return d};AdIm.AdImListingLayer.prototype.createListHtml=function(d){if(!this.checkPosition()){return}var b=this.$('<div class="yolp-list-items"></div>');for(var a=0;a<d.result.count;a++){var c=d.features[a];b.append(this.createItemHtml(a,c))}b.append(this.$("<br>"));return b};AdIm.AdImListingLayer.prototype.createItemHtml=function(a,d){if(!d){return""}if(!d.name){return""}var f=this;var b=this.$("<div></div>");var c=Y.Util.stripScript(d.property.ListDescription);if(d.title.length>15){d.title=d.title.substr(0,15)+"..."}if(c.length>33){c=c.substr(0,33)+"..."}var e=this.$('<a href="javascript:void(0);" class="title">'+d.title+"</a>");e.css("margin","0px");b.append(e);if(this.checkPosition()){b.append(this.$("<br>"));b.css("padding","4px")}else{b.append("&nbsp;&nbsp;")}b.append(c);b.click(function(g){window.open(d.property.Link,f.targetWindow);g.stopPropagation();f.sendLog()});b.hover(function(){b.css({"background-color":"#99CBFF",cursor:"pointer"});e.css("color","white");f.sstxt.css("background-position","5px -81px");f.logparam.lmv++},function(){b.css({"background-color":"",cursor:""});e.css("color","");f.sstxt.css("background-position","5px 6px")});return b};AdIm.AdImListingLayer.prototype.checkPosition=function(){if(this.position==AdImPlugin.HORIZONTAL){return false}return true};AdIm.AdImListingLayer.prototype.sendLog=function(){var b=this.map.getCenter();var a=this.map.getZoom();this.log=new Image();this.log.src=this.logurl+"?ssid="+this.ssid+"&plugin=im&c="+b+"&z="+a+"&adt="+this.logparam.adt+"&lmv="+this.logparam.lmv+"&t="+new Date().getTime();this.logparam.adt=0;this.logparam.lmv=0};var AdImPlugin=Y.extend(Y.Plugin,function(d,b,a,c){c=c||{};this.source=d;this.container=b;this.listing=null;this.imLayer=null;this.$=Y.useJQuery();this.position=a||AdImPlugin.VERTICAL;this.css;this.ssid=ImSession.get();this.maxCount=c.maxCount||null});AdImPlugin.prototype.load=function(b){this.map=b;var c=this.map.getPlugin("YahooMapLayer");if(c&&c.setEnableVendorChange){c.setEnableVendorChange(false)}if(b.isLoaded()){this.initializeLayer()}else{var a=b.bind("load",function(){this.initializeLayer();b.unbind(a)},this)}};AdImPlugin.prototype.getName=function(){return"yolp-im-plugin"};AdImPlugin.prototype.initializeLayer=function(){this.setStyleSheet();if(typeof this.container=="string"){this.container=this.$("#"+this.container)}else{this.container=this.$(this.container)}this.container.css({overflow:"hidden","background-color":"#ECF5FA"});this.listing=new Y.Listing(this.container);var a=this.map.getPlugin("yolp-vc-plugin");if(a){this.ssid=a.getSessionId()}this.imLayer=new AdIm.AdImListingLayer({source:this.source,position:this.position,ssid:this.ssid,maxCount:this.maxCount});this.map.addLayer(this.imLayer);this.listing.addLayer(this.imLayer);this.imLayer.sendLog();this.imLayer.drawYDFToList(new Y.YDF(new Object()));var b=this;this.imLayer.setAutoUpdate(true,null,null,null,function(){b.imLayer.errorResponse()});this.imLayer.execute()};AdImPlugin.prototype.unload=function(){this.container.css({overflow:"","background-color":""});if(this.css){this.css.remove()}this.listing.removeLayer(this.imLayer);this.map.removeLayer(this.imLayer);this.listing.empty();this.container.empty()};AdImPlugin.prototype.getSessionId=function(){return this.imLayer.ssid};AdImPlugin.prototype.bind=function(a,b){return function(){a.apply(b,arguments)}};AdImPlugin.prototype.setStyleSheet=function(){var d="http://i.yimg.jp/images/map/api/yolp/vc/css/yolp_pr.css";if(document.compatMode=="BackCompat"){d="http://i.yimg.jp/images/map/api/yolp/vc/css/yolp_pr_nodoctype.css"}var b=this.$("link",document);for(var c=0;c<b.length;c++){if(b[c].href==d){d="";break}}if(d){this.css=this.$('<link rel="stylesheet" href="'+d+'" type="text/css" />');var a=this.$("head",document);a.append(this.css)}};AdImPlugin.VERTICAL=1;AdImPlugin.HORIZONTAL=2;AdImPlugin.WIDTH=128;AdImPlugin.HEIGHT=24;var ImSession=function(){this.create=function(){var d=new Date();var a=this.randomString(10);var b=navigator.userAgent+String(d.getTime())+a;var c=this.MD5_hexhash(b);return c};this.randomString=function(e){e=e?e:10;var c=new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9");var d=new Array();for(var b=0;b<e;b++){var a=this.rand(0,c.length);d[d.length]=c[a]}return d.join("")};this.rand=function(c,a){var b=c+Math.floor(Math.random()*a+1);return b};this.MD5_T=new Array(0,3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745);this.MD5_round1=new Array(new Array(0,7,1),new Array(1,12,2),new Array(2,17,3),new Array(3,22,4),new Array(4,7,5),new Array(5,12,6),new Array(6,17,7),new Array(7,22,8),new Array(8,7,9),new Array(9,12,10),new Array(10,17,11),new Array(11,22,12),new Array(12,7,13),new Array(13,12,14),new Array(14,17,15),new Array(15,22,16));this.MD5_round2=new Array(new Array(1,5,17),new Array(6,9,18),new Array(11,14,19),new Array(0,20,20),new Array(5,5,21),new Array(10,9,22),new Array(15,14,23),new Array(4,20,24),new Array(9,5,25),new Array(14,9,26),new Array(3,14,27),new Array(8,20,28),new Array(13,5,29),new Array(2,9,30),new Array(7,14,31),new Array(12,20,32));this.MD5_round3=new Array(new Array(5,4,33),new Array(8,11,34),new Array(11,16,35),new Array(14,23,36),new Array(1,4,37),new Array(4,11,38),new Array(7,16,39),new Array(10,23,40),new Array(13,4,41),new Array(0,11,42),new Array(3,16,43),new Array(6,23,44),new Array(9,4,45),new Array(12,11,46),new Array(15,16,47),new Array(2,23,48));this.MD5_round4=new Array(new Array(0,6,49),new Array(7,10,50),new Array(14,15,51),new Array(5,21,52),new Array(12,6,53),new Array(3,10,54),new Array(10,15,55),new Array(1,21,56),new Array(8,6,57),new Array(15,10,58),new Array(6,15,59),new Array(13,21,60),new Array(4,6,61),new Array(11,10,62),new Array(2,15,63),new Array(9,21,64));this.MD5_F=function(a,c,b){return(a&c)|(~a&b)};this.MD5_G=function(a,c,b){return(a&b)|(c&~b)};this.MD5_H=function(a,c,b){return a^c^b};this.MD5_I=function(a,c,b){return c^(a|~b)};this.MD5_round=new Array(new Array(this.MD5_F,this.MD5_round1),new Array(this.MD5_G,this.MD5_round2),new Array(this.MD5_H,this.MD5_round3),new Array(this.MD5_I,this.MD5_round4));this.MD5_pack=function(a){return String.fromCharCode(a&255)+String.fromCharCode((a>>>8)&255)+String.fromCharCode((a>>>16)&255)+String.fromCharCode((a>>>24)&255)};this.MD5_unpack=function(a){return a.charCodeAt(0)|(a.charCodeAt(1)<<8)|(a.charCodeAt(2)<<16)|(a.charCodeAt(3)<<24)};this.MD5_number=function(a){while(a<0){a+=4294967296}while(a>4294967295){a-=4294967296}return a};this.MD5_apply_round=function(n,w,i,h,e){var m,l,k,j;var g,v,p;var q,o;m=h[0];l=h[1];k=h[2];j=h[3];g=e[0];v=e[1];p=e[2];o=i(w[l],w[k],w[j]);q=w[m]+o+n[g]+this.MD5_T[p];q=this.MD5_number(q);q=((q<<v)|(q>>>(32-v)));q+=w[l];w[m]=this.MD5_number(q)};this.MD5_hash=function(l){var c,q,b,t;var p,o,m,n,a;var h,e,d;var g;b=new Array(1732584193,4023233417,2562383102,271733878);p=l.length;o=p&63;m=(o<56)?(56-o):(120-o);if(m>0){l+="\x80";for(h=0;h<m-1;h++){l+="\x00"}}l+=this.MD5_pack(p*8);l+=this.MD5_pack(0);p+=m+8;c=new Array(0,1,2,3);q=new Array(16);t=new Array(4);for(d=0;d<p;d+=64){for(h=0,e=d;h<16;h++,e+=4){q[h]=l.charCodeAt(e)|(l.charCodeAt(e+1)<<8)|(l.charCodeAt(e+2)<<16)|(l.charCodeAt(e+3)<<24)}for(h=0;h<4;h++){t[h]=b[h]}for(h=0;h<4;h++){n=this.MD5_round[h][0];a=this.MD5_round[h][1];for(e=0;e<16;e++){this.MD5_apply_round(q,t,n,c,a[e]);g=c[0];c[0]=c[3];c[3]=c[2];c[2]=c[1];c[1]=g}}for(h=0;h<4;h++){b[h]+=t[h];b[h]=this.MD5_number(b[h])}}return this.MD5_pack(b[0])+this.MD5_pack(b[1])+this.MD5_pack(b[2])+this.MD5_pack(b[3])};this.MD5_hexhash=function(e){var d,b,f;var a;a=this.MD5_hash(e);b="";for(d=0;d<16;d++){f=a.charCodeAt(d);b+="0123456789abcdef".charAt((f>>4)&15);b+="0123456789abcdef".charAt(f&15)}return b};this.onload=function(){};this.onload()};ImSession.value=new String("");ImSession.get=function(){if(ImSession.value.length==0){var a=new ImSession();ImSession.value=a.create()}return ImSession.value};
