/* jQuery */
$(function(){

	/* set cookie */
	/*function setCookie(name,value,expires,path,domain,secure){
		if(domain&&domain.match(/^\.?localhost$/))
			domain=null;
		var curCookie=name+"="+escape(value)+
			(expires?"; expires="+expires.toGMTString():"")+
			(path?"; path="+path:"")+
			(domain?"; domain="+domain:"")+
			(secure?"; secure":"");
		document.cookie=curCookie;
	}*/

	/* get cookie */
	/*function getCookie(name){
		var prefix=name+'=';
		var c=document.cookie;
		var cookieStartIndex=c.indexOf(prefix);
		if(cookieStartIndex==-1)
			return '';
		var cookieEndIndex=c.indexOf(";",cookieStartIndex+prefix.length);
		if(cookieEndIndex==-1)
			cookieEndIndex=c.length;
		return unescape(c.substring(cookieStartIndex+prefix.length,cookieEndIndex));
	}*/

	/* set search box value */
	/*var search_box_value=getCookie("search_box_value");
	if(search_box_value!=""){
		setCookie("search_box_value","","","/",".vincent.in",false);
		$('#search_box').val("");
	}else{
		$('#search_box').val("");
	}*/

	/* google search */
	/*$('#search_button').click(function(){
	var scH=parseInt($(document).height()-200)+'px';
	var search_box_value=$('#search_box').val();
	var domains='http://spell.vincent.in/';
	var charset='UTF-8';
	var uri='http://www.google.co.jp/search'+'?q='+search_box_value+'&hl=ja&sitesearch='+domains+'&domains='+domains+'&ie='+charset+'&oe='+charset;

		if($('#search_box').val()!=""){*/
			/* set cookie */
			//setCookie("search_box_value",$('#search_box').val(),"","/",".vincent.in",false);
			//setCookie("search_data",$('#search_data').val(),"","/",".vincent.in",false);
			/* shadowbox open */
			/*Shadowbox.open({
				player:'iframe',
				width:'800px',
				height:scH,
				title:'Site Search -Powered by Google-',
				content:uri
			});
		}else{*/
			/* delete cookie */
			//setCookie("search_box_value","","","/",".vincent.in",false);
			//setCookie("search_data","","","/",".vincent.in",false);
			/*alert("検索キーワードを入力しましょう☆(´∀｀*)ﾉ");
		}
	});*/


	/* spell edit shadowbox open */
	$('[class*=sp:]').click(function(){
		var inf=unescape(this.className.replace(/.*sp:([^ ]+)( .*|$)/,'$1')).split(':');
		var url=['http://mt.vincent.in/mt.cgi','?__mode=view&_type=',inf[2],'&blog_id=',inf[0],'&id=',inf[1]].join('');
		var elem=document.createElement('a');
		$(elem).attr('href',url);
		Shadowbox.open(elem,{
			player:'iframe',
			title:$(this).attr('title')
		});
	});

	/* accordion */
	$('#apple-feeds,#itunes-store').accordion({
		header:'h4',
		autoHeight:false,
		collapsible:true,
		icons:{
			header:'ui-icon-circle-triangle-e',
			headerSelected:'ui-icon-circle-triangle-s'
		}
	});

	/* tab */
	$('#tabs').tabs().find('.ui-tabs-nav').sortable({axis:'x'});

	/* jBreadCrumb */
	$('#breadCrumbTop').jBreadCrumb();

	/* window open */
	$('.entry-content a,.comment-content a,.page-content a,.gdm_title a').not('.amazlet-box a,a[href*=#],a[rel*=shadowbox]').each(function(){
		var owUrl=$(this).attr('href');
		var owTxt=$(this).text();
		//$(this).before('&#9658;&#160;');
		$(this).after('&#160;<a href="'+owUrl+'" class="owimg" title="'+owTxt+'を別ウィンドウで開く"><img src="/images/openwin.gif" alt="別ウィンドウで開く" width="14" height="13" /></a>&#160;');
	});
	$('a.owimg').click(function(){
		window.open(this.href);
		return false;
	});

	/* smooth scroll */
	$('a[href*=#]').not('#tabs ul a[href*=#],#apple-feeds h4 a[href*=#],#itunes-store h4 a[href*=#]').click(function(){
		if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname){
			var target=$(this.hash);
			target=target.length&&target;
			if(target.length){
				var sclpos=0;
				var scldurat=1500;
				var targetOffset=target.offset().top-sclpos;
				$('html,body').animate({scrollTop:targetOffset},{duration:scldurat,easing:"easeOutQuint"});
				return false;
			}
		}
	});

	/* Yahoo! OpenID */
	$('.author a[href*=me\.yahoo\.co\.jp],#recent-comments .author:contains("me\.yahoo\.co\.jp")').each(function(){
		$(this).text('Yahoo! OpenID コメンター');
	});

	/* widget slide toggle */
	$('#beta div > h3').not('#archive-list > h3').each(function(){
	if($(this).next('div,ul')){
			$(this).attr("title","リストのトグル開閉").css('cursor','pointer');
		}
	});
	$('#beta div > h3').not('#archive-list > h3').click(function(){
		$(this).next('div,ul').slideToggle('slow');
	});

	/* featured categories */
	$('#featured > ul').tabs({fx:{opacity:'toggle'}}).tabs('rotate',10000,true);

});
