<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs
    title="美人時計 (bijin-tokei)"
    title_url="__MSG_module_url__"
    description="__MSG_module_description__"
    screenshot="http://www.ig.gmodules.com/gadgets/proxy/refresh=3600&amp;container=ig&amp;gadget=http%3A%2F%2Fbijint.com%2Fgadget%2Fbijin%2FFgadget.xml/http://www.bijint.com/gadget/bijin/assets/img/screenshot.jpg"
    thumbnail="http://www.ig.gmodules.com/gadgets/proxy/refresh=3600&amp;container=ig&amp;gadget=http%3A%2F%2Fbijint.com%2Fgadget%2Fbijin%2FFgadget.xml/http://www.bijint.com/gadget/bijin/assets/img/thumbnail.png"
    scrolling="false"
    singleton="false"
    height="320"
    author_email="cc@bijint.com"
    author="__MSG_author_name__"
    author_affiliation="__MSG_author_affiliation__"
    author_location="__MSG_author_location__"
    author_aboutme="__MSG_author_aboutme__"
    author_link="http://www.bijint.com/"
    author_photo="http://www.bijint.com/img/logo70x100.jpg">

    <Locale messages="http://www.bijint.com/gadget/bijin/assets/locale/ALL_ALL.xml" />
    <Locale messages="http://www.bijint.com/gadget/bijin/assets/locale/ja_ALL.xml" lang="ja" />
    <Require feature="dynamic-height"/>
    <Require feature="views"/>
    <Require feature="opensocial-0.8"/>
    <Require feature="analytics"/>
    <Icon mode="base64" type="image/gif">R0lGODlhEAAQALMKAERERFVVVREREczMzHd3d6qqqmZmZt3d3YiIiAAAAP///wAAAAAAAAAAAAAA
AAAAACH5BAEAAAoALAAAAAAQABAAAAQ5UMlJKx02q5AyrkgHIlYIJsZxcsSUkOdxJKrylqIA36ek
S6/aJCQT2RCwSYEAACSbSY10Sq1ar5MIADs=</Icon>
</ModulePrefs>

