/* ---------------------------------------------------------------------------------
  SCRIPTED BY 3OT NET
  Copyright 2009 (c) 3OT NET. All Rights Reserved.
  http://www.3ot.net/
----------------------------------------------------------------------------------- */

$(function(){blog.start();});blog={start:function(){this.menu();this.search();this.chkValidity();$('#com-form').submit(function(ev){blog.addComment(ev);});$('#add-comment-button').click(function(ev){blog.addComment(ev);});this.tb();this.tripleovertime();this.topEntryIcon();if($.browser.msie&&$.browser.version.match(/^(6|5)/)){this.ieOnly();}},ieOnly:function(){$('a').focus(function(){if($(this).attr('id').match(/^prev-page|next-page$/)){$(this).css({backgroundPosition:'0 -100px'});var _e=this;setTimeout(function(){$(_e).css({backgroundPosition:'0 -50px'});},100);}
$(this).blur();});},topEntryIcon:function(){if($('#top-contents').length){$('.top-entry-link','#top-contents').hover(function(){$(this).parent().parent().parent().contents('.block-left').contents('a[class="entry-icon"]').css({backgroundPosition:'0 -120px'});},function(){$(this).parent().parent().parent().contents('.block-left').contents('a[class="entry-icon"]').css({backgroundPosition:'0 0'});});$('a[class="entry-icon"]').hover(function(){$(this).css({backgroundPosition:'0 -120px'});},function(){$(this).css({backgroundPosition:'0 0'});});}},tripleovertime:function(){if($('.tripleovertime','#sub').length){var _str=$('.tripleovertime','#sub').html().replace(/^(.+) \[atmark\] (.+)$/,"$1@$2");$('.tripleovertime','#sub').html('<a href="mailto:'+_str+'">'+_str+'</a>');}},search:function(){$('#search').submit(function(ev){ev.preventDefault();blog.doSearch();});$('input[type="text"]','#search').css('color','#aaaaaa').attr('value','ブログ内検索');$('input[type="text"]','#search').focus(function(){if($(this).css('color')=='rgb(170, 170, 170)'||$(this).css('color')=='#aaaaaa'){$(this).attr('value','').css('color','#000000');}}).blur(function(){if(!$(this).attr('value')){$(this).css('color','#aaaaaa').attr('value','ブログ内検索');}});},doSearch:function(){if(!$('input[type="text"]','#search').attr('value')){return false;}else if($('input[type="text"]','#search').css('color')=='rgb(170, 170, 170)'||$('input[type="text"]','#search').css('color')=='#aaaaaa'){return false;}else{if($('#search-result').css('display')!='block'){$('#contents-padding').fadeOut('fast',function(){$(this).before('<div id="search-result"></div>');blog.doSearchSub();});}else{blog.doSearchSub();}}},doSearchSub:function(){$('#search-result').html($('<div id="search-loader">検索中 ...</div>'));blog.httpAjax({phpScript:'/php/search.php',post:{searchStr:$('input[type="text"]','#search').val()},func:function(res){if(res.status=='ok'){$('#search-loader').fadeOut('fast',function(){$('#search-result').html(res.result);});}}});},backButton:function(){$("#search-result").fadeOut('slow').remove();$("#contents-padding").fadeIn('slow');},menu:function(){$('#menu > li > ul').css({opacity:0.95});$('<img src="/images/common/one-pixel-525050.gif" width="1" height="1" style="background:#434343;width:1px;height:1px;position:absolute;top:-1px;left:0;z-index:10;" /><img src="/images/common/one-pixel-525050.gif" width="1" height="1" style="background:#434343;width:1px;height:1px;position:absolute;top:-1px;right:0;z-index:10;" /><img src="/images/common/one-pixel-525050.gif" width="1" height="1" style="background:#434343;width:1px;height:1px;position:absolute;bottom:0;left:0;z-index:10;" /><img src="/images/common/one-pixel-525050.gif" width="1" height="1" style="background:#434343;width:1px;height:1px;position:absolute;bottom:0;right:0;z-index:10;" />').appendTo('#menu');},tb:function(){if($('div[id^="jumbo-"]').length){$('div[id^="jumbo-"]').append('<div id="tb-caption">このエントリのトラックバックurl:</div><div id="tb-val">http://'+location.host+'/ping/'+$('div[id^="jumbo-"]').attr('id').replace(/jumbo-/,'')+'/'+blog.onePixels()+'</div>');}},onePixels:function(){return'<img src="/images/common/one-pixel-ffffff.gif" width="1" height="1" alt="one-px-ffffff-tl" class="one-px-ffffff-tl" /><img src="/images/common/one-pixel-ffffff.gif" width="1" height="1" alt="one-px-ffffff-tr" class="one-px-ffffff-tr" /><img src="/images/common/one-pixel-ffffff.gif" width="1" height="1" alt="one-px-ffffff-bl" class="one-px-ffffff-bl" /><img src="/images/common/one-pixel-ffffff.gif" width="1" height="1" alt="one-px-ffffff-br" class="one-px-ffffff-br" />';},addComment:function(ev){ev.preventDefault();var _valName=$('input[name="name"]','#com-form').val();var _valUrl=$('input[name="url"]','#com-form').val();var _valEmail=$('input[name="email"]','#com-form').val();var _valBody=$('textarea[name="body"]','#com-form').val();var _valEnableCookie=$('input[name="enable-cookie"]','#com-form').attr('checked')?'on':'off';var _chkName=this.validity('name',_valName);var _chkUrl=this.validity('url',_valUrl);var _chkEmail=this.validity('email',_valEmail);var _chkBody=this.validity('body',_valBody);if(_chkName&&_chkUrl&&_chkEmail&&_chkBody){$('#comment-overlay').css({width:$('#comment-form-wrap').width()+20+'px',height:$('#comment-form-wrap').height()+20+'px',opacity:0.5}).append($('<img src="/images/common/comment-form-loader.gif" width="32" height="32" id="form-loader" />').css({top:($('#comment-form-wrap').height()+20-32)/2+'px'})).fadeIn('fast');this.httpAjax({phpScript:'/php/addComment.php',post:{name:_valName,url:_valUrl,email:_valEmail,body:_valBody,enableCookie:_valEnableCookie,entryId:$('input[name="entry-id"]','#com-form').val()},func:function(res){if(res.status=='ok'){$('#form-loader').fadeOut('fast',function(){$(this).remove();$('<div id="thankyou">THANK YOU!</div>').appendTo($('#comment-overlay'));setTimeout(function(){$('#thankyou').fadeOut('fast',function(){$(this).remove();$('#comment-overlay').fadeOut('fast',function(){$(res.dom).css({display:'none'}).appendTo('#comments').slideDown('fast',function(){$('textarea[name="body"]','#com-form').val('');$('.valid','#com-form').empty();$('#recent-comments').replaceWith(res.recentComments);});});});},1000);});}}});}},chkValidity:function(){$('input[type="text"], textarea','#com-form').blur(function(ev){blog.validity($(ev.target).attr('name'),$(this).val());});},validity:function(_name,_val){this.alert=false;if(_name=='name'){if(!_val){this.alert='お名前は必須です！';}else if(_val.length>100){this.alert='長すぎ！100文字以内でお願いします！';}}else if(_name=='email'){if(_val&&_val.length>255){this.alert='長すぎ！255文字以内でお願いします！';}else if(_val&&!_val.match(/^[\x01-\x7F]+@(([-a-z0-9]+\.)*[a-z]+|\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])/)){this.alert='メールアドレスの書式が間違っています！';}}else if(_name=='url'){if(_val&&_val.length>255){this.alert='長すぎ！255文字以内でお願いします！';}else if(_val&&!_val.match(/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)$/)){this.alert='urlの書式が間違っています！';}}else if(_name=='body'){if(!_val){this.alert='コメント本文は必須です！';}else if(_val.length>1000){this.alert='長すぎ！2000文字以内でお願いします！';}}
if(this.alert){this.oops(_name);return false;}else{this.valid(_name);return true;}},oops:function(_name){$('input[name='+_name+'], textarea[name='+_name+']').css({borderColor:'#d61659'});$('#'+_name+'-label').css({backgroundPosition:'0 -42px'});$('span','#'+_name+'-label').css({backgroundPosition:'100% -42px'});$('#'+_name+'-valid').css({top:'0',left:'-165px'}).html('<span class="alert-top"></span><span class="alert-bottom"><span>'+blog.alert+'</span></span>');},valid:function(_name){$('input[name='+_name+'], textarea[name='+_name+']').css({borderColor:'#bbc8d0'});$('#'+_name+'-label').css({backgroundPosition:'0 0'});$('span','#'+_name+'-label').css({backgroundPosition:'100% 0'});$('#'+_name+'-valid').css({top:'-10px',left:'-20px'}).html(this.png('/images/common/valid.png',40,40));},httpAjax:function(obj){$.ajax({url:obj.phpScript,cache:false,type:'POST',dataType:'json',data:obj.post,error:function(XMLHttpRequest,textStatus,errorThrown){alert("ERROR!\n\nXMLHttpRequest: "+XMLHttpRequest+"\ntextStatus: "+textStatus+"\nerrorThrown: "+errorThrown);},success:function(res){obj.func(res);}});},png:function(_png,_w,_h,_chkIe,_id,_style,_attr){var iePngStyle=function(_png){return'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+_png+')';};if($.browser.msie&&$.browser.version.match(/^(6|5)/)){return'<div id="'+_id+'" style="width:'+_w+'px;height:'+_h+'px;'
+iePngStyle(_png)+';'+_style+'"'+_attr+'></div>';}else{return'<img src="'+_png+'" width="'+_w+'" height="'+_h+'" id="'+_id+'" style="'+_style+'"'+_attr+' />';}}};