/* Like@Lunatic
   common & basic script
 * Author: Naoki Sekiguchi
 * LastUpdate: 2010/07/09
 */

(function($) {

$(function() {
	$.likealunatic.externalLink();
	$.likealunatic.lightbox();
	$.likealunatic.scroll();

	LNW.write();
});

$.likealunatic = {
// set style for external site link
	externalLink: function() {
		var conf = {
			context: 'div.post>div.content'
		},
		$link,
		domain = "http://likealunatic.jp";
		if (conf.context) {
			$link = $('a[href^=http:]:not([href^=' + domain + '])', $(conf.context));
		} else {
			$link = $('a[href^=http:]:not([href^=' + domain + '])');
		}
		$link.bind('click', function(e) {
			e.preventDefault();
			window.open(this.getAttribute('href'), '_blank');
		});
		$link.addClass('external-link');
	},

// scroll to inside page link
	scroll: function() {
		$('a[href^="#"]').each(function() {
			$(this).bind("click", function() {
				var href = $(this).attr('href');
				var targetOffset = Math.floor($(href).offset().top);
				$('html,body').animate({'scrollTop': targetOffset}, 'swing');
			});
		});
	},

// script for "jQuery lightBox plugin"
	lightbox: function() {
		var conf = {
			context: 'div.post'
		},
		$link;
		function setLightbox(context) {
			$link = $('a[href$=".jpg"], a[href$=".gif"], a[href$=".png"]', context);
			$link.lightBox().addClass('lightbox-link');
		}
		if (conf.context) {
			$(conf.context).each(function() { setLightbox(this); });
		} else {
			setLightbox();
		}
	}

};

// "position:fixed" style for lt IE6
$.fn.positionFixed = function() {
	if ($.browser.version > 6) { return; }
	var self = this;
	$(self).css({ 'position': 'absolute' });
	var topPos = $(self).position().top;
	$(window).bind('scroll', function() {
		$(self).css({ 'top': document.documentElement.scrollTop + topPos });
	});
};

})(jQuery);

// "console" object for Legacy Browsers
if (!console) {
	var console = {
		log: function() {
			var s = '';
			for (var i=0, l=arguments.length; i<l; i++) {
				s += arguments[i];
			}
			alert(s);
		}
	};
}

