$(function(){
    /* HoverElement */
    $(".HoverElement").mouseenter(function() {
        var t=$.trim($(this).attr("tr"));
        t.match(/\./) ? $(this).find(t).show():$(t).find().show();
    }).mouseleave(function(){
        var t=$.trim($(this).attr("tr"));
        t.match(/\./) ? $(this).find(t).hide():$(t).find().hide();
    });
    /* toggleTextInput */
    $(".toggleTextInput").click(function() {
        var o=$(this);
        var t=$.trim(o.attr("tr"));
        var t1=$.trim(o.val());
        t==t1 && o.val("");
    }).focus(function() {
        var o=$(this);
        o.removeClass('toggleTextInputNormal');
    }).blur(function() {
        var o=$(this);
        var t=$.trim(o.attr("tr"));
        var t1=$.trim(o.val());
        o.addClass('toggleTextInputNormal');
        !t1 && o.val(t);
    }).each(function() {
        $(this).val($(this).attr("tr"));
    }).parents("form").submit(function() {
        var o = $(this).find('.toggleTextInput');
        var t=$.trim(o.attr("tr"));
        var t1=$.trim(o.val());
        if (t1==t) {
            o.focus().click();
            tipBox.warn("请出入您要搜索的内容.",3000);
            return false;
        }
    });
    /* input icon outline fixed */
    $(".ico_input16,.ico_input12").focus(function() {
        $(this).blur();
    });
    /* click to toggle one Element */
    $(".clickToggleElement").click(function() {
        $(this).attr("tr").toggle();
        $(this).blur();
        return false;
    });
    $(".clickShowElement").click(function() {
        var hideEle=$(this).attr("hidetr");
        if (hideEle) {
            $(hideEle).hide();
        };
        var showEle=$(this).attr("showtr");
        if (showEle) {
            $(showEle).show();
        };
        $(this).blur();
    });
    $(".switchElement").click(function() {
        $(this).hide();
        $($(this).attr("tr")).show();
        $(this).blur();
        return false;
    });

    
    var c2link = function() {
        /* set editor source */
        var html = $(this).html();
        $(this).html(href2link(html));
    };
    $('.hrefToLink').each(c2link);
    
    /* init all editors */
    var editors = $("textarea.postEditor").each(c2link);
    editors.length && loadJS("/static/js/editor_1_0_final/loadeditor.js");
    
    /* init all inforcards on load */
    var cards = $(".ShowUserInfoCard");
    cards.length && Utils.initInforCard(cards);
    
    /* init all footprint_infor_cards on load */
    var footprintCards = $(".ShowFootprintInfoCard");
    footprintCards.length && Utils.initFootprintCard(footprintCards);
        
    /* ------------ */
    if ($(".jcalendar").length) {
        $.include({
            '/static/stylesheets/ext/jcalendar.css':null,
            '/static/js/ext/jcalendar.js':null
        },function () {
            $('.jcalendar').jcalendar();
        });
    };
    /* -----------
    if ($(".datepicker").length) {
        $.include({
            '/static/stylesheets/ui/jquery-ui-1.8.2.custom.css':null,
            '/static/js/jquery-ui-1.8.2.custom.min.js':null
        },function () {
            window.kick = $(".datepicker").datepicker();
        });
    };
     */
    /* get trip counts for search input */
    /*$.post('/get_trip_count/',function(data){
        var count = data.count;
        $("#searchForm").find('[id="q"]').attr({
            value:"已加入的行程"+ count +"个",
            tr:"已加入的行程"+ count +"个"});
    },"json");
    */
    
    $("#submitSearch").click(function() {
         if($.trim($("#searchForm").find('[id="q"]').val()).substring(0,6)=="已加入的行程"){
             $("#searchForm").find('[id="q"]').val("");
         }
    });
    $('.btnCopyToClickBoard').click(function (){
        $("#flashTools")[0].fsetClipboard();
        return false;
    });
    
    /* ---------- */
    $('.btnSure').click(function() {
        var btn = $(this).addClass("clicked");
        setTimeout(function() {
            btn.removeClass("clicked");
        },300);
        return true;
    });
    $(".tabSection").each(function(){
        $(this).find(">ul.tabs").tabs($(this).find(".tabsContent>.tab"));
    });

    $(".tabTagSection").each(function(){
        $(this).find(">ul.tabs_tag_nav").tabs($(this).find(".tabsContent>.tab"));
    });
    /* fix input href link hover style */
    $(".hrefLink").hover(function() {
        $(this).addClass('hrefLinkHover');
    },function() {
        $(this).removeClass('hrefLinkHover');
    });
    
    /* images fix width fixed size */
    fixThumbnail("boxIncludePic120_120",120,120,false,true);
    fixThumbnail("boxIncludePic58",58,58,false,true);
    // /trip/44/
    fixThumbnail("fix_685",685,685,true);
    fixThumbnail("fix_720",720,720,true);
    // /club/2/topic/2/
    fixThumbnail("fix_600",600,600,true);
    fixThumbnail("fix_615_615",615,615,true);
    fixThumbnail("fix_800",800,800,true);
});
function toDateString(t) {
    function fillZero (s) {
        var t=new Number(s);
        if (t<10) {
            t="0"+t;
        };
        return t;
    }
    var tString="";
    tString += t.getFullYear()+"-";
    tString += fillZero(t.getMonth()+1)+"-";
    tString += fillZero(t.getDate())+" ";
    tString += fillZero(t.getHours())+":";
    tString += fillZero(t.getMinutes())+":";
    tString += fillZero(t.getSeconds());
    return tString;
}

/** modal dialog tpl
    <!-- 删除脚印dialog -->
    <div class="modal" id="dialog-confirm"> 
        <h2 class="mTitle">提示</h2>
        <p class="mContent">定删除此脚印吗?</p>
        <p class="mButtons">
            <a class="close btnSure">确定</a>
            <a class="close btnCancel">取消</a>
        </p>
    </div>
 */
/** modal dialog
    
 */

/**
 * init global copy to clipboard button
 * @author 
 * @version $Rev$
 * @requires OtherClassName
 */
$(function() {
    setTimeout(function() {
        $('.copyToClipBoard').each(function() {
            var button = $(this);
            Utils.initFlashCopyButton(button.attr("id"));
        });
    },1000);

});
/**
 * @messageBox
 */
$(function() {
    var box = $('.messageBox');
    var count = Number(box.attr("count"));
    if (count > 0) {
        TitleTiper.tip("新消息",function(isDefault) {
            if (isDefault) {
                box.css({color:'#666666'});
            }else{
                box.css({color:'#ff0000'});
            }
            
        },1000);
    }
});
$(function() {
    $('img.noCache').each(function() {
       var img = $(this);
       img.attr({
           src:img.attr('src') + "?" + Utils.unid()
       });
    });
    $('.showRating').find(".ratingReal").each(function() {
        $(this).width(Number($(this).attr('rating'))*80/5);
    });
});

