(function($) {
$(function() {
$.ssp.twitter();
$.ssp.Pagetop();
$.ssp.rollover();
$.ssp.Popup();
});
$.ssp = {
twitter: function(){
$("#twit").empty();
$.ajax({
dataType: "json",
url: "http://twitter.com/statuses/user_timeline/hidotn.json?callback=?",
timeout: 2000,
error: function(){
$("#twit").html("<li>ERROR</li>");
},
success: function (data) {
$("#twit").empty();
var my_id = "hidotn";
var item_max = 3;
var timeline_list = new Array();
var cnt = 1;
var html;
for (var i = 0; i < data.length; i++){
var text  = data[i]['text'];
if (text.match(/^@/)) { continue; }
if (cnt > item_max) { break; }
cnt++;
var created_at = data[i]['created_at'].split(" ");
var post_date = created_at[1] + " " + created_at[2] + ", " + created_at[5] + " "+ created_at[3];
var date = new Date(post_date);
date.setHours(date.getHours() + 9);
var year = date.getFullYear();
var mon = date.getMonth() + 1;
var day = date.getDate();
var time = date.getHours();
var minu = "00" + date.getMinutes();
minu = minu.substr(minu.length-2,2); 
var out_date = year + "/" + mon + "/" + day + " "+ time + ":" + minu;
html ='<li><a href="http://twitter.com/hidotn" target="_blank"><span>' + out_date + '</span>' + text + '</a></li>';
$("#twit").append(html);
  }
 $("#twit").liScroll({travelocity: 0.04});
}
});
jQuery.fn.liScroll = function(settings) {
settings = jQuery.extend({
travelocity: 0.05
}, settings);
return this.each(function(){
var $strip = jQuery(this);
$strip.addClass("newsticker")
var stripWidth = 0;
var $mask = $strip.wrap("<div class='mask'></div>");
var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
var containerWidth = $strip.parent().parent().width();
$strip.find("li").each(function(i){
stripWidth += jQuery(this, i).width();
});
$strip.width(stripWidth);
var defTiming = stripWidth/settings.travelocity;
var totalTravel = stripWidth+containerWidth;
function scrollnews(spazio, tempo){
$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
}
scrollnews(totalTravel, defTiming);
$strip.hover(function(){
jQuery(this).stop();
},
function(){
var offset = jQuery(this).offset();
var residualSpace = offset.left + stripWidth;
var residualTime = residualSpace/settings.travelocity;
scrollnews(residualSpace, residualTime);
});
});
};
},
Pagetop: function(){ 
$('a[href^=#]').click(function () {
$(this).blur();
var href = $(this).attr("href");
var topPx = $(href).offset().top;
$('html,body').animate({ scrollTop: topPx }, 800, "swing");
return false;
});
},
rollover: function() {
var preLoad = new Object();
$('img.rollover,input.rollover').not("[src*='_o.']").each(function(){
var imgSrc = this.src;
var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
var imgOver = imgName + '_o' + fType;
preLoad[imgSrc] = new Image();
preLoad[imgSrc].src = imgOver;
$(this).hover(
function (){ this.src = imgOver; },
function (){ this.src = imgSrc; }
);
});
},
Popup: function(){
$(".popup").click(function() {
var popup = window.open(this.href, "popWin", "scrollbars=1, resizable=1, width=800, height=600");
popup.focus();
return false;
});
}
};
})(jQuery);
