jQuery(document).ready(function($) {
	$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=focusimc&callback=?&count=1",function(data) {

		var _t = data[0].text+" ";
		var reg = new RegExp("@.+?(?=\\s)","g");
		_n = _t.match(reg);
		
		if (_n!=null) {
			for (var i=0;i<_n.length;i++) {		
				_t = _t.replace(_n[i], "<a href='http://www.twitter.com/"+_n[i].toString().substr(1)+"' target='_blank'>"+_n[i].toString()+"</a>");
			}
		}
			
		$("div.home-twitter").html("<p class='grey bold'>"+_t+"</div>")
	
	});
	
	$totalwidth = 0;
	$("#homeslider #homesliderholder img").each(function(index) {
    	$totalwidth += $(this).width();
	});
	
	if($totalwidth > 940){
		$("#homeslider #homesliderholder").width($totalwidth*3);
	}
	
	$imgs = $("#homeslider #homesliderholder").html();
	$("#homeslider #homesliderholder").html($imgs+$imgs+$imgs);
		
	$("#homeslider #homesliderholder").css("left",0-$totalwidth);

	function slideright() {
		$left = parseInt($("#homeslider #homesliderholder").css("left"));
		if($left < ($totalwidth*-2)){
			$("#homeslider #homesliderholder").stop().css("left",$left+$totalwidth);
		}
	    $("#homeslider #homesliderholder").stop().animate({
		    left: '-=20',
		  }, 100, function() {
		});
	}

	function slideleft() {
		$left = parseInt($("#homeslider #homesliderholder").css("left"));
		console.log($left);
		if($left > -100){
			$("#homeslider #homesliderholder").stop().css("left",$left-$totalwidth);
		}
	    $("#homeslider #homesliderholder").stop().animate({
		    left: '+=20',
		  }, 100, function() {
		});
	}	

    $("#homesliderright").hover(
        function() {
            hoverInterval = setInterval(slideright, 100);
        },
        function() {
            clearInterval(hoverInterval);
        }
    );

    $("#homesliderleft").hover(
        function() {
            hoverInterval = setInterval(slideleft, 100);
        },
        function() {
            clearInterval(hoverInterval);
        }
    );	
	
});
