
var photobox_dicts=new Array();
var photobox_index=0;

var photobox_urls=new Array();
var photobox_names=new Array();

var photobox_sorted_dicts=new Array();
var photobox_flag_all=false;
var photobox_max=0;

function loadFriends(){
    var i=0;
    photobox_urls[i]="http://itools.jp/~sakura/pb/";photobox_names[i]="さくら";++i;
    photobox_urls[i]="http://homepage.mac.com/happy_site/PhotoBox/";photobox_names[i]="happyqoochan";++i;
    photobox_urls[i]="http://homepage.mac.com/tkoike/pb/";photobox_names[i]="tkoike";++i;
    photobox_urls[i]="http://homepage.mac.com/osawa1103/pb/";photobox_names[i]="osawa1103";++i;
    photobox_urls[i]="http://homepage.mac.com/tdonishi/pb/";photobox_names[i]="てくっち";++i;
    photobox_urls[i]="http://www.m-sis.com/~edge/";photobox_names[i]="シエホ";++i;
    photobox_urls[i]="http://ayu.sub.jp/pb/";photobox_names[i]="ayucicca";++i;
    photobox_urls[i]="http://masato-j.com/pb/";photobox_names[i]="Masato";++i;
    photobox_urls[i]="http://homepage.mac.com/djkaz/pb2/";photobox_names[i]="DJ-Kaz";++i;
    photobox_urls[i]="http://homepage.mac.com/a_shimomoto/pb/";photobox_names[i]="shimo";++i;
    photobox_urls[i]="http://chesu.to/~ham/pb/";photobox_names[i]="ham";++i;
    photobox_urls[i]="http://taicho.orz.ne.jp/";photobox_names[i]="たいちょ";++i;
    photobox_urls[i]="http://homepage.mac.com/mhashi/pb/";photobox_names[i]="mhashi";++i;
    photobox_urls[i]="http://homepage.mac.com/yamamoto2000/pb/";photobox_names[i]="yamamoto2000";++i;
    photobox_urls[i]="http://homepage.mac.com/tnakamula/pb/";photobox_names[i]="Yossix";++i;
    photobox_urls[i]="http://homepage.mac.com/pismo_1968/pb/";photobox_names[i]="Pismo512MB";++i;
    photobox_urls[i]="http://members.jcom.home.ne.jp/yous-kay/pb/";photobox_names[i]="covusuke";++i;
    photobox_urls[i]="http://homepage.mac.com/brownshoes/woi/";photobox_names[i]="wettshirts";++i;
    photobox_urls[i]="http://www.k3.dion.ne.jp/~indigo/pb/";photobox_names[i]="takuya";++i;
    photobox_urls[i]="http://homepage.mac.com/ashind/pb/";photobox_names[i]="秋人";++i;
    photobox_urls[i]="http://homepage.mac.com/kazue147/pb/";photobox_names[i]="shamal";++i;
    photobox_urls[i]="http://homepage.mac.com/ikkoh1/pb/";photobox_names[i]="ikkoh";++i;
    photobox_urls[i]="http://cave.under.jp/_pb/";photobox_names[i]="pinut";++i;
    photobox_urls[i]="http://gon6.sakura.ne.jp/PB/";photobox_names[i]="gon6";++i;
    photobox_urls[i]="http://homepage.mac.com/gon_iii/PhotoBox/";photobox_names[i]="Gon-III";++i;
    photobox_urls[i]="http://homepage.mac.com/marinodive/pb/";photobox_names[i]="marino";++i;
    photobox_urls[i]="http://homepage.mac.com/naoki_k_e/pb/";photobox_names[i]="くりぞ";++i;
    photobox_urls[i]="http://www.m-sis.com/~nail/pb/";photobox_names[i]="nail";++i;
    photobox_urls[i]="http://homepage.mac.com/murozo/pb/";photobox_names[i]="murozo";++i;

    for(i=0;i<photobox_urls.length;++i)	loadInfo(photobox_urls[i]);
}
function loadInfo(top){
    document.write('<'+'script type="text/javascript" src="'+top+'info.js"></script'+'>');
    document.write('<'+'script type="text/javascript" src="http://color.digichrome.org/friends-append.js"></script'+'>');  
}


function htmlStringFromDict(dict)
{
	if(photobox_flag_all){
		return "<div class=\"allfriends_item\">\n<h2>"+dict["name"]+"</h2>\n<p class=\"photo\"><a href=\""+dict["top"]+"\"><img src=\""+dict["image"]+"\" alt=\""+dict["name"]+" "+date(dict["date"])+"\" title=\""+dict["name"]+" "+date(dict["date"])+"\" width=\"120\" height=\"90\" /></a></p>\n<p class=\"information\">"+date(dict["date"])+"</p>\n</div>\n";
	}else{
		return "<div class=\"friends_item\" align=\"right\">\n<p class=\"photo\"><a href=\""+dict["top"]+"\" >"+date(dict["date"])+"<br />"+dict["name"]+"</a></p>\n</div>";
	}
}
function buildFriendsArea(max)
{
	if(max==0){
		photobox_flag_all=false;
		photobox_max=7;
	}else{
		photobox_flag_all=true;
		photobox_max=max;
	}
    
    var emptyDict=new Array();
    emptyDict["top"]="javascript:void(0);";
    emptyDict["image"]="http://color.digichrome.org/pbimg/loading.png";
    emptyDict["name"]="Loading...";
    emptyDict["date"]="000000000000";
    
    for(i=0;i<photobox_max;++i){
        document.write("<div id='friends_item_"+(i)+"'>");
        document.write(htmlStringFromDict(emptyDict));
        document.write("</div>");
    }
}
function friendsLoaded(idx)
{
	var insertIndex=-1;
	for(i=0;i<photobox_sorted_dicts.length;++i){
		if(compare(photobox_dicts[idx],photobox_sorted_dicts[i])>0){
			insertIndex=i;
			break;
		}
	}
	if(insertIndex==-1) insertIndex=photobox_sorted_dicts.length;
	for(i=photobox_sorted_dicts.length;i>insertIndex;--i){
		photobox_sorted_dicts[i]=photobox_sorted_dicts[i-1];
	}
	photobox_sorted_dicts[insertIndex]=photobox_dicts[idx];
	
	
	
    for(i=insertIndex;i<Math.min(photobox_sorted_dicts.length,photobox_max);++i){
		document.getElementById("friends_item_"+(i)).innerHTML=htmlStringFromDict(photobox_sorted_dicts[i]);
    }
}


/////////////////////////////////////////////////////////////////////

function year(date){	return (""+date).substr(0,4);}
function month(date){	return (""+date).substr(4,2);}
function day(date){		return (""+date).substr(6,2);}
function hour(date){	return (""+date).substr(8,2);}
function minute(date){	return (""+date).substr(10,2);}

function compare(a,b){	return (a["date"]-b["date"]);}
function date(date){//do not remove
    return ""+year(date)+"/"+month(date)+"/"+day(date)+" "+hour(date)+":"+minute(date);
}

/////////////////////////////////////////////////////////////////////

function intelligentOpen(file,openType){
    if( openType == 'Photo' ){
        window.open(file, openType, "toolbar=no,status=no,menubar=no");
    }
    else if( openType == 'Movie' ){
        window.open(file, openType, "toolbar=no,status=no,menubar=no,width=400,height=300");
    }
    else if( openType == 'Audio' ){
        window.open(file, openType, "toolbar=no,status=no,menubar=no,width=400,height=64");
    }
}

