$(function(){
	
	//comment reel
	var rotate = function(){
	
	    var triggerID = $active.attr('rel') - 1;
	    var comment_reelPosition = triggerID * width;
	
	    $('.paging a').removeClass('active');
	    $active.addClass('active');
	
	    $('.comment_reel').animate({
	        left: -comment_reelPosition
	    }, 500 );
	}
	
	var width     = $('.window').width();
	var listSum   = $('.comment_reel li').size();
	var reelWidth = width * listSum;

	$('.comment_reel').css({'width' : reelWidth});
    
    var list = listSum;
    var cnt = 0;
    
    while( list > 3){
    	list = list - 3;
    	cnt++;
    }
    if( list != 0 ){
    	cnt++;
    }
    
    for( var i=1; i<= cnt; i++ ){
    	$('.paging').append('<a href="#" rel="'+i+'" class="ir">'+i+'</a>');
    }
    
    $('.paging').show();
	$('.paging a:first').addClass('active');
    
    $('.paging a').click(function() {
    	$active = $(this);
       	rotate();
    	return false;
    });
    //end
    
    $('a.poplight[href^=#]').click(function() {
	    var popID  = $(this).attr('rel');
    	var popURL = $(this).attr('href');

	    var query    = popURL.split('?');
	    var dim      = query[1].split('&');
    	var popWidth = dim[0].split('=')[1];

	    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close ir">close</a>');

	    var popMargTop  = ($('#' + popID).height() + 16) / 2;
	    var popMargLeft = ($('#' + popID).width() + 20) / 2;

	    $('#' + popID).css({
    	    'margin-top' : -popMargTop,
        	'margin-left' : -popMargLeft
    	});

	    $('body').append('<div id="fade"></div>');
    	$('#fade').fadeIn('fast');

    	return false;
	});


	$('a.close, #fade').live('click', function() {
    	$('#fade , .popup_block').fadeOut(function() {
        	$('#fade, a.close').remove();
    	});
    	return false;
	});
	
	var url = "http://twitter.com/statuses/user_timeline/rythgs.json?count=1&callback=?";
    $.getJSON(url, function(data){
        if( data[0].text != undefined ){
            var tweet = data[0].text;
            $("#twitter span").html("").css("display", "none");
            $("#twitter span").text(tweet).fadeIn("slow");
        }
	});
	
	/*
	var entry_url = encodeURI(window.location.href);
	$.getJSON("http://otter.topsy.com/trackbacks.js?url="+entry_url+"&callback=?",
		function(data){
			$('#reteet_count').text(data.response.total);
		}
	);*/
	
	/*
	var column_type = new Array(1, 3, 2);
	$('#top .box').each(function(i){
		if( i >= 3 ){
			i = 0;		
		}
		$(this).addClass('col'+column_type[i]);
	});
	*/
	
	//$('#top').animate({opacity:1}, 500);
});
