var isOpera = Boolean(navigator.userAgent.match("Opera"));

function openTopicsWindow(obj) {
	var $d = new Date();
	var $m = (($d.getMonth() + 1) < 10) ? ('0' + ($d.getMonth() + 1)) : ($d.getMonth() + 1);
	var $h = '' + $d.getFullYear() + $m + $d.getDate() + $d.getHours() + $d.getMinutes();
    var url = "http://www.sneakerbunko.jp/blog/index.html?from=topics";
    
    /*if(isOpera) {
        var $h = 431;
        var $l = obj.x + Math.floor((obj.sw - 1024) / 2) + 15;
        var $t = obj.y + 150;
        var $w = window.open(url, 'external', 'width=550,height='+$h+',scrollbars=auto,left='+$l+',top='+$t);
        $w.focus();
        return;
    }*/

    var div = document.getElementById("external");
    //div.orgLeft = obj.x //+ Math.floor((obj.sw - 1024) / 2) + 15;
	div.orgLeft = getWindowWidth()/2-420;
	if(getWindowWidth()<1000){div.orgLeft = 80};
    div.orgTop = obj.y //+ 135;
    div.orgWinWidth = getWindowWidth();
    div.orgWinHeight = obj.sh-60-obj.sh*0.08+115;//getWindowHeight();
    div.style.visibility = "visible";
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    
    var ifm = div.getElementsByTagName("iframe")[0];
    ifm.src = url;
    ifm.style.width = "860px";
    ifm.style.height = div.orgWinHeight-235+'px';
    ifm.focus();
	
}

function openStoryWindow(obj,no) {
	var $d = new Date();
	var $m = (($d.getMonth() + 1) < 10) ? ('0' + ($d.getMonth() + 1)) : ($d.getMonth() + 1);
	var $h = '' + $d.getFullYear() + $m + $d.getDate() + $d.getHours() + $d.getMinutes();
    var url = "/contents/shortstory/"+no+"/index.html";
	// var url = "http://www.sneakerbunko.jp/contents/shortstory/"+no+"/index.html";

    var div = document.getElementById("external");
    //div.orgLeft = obj.x //+ Math.floor((obj.sw - 1024) / 2) + 15;
	div.orgLeft = getWindowWidth()/2-420;
	if(getWindowWidth()<1000){div.orgLeft = 80};
    div.orgTop = obj.y //+ 135;
    div.orgWinWidth = getWindowWidth();
    div.orgWinHeight = obj.sh-60-obj.sh*0.08+115;//getWindowHeight();
    div.style.visibility = "visible";
    div.style.left = div.orgLeft + 160 + 'px';
    div.style.top = div.orgTop + 'px';
    
    var ifm = div.getElementsByTagName("iframe")[0];
    ifm.src = url;
    ifm.style.width = "700px";
    ifm.style.height = div.orgWinHeight-235+'px';
    ifm.focus();
	
}



function closeExternalWindow() {
    var div = document.getElementById("external");
    var ifm = div.getElementsByTagName("iframe")[0];
    div.style.visibility = "hidden";
    ifm.style.width = "0";
    ifm.style.height = "0";	
    ifm.src = "ttp://www.sneakerbunko.jp/swf/blank.html";
}

function fixFramePosition() {
    var div = document.getElementById("external");
    var ifm = div.getElementsByTagName("iframe")[0];

    var offset_x = getWindowWidth() - div.orgWinWidth;
    var offset_y = getWindowHeight() - div.orgWinHeight;

    var div_left = div.orgLeft + Math.floor(offset_x/2);
    var ifm_height = ifm.orgHeight + offset_y;
    
    if(!div_left) { div_left = 0; }
    if(!ifm_height) { ifm_height = 0; }
    
    div.style.left = div_left + "px";
    ifm.style.height = ifm_height + "px";
}

function getWindowWidth() {
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
    return w;
}
function getWindowHeight() {
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    return h;
}


