/*
 * 
 * Ex: Javascript improves in the speed on IE only.
 * update: 2007-10-11
 * info: http://d.hatena.ne.jp/amachang/20071010/1192012056
 * 
 */

/*@cc_on _d=document;eval('var document=_d')@*/





/*
 * 
 * Ex: Global navigation.
 * update: 2008-10-7
 * info: http://www.jeremymartin.name/projects.php?project=kwicks
 * file [jquery.kwicks.js] changed that container -> jkcontainer (Reason: collide with CSS ID)
 * 
 */

jQuery(function() {
	$('#kwicks').kwicks({duration: 300,max: 200,spacing: 0});
});





/*
 * 
 * Ex: Entry List show/hide control. (index page only)
 * update: 2008-10-7
 * 
 */

jQuery(function() {
	$('#entryList dd').hide();
	$('#entryList dd:first').show();
	$('#entryList dt:first').addClass('selected');
	$('#entryList dt').hover(
		function(){
		$('#entryList dd').hide();
		$('#entryList dt').removeClass('selected');
		$(this).addClass('selected');
		$(this).next().show();
		return false;
	});
});





/*
 * 
 * Ex: jQMinMax automatically adds min/max support to those elements.
 * update: 2008-11-21
 * info: http://davecardwell.co.uk/javascript/jquery/plugins/jquery-minmax/
 * 
 */

jQuery(function() {
	$('#entryList img').minmax();
});





/*
 * 
 * Ex: Style for input, TextArea, select.
 * update: 2009-1-15
 * 
 */

jQuery(function() {
	$('input[type=password], input[type=text]').addClass('jText');

	$('input[type=password], input[type=text], textarea').focus(function() {
		$(this).addClass('jFocus');
	});

	$('input[type=password], input[type=text], textarea').blur(function() {
		if ($(this).find('.jFocus')) {
			$(this).removeClass('jFocus');
		}
	});
/*
	$('select').change(function() {
		$(this).blur();
	});
*/
});





/*
 * 
 * jQuery jFeed.
 * Ex: Append hatena bookmark, from NP_simpleTag's first Tag.
 * update: 2009-1-24
 * info: http://www.hovinne.com/blog/index.php/2007/07/15/132-jfeed-jquery-rss-atom-feed-parser-plugin
 * 
 */

function hatebulist() {
	var onetag = jQuery('#itemTagList a:first').text();
    jQuery.getFeed({
        url: 'http://luvsic.net/jfeed/proxy.php?url=http://b.hatena.ne.jp/t/'+onetag+'?mode=rss',
        success: function(feed) {
        
            jQuery('#hatebuTag').append('<h3>'
            + '<a href="'
            + feed.link
            + '" rel="nofollow">'
            + feed.title
            + '</a>'
            + '</h3>');
            
            var html = '';
            
            for(var i = 0; i < feed.items.length && i < 5; i++) {
            
                var item = feed.items[i];
                
                html += '<li>'
                + '<a href="'
                + item.link
        	    + '" rel="nofollow">'
                + item.title
                + '</a>'
                + '</li>';
                
            	var html2 = '';

            	html2 += '<div class="rayout"><ul>'
                + html
                + '</ul></div>';
            
            }
            
            jQuery('#hatebuTag').append(html2);
			$('#hatebuTag a').click(function() {
				window.open(this.href, '');
				return false;
			});
        }
    });
}





/*
 * 
 * jquery.favicon.js
 * Ex: show the favicon if website has .ico on root directory,
 * update: 2009-1-21
 * info: http://developmentor.lrlab.to/postal/jquery/jquery.favicon.html
 * 
 */

jQuery(function($) {
	$('.commentinfo span a').each(function(i, n) {
		$('<img />')
		.favicon(n.href)
		.insertBefore(n);
	});
}); 





/*
 * Ex: Insert function of change the font-size and width on code area. (see option for NP_GeSHi2.)
 * update: 1/24,2009
 * info: 
 * 
 */

