$(window).load(function(){
    $('.column a').autoHeight();
    //$('#news div,#sidebar .news').corner('5px');
});

$(window).load(function(){
    var temp=location.hash.split('!');
    if(temp.length<2) return;
    $.scrollTo($('a[name='+temp[1]+']'),1000);
});

$(function(){
    return;
    $('#searchtype').jQselectable({pos:-6});
});

$(function(){
    if(location.protocol.indexOf('https:')<0) return;
    $('a').each(function(){
        var temp=$(this).attr('href');
        if(!temp) return;
        if(temp.indexOf('/camp-rv.com')<0) return;
        $(this).attr({href:temp.replace('/camp-rv.com','http://www.camp-rv.com')});
    });
});

$(function(){
    $('#global>div>ul>li').each(function(){
        if($('ul',this).length) $(this).addClass('has_child');
        $(this).bind('mouseenter',function(){ $('ul, .dropShadow',this).slideDown(200); });
        $(this).bind('mouseleave',function(){ $('ul, .dropShadow',this).slideUp(); });
    });
    $('#global .null').click(function(){return false;});
    var getFile=function(val){
        var src=val.split('.');
        return [
            src.slice(0,-1).join('.'),
            src[src.length-1]
        ];
    };
    $('#global>div>ul>li>a,#headnavi a').hover(function(){
        var temp=$(this).find('img');
        var src=getFile(temp.attr('src'));
        temp.attr({'src':src[0]+'_on.'+src[1]});
    },function(){
        var temp=$(this).find('img');
        var src=getFile(temp.attr('src'));
        temp.attr({'src':src[0].split('_on')[0]+'.'+src[1]});
    });
});

$(function(){
    if(document.referrer.indexOf('camp-rv.com')>=0){
        $('#global ul ul').hide();
        return;
    }
    setTimeout(function(){
        $('#global ul ul').each(function(i){ $(this).delay(i*200).slideUp(); });
    },600);
});

$(function(){
    return;
    if($.cookie("access")) $('#first').css({display:'none'});
    $(window).load(function(){ $.cookie("access",$('body').addClass('access')); });
});

$(function(){
    var temp=Math.floor(((new Date(2012,2-1,10)).getTime()-(new Date()).getTime())/(24*60*60*1000))+1;
    temp=[Math.floor(temp/10),temp%10];
    $('#cover .countdown span').html('<img src="img/numbers/'+temp[0]+'.png"><img src="img/numbers/'+temp[1]+'.png">');
});

$(window).load(function(){
    $.getJSON(
        'http://search.twitter.com/search.json?callback=?&q=%23campingcar&rpp=10',
        function(data) {
            var obj=$('#tweet');
            if(obj.length<1) return;
            $.each(data.results,function(i,t){
                if(!t.text) return;
                t.text=t.text.replace(
                    /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,
                    '<a href="$1">$1</a>'
                );
                t.text=t.text.replace(
                    /(^|[\W])@(\w+)/gi,
                    "$1@<a href=\"http://twitter.com/$2\">$2</a>"
                );
                t.text=t.text.replace(
                    /(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi,
                    ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all">#$1</a>'
                );
                var hour=Math.round(((new Date())-(new Date(t.created_at)))/(1000*60*60));
                obj.append([
                    '<div class="tweet">',
                    '<a class="user" href="http://twitter.com/intent/user?screen_name=',t.from_user,'">',
                    '<img src="',t.profile_image_url,'" width="48" height="48">',
                    t.from_user,
                    '</a><br>',
                    '<span class="text">',t.text,'</span><br>',
                    '<span class="hours">',hour,' hours ago</span>',
                    '</div>'
                ].join(''));
            });

            var cols=$('#tweet .tweet');
            cols.autoHeight({height:'height'});
            var h=cols.outerHeight();
            $('#tweet').height((h)*2);
            var api=obj.jScrollPane({
                verticalDragMinHeight:h,
                verticalDragMaxHeight:h,
                contentWidth:248,
                horizontalGutter:0,
                verticalGutter:0,
                animateDuration:200,
                animateScroll:true
            }).data('jsp');
            api.scrollToBottom(false);
            var next=cols[cols.length-3];
            var timer=setInterval(function(){
                api.scrollToElement(next,true,true);
            },4000);
            obj.bind('jsp-scroll-y',function(e,y,t,b){
                var temp=Math.floor(y/h);
                if(y%h>0) return next=cols[temp];
                if(temp<1) temp=cols.length;
                next=cols[temp-1];
            });
        }
    );
});

