var $j = jQuery.noConflict();

$j(document).ready(function() {	
	
	$ = $j;
	
	// toggle effect start
	$('#tseCTIsmileys-comment').hide();

	$('#tango_title').click( function() {
		$('#tseCTIsmileys-comment').toggle('slow');    
		return false;
	});      
	// toggle effect end   

		
	// fit images
	// Automatically decrease image width to fit content division
	var selector = '.entry-content img'; // selector
	var hasImages = $(selector).is('img');
	
	var contentWidth = $('.entry-content').width(); // content width
	
	var width = 0;
	var height = 0;
	var x = 0;
	var y = 0;
	
	if ( hasImages ) {
		
		$.each($(selector) ,function() {
			
			width = $(this).width();
			height = $(this).height();
			
			if ( width >= contentWidth ) {	
				// width:height = contentWidth:?
				x = width / contentWidth;				
				y = height / x;
				
				$(this).width(contentWidth);
				$(this).height(y);
			}					
		});
	}
	// fit images
	
	
	var blog = 'http://ipm.pe.kr/blog/';
	var currentPage = window.location.href;
	
	$(window).keyup(function(event) {
		if ( blog == currentPage || window.location.pathname.search('page') != -1 ) {
			if ( event.keyCode == 37 ) { // left			
				if ( blog == currentPage ) window.location.href = blog + 'page/2/';
				else {
					var cPageNo = ( window.location.pathname.substr(11) ).replace('/', '');
					window.location.href = blog + 'page/' + ( ++cPageNo ); // cPageNo, str to no
				}			
			} else if ( event.keyCode == 39 ) { // right
				if ( blog != currentPage ) {
					var cPageNo = ( window.location.pathname.substr(11) ).replace('/', '');
					if ( cPageNo > 1 ) window.location.href = blog + 'page/' + ( --cPageNo ); // cPageNo, str to no
				}
			}
		}
	});
});