jQuery(function() {

	$('div.codeArea div').prepend('<span class="functext">'
		+ '<ul class="fontChange">'
			+ '<li>small</li>'
			+ '<li class="selectedFunc">normal</li>'
			+ '<li>big</li>'
			+ '</ul>'
		+ '<ul class="widthChange">'
			+ '<li class="selectedFunc">w98%</li>'
			+ '<li>w800px</li>'
			+ '</ul>'
		+ '</span>'
	);

	$('.fontChange li:nth-child(1)').click(function()  {$(this).parent().parent().parent().css('font-size','85%');});
	$('.fontChange li:nth-child(2)').click(function()  {$(this).parent().parent().parent().css('font-size','100%');});
	$('.fontChange li:nth-child(3)').click(function()  {$(this).parent().parent().parent().css('font-size','116%');});
	$('.widthChange li:nth-child(1)').click(function() {$(this).parent().parent().parent().animate({width: '98%'});});
	$('.widthChange li:nth-child(2)').click(function() {$(this).parent().parent().parent().animate({width: '800px'});});

	$('.functext li').click(function() {
		$(this).parent().children().removeClass('selectedFunc');
		$(this).addClass('selectedFunc');
	});

});





/*
 * Ex: allows the user to extend the textarea element/area within the web page whenever they feel.
 * update: 1/21,2009
 * info: http://plugins.jquery.com/project/TextAreaResizer
 * 
 */

jQuery(function() {
	if ($('textarea#nucleus_cf_body').length) {
		$('textarea#nucleus_cf_body:not(.processed)').TextAreaResizer();
	};
});





/*
 * Ex: informs the sendmail done.
 * update: 2009-1-29
 * info: http://2inc.org/js/28.html
 * 
 */

jQuery(function() {
	var mailDone = '#nucleus_mf';

	if(location.pathname.match('/member/')) {
		if(location.href.match(mailDone)) {
			if ($('form .error').length) {
				$('form .error').animate({backgroundColor: 'orange', color: '#fff'},1200);
			} else {
				$('form').css('display','none');
				$('#nucleus_mf').after('<div id="mailDone"><span>送信を完了しました。</span><br />Thank you for your message!</div>');
				$('#mailDone').animate({backgroundColor: '#6DDEFF', color: '#fff'},1200).animate({backgroundColor: '#FFEC35', color: '#666'},1200);
			}
		}
	}
});





/*
 * Ex: Another location link use target _blank. Trucking External link clicking by Google Analytics.
 * update: 2009-2-8
 * info: http://howtohp.com/javascript/external.php
 * info: http://css-tricks.com/track-outgoing-clicks-in-google-analytics-with-jquery/
 * 
 */

jQuery(function(){
	var domains = [document.domain,'luvsic.net'];
	var domain_selector = '',left_str= ':not([href^=http://',left_str_https= ':not([href^=https://',right_str = '])';

	domain_selector = left_str+domains.join(right_str+left_str)+right_str;
	domain_selector+= left_str_https+domains.join(right_str+left_str_https)+right_str;

	$('a[href^=http]'+domain_selector+':not(:has(img))').addClass('external').attr('target', '_blank');

	$('a[href^=http]'+domain_selector).bind('click keypress', function(event) {
		var code=event.charCode || event.keyCode;
		if(!code || (code && code == 13)) {
			if(pageTracker){
				var fixedLink = this.href;
				fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
				fixedLink = '/outgoing/' + fixedLink;
				pageTracker._trackPageview(fixedLink);
			};
		};

	});
});





/*
 * Ex: Trucking the number of file download by Google Analytics.
 * update: 2009-2-8
 * info: http://css-tricks.com/track-outgoing-clicks-in-google-analytics-with-jquery/
 * 
 */

jQuery(function() {

	$('a[rel^=fileDL]').bind('click keypress', function(event) {
		var code=event.charCode || event.keyCode;

		if(!code || (code && code == 13)) {
			if(pageTracker){
				var fixedLink = this.href;
				fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
				fixedLink = '/fileDL/' + fixedLink;
				pageTracker._trackPageview(fixedLink);
			};
		};

	});
});





/*
 * jQuery Fancy Zoom.
 * update: 1/15,2009
 * info: http://www.dfc-e.com/metiers/multimedia/opensource/jquery-fancyzoom/
 * 
 */

jQuery(function() {
	$('.fancyZoom').fancyzoom({
		imgDir      : "http://luvsic.net/skins/bluebird/css/img/fancyzoom/",
		Speed       : 600,
		showoverlay : true,
		overlayColor: "#D1F3FF",
		overlay     : 0.5
	});
});





/*
 * Ex: Smooth Scroll To Page's Top.
 * update: 2009-4-26
 * info: http://d.hatena.ne.jp/dayflower/20081007/1223358033
 * 
 */

jQuery(function () {
	$('#toTop').click(function(){
        $(this).blur();
        $('html,body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });
});




