$(document).ready(function(){
	
	$("#tweet").tweet({
			join_text : "auto",
			username : "rockinriomadrid",
			avatar_size : 32,
			template: "{time}{text}",
			count : 3,
			auto_join_text_default : "",
			auto_join_text_ed : "",
			auto_join_text_ing : "",
			auto_join_text_reply : "",
			auto_join_text_url : "",
			loading_text : "..."
	}).bind("loaded",function(){$(this).find("a").attr("target","_blank");});
	
	$("#poll_return_link").click(function() {
        $("#poll_results").animate({
            opacity: 0
        }, 100, function() { $("#poll_results").css("visibility", "hidden"); });
        $("#poll_form").css("visibility", "visible");
        $("#poll_form").animate({
            opacity: 1
        }, 100);
               
    });
                                                                               
    $("#poll_results_link").click(function() {
    	$("#poll_results").css("visibility", "visible");
        $("#poll_results").animate({
            opacity: 1
        }, 100);
        $("#poll_form").animate({
            opacity: 0
        }, 100, function() { $("#poll_form").css("visibility", "hidden"); } );
               
    });
    
    $("[rel=tooltip]").tipsy({
        gravity:"s",
        fade:true
    });
    var k=29,i=6,m=2012,b=15,f=new Date(m,i-1,k,b),j=f-(new Date()),a=Math.floor(j/3600000),l=Math.floor(a/24),h=a.toString().split(""),d=l.toString().split("");
    var e="",c="";
    $(d).each(function(n,o){
        e+='<img src="http://www.rockinriomadrid.es/content/rockinriomadrid/img/contador_0'+o+'.png" alt="'+o+'" />'
        });
    $(h).each(function(n,o){
        c+='<img src="http://www.rockinriomadrid.es/content/rockinriomadrid/img/contador_0'+o+'.png" alt="'+o+'" />'
        });
    $(".counter .days").html(e+'<img src="http://www.rockinriomadrid.es/content/rockinriomadrid/img/contador_dias.png" alt="Dias" />');
    $(".counter .hours").html(c+'<img src="http://www.rockinriomadrid.es/content/rockinriomadrid/img/contador_horas.png" alt="Horas" />');
    $.getJSON("http://twitter.com/statuses/user_timeline/rockinriomadrid.json?count=5&callback=?",function(o){
        var n=o.length;
        $.each(o,function(u,x){
            var r=new Date(x.created_at);
            var w=(r.getDay().length==1)?"0"+r.getDay():r.getDay();
            var s=(r.getHours().length==1)?"0"+r.getHours():r.getHours();
            var p=new Date();
            var q=(p.getDay().length==1)?"0"+p.getDay():p.getDay();
            var v=(p.getDay().length==1)?"0"+p.getDay():p.getDay();
            var t;
            if(v>w){
                t=((v-w)*24)+(q-s)
                }else{
                t=p-s
                }
                months=new Array(12);
            months[0]="Jan";
            months[1]="Fev";
            months[2]="Mar";
            months[3]="Abr";
            months[4]="Mai";
            months[5]="Jun";
            months[6]="Jul";
            months[7]="Ago";
            months[8]="Set";
            months[9]="Out";
            months[10]="Nov";
            months[11]="Dez";
            month=months[r.getMonth()-1];
            last=(u==n-1)?" last":"";
            text=(x.text.length>90)?x.text.substring(0,90)+' <a href="http://www.twitter.com/rockinriomadrid" target="_blank">...</a>':x.text;
            $("#twitter").append('<p class="tweet'+last+'">'+w+" "+month+"<br/><span>"+text+"</span></li>");
            $("#mam .container.right .middle .list").append('<p class="tweet'+last+'"><img src="http://a2.twimg.com/profile_images/431622377/logofacebook_normal.jpg" style="clear:left; float: left; margin-right: 10px; margin-bottom: 10px;" /><a href="http://www.twitter.com/rockinriomadrid" target="_blank">rockinriolisboa</a><br/><span>'+text+'</span><br/><span class="hour">hace '+t+"h</span>")
            })
        });
    $("nav ul li").hover(function(){
        $(this).children("ul").eq(0).stop(1,1).fadeIn(100)
        },function(){
        $(this).children("ul").eq(0).stop(1,1).fadeOut(100)
        });
    $("article#gallery .block .middle .gallery").jCarouselLite({
        btnNext:".next",
        btnPrev:".prev",
        speed:500,
        visible:1,
        start:-1,
        circular:false,
        beforeStart:function(n){
            $(n).children("p").fadeOut()
            },
        afterEnd:function(n){
            var o=$("article#gallery .block .middle .gallery ul li").length;
            var p=n.prevAll().length+1;
            $("article#gallery .block .middle p.counter").html(p+"/"+o)
            }
        });
var g=$("article#gallery .block .middle .gallery ul li").length;
    $("article#gallery .block .middle p.counter").html("1/"+g);
    $("article#gallery .block .middle .next").click();
    $("section#slideshow .gallery").jCarouselLite({
    speed:500,
    auto:10000,
    visible:1,
    beforeStart:function(n){
        $("section#slideshow .nav .outer-center .inner-center ul li a").removeClass("active")
        },
    afterEnd:function(n){
        var p=$(n[0]).attr("id");
        var o="section#slideshow .nav .outer-center .inner-center ul li a."+p;
        $(o).addClass("active")
        },
    btnGo:["section#slideshow .nav .1","section#slideshow .nav .2","section#slideshow .nav .3","section#slideshow .nav .4","section#slideshow .nav .5","section#slideshow .nav .6","section#slideshow .nav .7","section#slideshow .nav .8","section#slideshow .nav .9","section#slideshow .nav .10","section#slideshow .nav .11","section#slideshow .nav .12"]
    });
$("section#slideshow .nav .outer-center .inner-center ul li a.1").click()
    });
