/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var o = {
    tweetsScroll:$('<div>').css("position", "absolute"),
    tweetsH:$("<div>").attr("id", "tweetsH"),
    twNum:1,
    
    ready:function()
    {
        $('.portfolioItem a, .thumbnail').fancybox({autoScale: false});
        $('.close').click(o.closeOverlay);
        $('.contactButton, .contact, .contact_lightbox').click(o.openOverlay);
        
        $("#headerRight .header_text").click(function() {
        	window.location = "/het_verrast";
        });
        $("#title a").hover(
        	function() {$(this).parent().addClass("hover");},
        	function() {$(this).parent().removeClass("hover")
        });
        
        $("#headerRight").append(o.tweetsH);
        
        $.getJSON("/tweets.php", {}, o.tweetsLoaded);
    },
    
    openOverlay:function()
    {
        $('.overlay').show();
        $(".wantmail").css('display', 'inline');
        setTimeout(function()
        {
            $('.wantmail').css('display', 'block');
        }, 200);
    },
    
    closeOverlay:function()
    {
      $('.overlay').hide();
      return true;
    },
    
    tweetsLoaded:function(arr)
    {
        var key = 0;
        var obj = arr[key];
        obj.text = obj.text.replace(/(http:\/\/([^\s]+))/g, '<a href="$1" target="_blank">$1</a>')
                .replace(/@([A-Za-z0-9_-]+)/g, '<a href="http://twitter.com/$1" target="_blank">@$1</a>')
                .replace(/#([A-Za-z0-9_-]+)/g, '<a href="http://twitter.com/search?q=%23$1" target="_blank">#$1</a>')
        //obj.text = "<a href='http://twitter.com/denieuwesinfo' target='_blank' style='color:black !important;'><b>denieuwesinfo</b></a>"+

        var hl = $("<div>").addClass("tweetRow");
        $("<img/>").attr('src', "/assets/img/new/twitter.png").appendTo(hl);
        hl.append("<font color='#999999' style='font-size:13px; display:block; margin-top:2px; margin-left:42px;'>Tweets<br/>"+
                    "<a href='http://twitter.com/denieuwesinfo' target='_blank' style='font-size:10px'>Volg ons op Twitter »</a></font>");
        hl.append("<div>"+obj.text+"</div>");
        o.tweetsScroll.append(hl);
        //o.tweetsScroll.
        o.tweetsH.append(o.tweetsScroll);
        //o.loadNext();
        
    },
    
    loadNext:function()
    {
        pos = $(o.tweetsScroll).children('.tweetRow').eq(o.twNum).position().top;
        o.tweetsScroll.delay(4000).animate({top:-pos}, 1000, o.loadNext);
        o.twNum++;
        if(o.twNum>=o.tweetsScroll.children('.tweetRow').length){
            o.twNum = 0;
        }
    }
    
}

$(document).ready(o.ready);
