$(document).ready(function(){

    var ix=1;

    $('.xoxoxo').each(function(index) {
        $(this).wrap('<a href="#t">');        
    });       

    var timer = setInterval(showDiv, 7000);
    var timer2 = setInterval(router, 10000);

    function showDiv() {
        if (Math.floor(Math.random()*2)) {
            $('#ads').css('border-left', '1px solid yellow');
            $('#ads').css('border-top', '1px solid yellow');
            setTimeout(function() {
                $('#ads').css('border', '1px solid #fff');
            },200);
        }
    }
    function router() {
        var n = Math.floor(Math.random()*3);
        switch(n) {
            case 0:
                changeHead();
                break;
            case 1:
                walktheline();
                break;
            default:
                break;
        }
    }
    function changeHead() {
        var u = $('#headimg').attr('src');
        ix++;
        if (ix==qi) ix=0;
        var e = u.split('_');
        var nu = e[0] + "_" + ix + ".jpg";
        $('#headimg').attr('src', nu);
    }
    function walktheline() {
        var a = $('#imgs1 a:first-child');
        a.clone().appendTo('#imgs2');
        var b = $('#imgs2 a:first-child');
        a.remove();
        b.clone().appendTo('#imgs1');
        b.remove();
    }
});