<Content type="html"><![CDATA[
<div id="wrapper">
    <a target="_blank" id="photo" href="__MSG_module_url__"><span class="dummy">&nbsp;</span></a>
</div>
<style type="text/css">/*<!--*/
    body { margin:0; padding:0; color:#333; background:#fff; }
    #wrapper { padding:0; text-align:center; }
    #photo { width:240px; height:320px; margin:0 auto; display:block; position:relative; top:0; left:0; text-decoration:none; }
    .canvas #photo { width:590px; height:450px; margin:0; }
    #photo .dummy { display:block; width:240px; height:320px; filter:alpha(opacity=0); -moz-opacity:0; opacity:0; background:#fff; z-index:9; position:absolute; top:0; left:0; }
    #photo img,
    #photo span { position:absolute; top:0; left:0; width:100%; display:block; }
    img.hover { visibility:hidden; }
    .hover img { visibility:hidden; }
    .hover img.single,
    .hover img.hover { visibility:visible; }
    img { border:0; }
/*-->*/</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript">/*<!--*/
;(function($){

var wrapper, photoDiv, currentPhoto;
var
    usedRandom = {},
	defaultLink,
    isMixi = /^.+mixi\-platform.com$/.test(document.location.host);
var
    //
    PHOTO_DOMAIN = "http://www.bijint.com",
    PHOTO_DIR = "240x320",
    PHOTO_DIR_L = "590x450",
    PHOTO_EXT = ".jpg",
    DEFAULT_PHOTO_PATH = "/assets/pict/bijin/"
    RANDOM_BASE = "abcdefghijklmnopqrstuvwxyz0123456789",
    PROXY_URL = "http://www.ig.gmodules.com/gadgets/proxy/refresh=3600&container=ig&gadget=http%3A%2F%2Fbijint.com%2Fgadget%2Fbijin%2FFgadget.xml/",
    JSON_URL = PHOTO_DOMAIN+"/misc/tools/out/%digits%.json",
    RANDOM_LENGTH = 10,
    MAX_WIDTH = 240,
    MAX_HEIGHT = 320,
    MAX_WIDTH_L = 590,
    MAX_HEIGHT_L = 450,
    PADDING = 0,
    MIXI_MAX_HEIGHT = 212;

function init() {
    wrapper =$("#wrapper");
    if(isCanvas()) {
        wrapper.addClass("canvas");
        MAX_WIDTH = MAX_WIDTH_L;
        MAX_HEIGHT = MAX_HEIGHT_L;
    }
    photoDiv = $("#photo");
    update(new Date());
    $(window).bind("resize",onResize);
    photoDiv.bind("mousedown",function(){
        sendTrack(true,true);
    });
    photoDiv.bind("click",function(){
        var href = $(this).attr("href");
        if(isMixi&&window.mixi&&mixi.util&&typeof mixi.util.requestExternalNavigateTo=="function") {
            setTimeout(function(){
                if(isCanvas())
                    mixi.util.requestExternalNavigateTo(href);
                else
                    gotoCanvas();
                return false;
            },99);
            return false;
        }
    });
    photoDiv.hover(function(){
        $(this).addClass("hover");
    },function(){
        $(this).removeClass("hover");
    });
    sendTrack();
    onResize();
}

function gotoCanvas() {
    gadgets.views.requestNavigateTo(new gadgets.views.View("canvas"));
}


function sendTrack(time,click) {
    var path = "/gadget/bijin/"+(isMixi?"mixi":"igoogle");
    var view = getView();
    if(view&&view!="home") path += "/"+view;
    if(time) path += "/"+time4Digits();
    if(click) path += "/click";
    try {
        _IG_Analytics("UA-11286402-1",path);
    } catch(e) {}
}

function getView() {
    try {
        return gadgets.views.getCurrentView().getName().toLowerCase();
    } catch(e) { return ""; }
}

function isCanvas() {
    return /^canvas$/.test(getView());
}

function onResize() {
    if(isMixi&&!isCanvas()) {
        photoDiv.css({
            width : Math.ceil(MAX_WIDTH*MIXI_MAX_HEIGHT/MAX_HEIGHT),
            height : MIXI_MAX_HEIGHT
        });
        gadgets.window.adjustHeight(MIXI_MAX_HEIGHT);
        return;
    }
    var w = $(window).width();
    var m = w<MAX_WIDTH+PADDING*2;
    photoDiv.css({
        width : m?"100%":(MAX_WIDTH+"px"),
        height : m?"auto":(MAX_HEIGHT+"px")
    });
	defaultLink = defaultLink||photoDiv.attr("href");
    if(!currentPhoto) return;
    setTimeout(function(){
        var h = currentPhoto.height()+PADDING*2||MAX_HEIGHT+PADDING*2;
        try {
            gadgets.window.adjustHeight(h);
        } catch(e) {
            try {
                _IG_AdjustIFrameHeight(h)
            } catch(e) {}
        }
    },0);
}


function getRandom() {
    do {
        var rnd = "";
        while(rnd.length<RANDOM_LENGTH) {
            rnd += RANDOM_BASE.charAt(Math.floor(Math.random()*RANDOM_BASE.length))||"";
        }
    } while(usedRandom[rnd]);
    usedRandom[rnd] = true;
    return rnd;
}

function update(date) {
    var timeout;
    var nextTime = new Date();
    nextTime = new Date(nextTime.getFullYear(),nextTime.getMonth(),nextTime.getDate(),nextTime.getHours(),nextTime.getMinutes()+1);
    if(date) {
        timeout = nextTime.getTime() - date.getTime();
    } else {
        date = nextTime;
        timeout = 60000;
    }
    var fd = time4Digits(date);
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
    gadgets.io.makeRequest(JSON_URL.replace(/%digits%/,fd), function(res){
        res = res||{};
        var data = res.data||{};
        var link = data.link_url||defaultLink;
        var id = "photo-"+getRandom();
        var loaded = false;
        var ht = [
            "<span id=\"",id,"\" style=\"display:none;z-index:2;\">",
                getImageTag(data.pict_path||DEFAULT_PHOTO_PATH,fd,"neutral"+(data.pict_path_hover?"":" single")),
                getImageTag(data.pict_path_hover,fd,"hover"),
            "</span>"
        ];
        photoDiv.append($(ht.join("")));
        var ele = $("#"+id);
        ele.data("link",link);
        setTimeout(function(){
            if(!loaded || !link) update();
        },timeout);
        $("img.neutral",ele).bind("load",function(){
            var d = new Date();
            var c = d.getTime();
            var t = date.getTime();
            var p = t-c;
            loaded = true;
            if(p<-60000) return ele.remove();
            if(p>0) {
                setTimeout(function(){ fadeIn(ele); },p);
                return;
            }
            fadeIn(ele);
        });
    
    }, params);
}

function getImageTag(path,fd,styleClass) {
    if(!path) return "";
    path += (isCanvas()?PHOTO_DIR_L:PHOTO_DIR)+"/"+fd+PHOTO_EXT;
    if(!/^https?\:/.test(path)) path = PHOTO_DOMAIN+path;
    var img = getImageURL(path);
    return "<img src=\""+img+"\" class=\""+styleClass+"\" />";
}

function fadeIn(ele) {
    ele.fadeIn();
    photoDiv.attr("href",ele.data("link"));
    if(currentPhoto) {
        currentPhoto.css("z-index","1");
        currentPhoto.fadeOut("slow",function(){
            $(this).remove();
        });
    }
    sendTrack(true);
    currentPhoto = ele;
    onResize();
    update();
}

function formatNum(n) {
    return n<10?"0"+n:String(n);
}

function time4Digits(date) {
    date = date || new Date();
    return [
        formatNum(date.getHours()),
        formatNum(date.getMinutes())
    ].join("");
}

function getImageURL(urlOrg) {
    if(urlOrg.indexOf("?")==-1) urlOrg += "?";
    var date = new Date();
    urlOrg += [
        "yyyymmdd=",
        date.getFullYear(),
        formatNum(date.getMonth()+1),
        formatNum(date.getDate()),
        "&ext=", PHOTO_EXT
    ].join("");
    var url;
    try {
        url = gadgets.io.getProxyUrl(urlOrg);
    } catch(e) {
        try {
            url = _IG_GetImageUrl(urlOrg);
        } catch(e) {}
    }
    return url==urlOrg?PROXY_URL+urlOrg:url;
}

try {
    gadgets.util.registerOnLoadHandler(init);
} catch(e) {
    try {
        _IG_RegisterOnloadHandler(init);
    } catch(e) {
        $(init);
    }
}

/** start:MIXI AD PROGRAM */
(function(){
    if(!isMixi||!isCanvas()) return;
    var url = "http://mixi.jp/ad_application_program_invoker.pl?appli_id=7325&ad_id=935538716019f2483dbe08c5a866fce85c3420db";
    document.writeln(['<scri','pt src="',url,'&ts=',(new Date).getTime(),'">','</scri','pt>'].join(''));
})();
/** end:MIXI AD PROGRAM */

})(jQuery.noConflict(true));

/*-->*/</script>
]]></Content>

</Module>