var items = new Array();
var subjects = new Array();
var clients = new Array();
var links = new Array();
var publishDates = new Array();
var locations = new Array();
var photomains = new Array();
var thumphotos = new Array();
var photos = new Array();
var descriptions = new Array();
var length;


  //送信用関数 loadPortfolio
  function loadPortfolio(url)
  {
    sendRequest(onLoadPortfolio,'','GET',url,true,true);
  }

	//コールバック関数 onLoadPortfolio
  function onLoadPortfolio(oj)
  {
    //responseXMLでレスポンスを取得
    var xdoc  =  oj.responseXML;
    items = xdoc.getElementsByTagName('item');
    subjects = xdoc.getElementsByTagName('subject');
    clients = xdoc.getElementsByTagName('client');
    linkhrefs = xdoc.getElementsByTagName('linkurl');
    publishDates = xdoc.getElementsByTagName('published');
    locations = xdoc.getElementsByTagName('location');
    photomains = xdoc.getElementsByTagName('photomain');
    thumphotos = xdoc.getElementsByTagName('thumphoto');
    photos = xdoc.getElementsByTagName('photo');
    descriptions = xdoc.getElementsByTagName('description');
    length = items.length;


		//サムネイル出力
		var pibot = 0;
		var thmb = '';

    for(var i=0; i<length; i++){

			//制作年
    	var year = publishDates[i].firstChild.nodeValue.substring(0,4);

			//初回のピボット計算
    	if(i==0){
    		if(year%5 ==0){
    			pibot = year -5;
    		}
    		else{
    			pibot = year - (year%5);
    		}
    		//年の出力
	    	thmb += '<div class="contentYears"><p>'+year+'</p></div>';
	    	thmb += '<ul>';
    	}
    	else if(year<=pibot){
    		//年の出力
    		pibot = Math.ceil(year/5)*5
    		thmb += '</ul><div class="clear"></div>';
    		thmb += '<div class="contentYears"><p>'+pibot+'</p></div>';
    		thmb += '<ul>';
    		pibot -= 5;
    	}
    	
	    
	    var img;
	    var imgAttirbutes;
	    
	    if(photomains[i].firstChild!=null){
	    	//img = <img />
	    	img = photomains[i].firstChild.nodeValue;
	    	//attribete取り出し
	   		imgAttirbutes = getSourceAttribute(img);
	    }
	    
	    
	    if(thumphotos[i].firstChild!=null){
	    	//img = <img />
	    	img = thumphotos[i].firstChild.nodeValue;
	    	//attribete取り出し
	    	if(img!=null&&img!=''){
		   		imgAttirbutes = getSourceAttribute(img);
		   	}
	    }

	    //parmalink = <link />
	    var linkhref = linkhrefs[i].firstChild.nodeValue;
	     if(thumphotos[i].firstChild!=null || photomains[i].firstChild!=null){
	        	thmb+='<li>'+'<a href="'+ linkhref +'" onmouseover="javascript:showSammary('+i+');" onmouseout="javascript:showSammary(\'off\');" style="text-align:center; overflow:hidden;"><img src="'+imgAttirbutes["src"]+'" height="48px"></a></li>';
	    }else{
	    			thmb+='<li>'+'<a href="'+ linkhref +'" onmouseover="javascript:showSammary('+i+');" onmouseout="javascript:showSammary(\'off\');"><img src="/images/noimage.gif" width="70px" height="48px"></a></li>';
	    }
    }
    thmb += '</ul><div class="clear"></div>';
    //alert(thmb);

    document.getElementById('contentThmb').innerHTML = thmb;
    initSc();
    
    
  }

  function showSammary(n){
  	var title = '<h1></h1><p></p>';
  	var year = '<em></em>';
  	var location = '';
  	var description = '<p></p>';
  	if(n!='off'){
	    title = '<h1>'+subjects[n].firstChild.nodeValue+'</h1>'+
  		'<p><span class="fontSizeSmall">'+clients[n].firstChild.nodeValue+'</span></p>';
  		year = '<em><span class="fontSizeSmall">'+publishDates[n].firstChild.nodeValue.substring(0,4)+'</span></em>';
  		location = '<span class="fontSizeSmall">'+locations[n].firstChild.nodeValue+'</span>';
  		/*
  		if(descriptions[n].firstChild != null){
  		description = '<p style="color:#fff;">'+descriptions[n].firstChild.nodeValue+'</p>';
  		}
  		*/
  	}
  		document.getElementById('projInfo').innerHTML = title;
  		document.getElementById('projYear').innerHTML = '<p>'+ year +'&nbsp;&nbsp;'+ location +'</p>';
  		//document.getElementById('projDescript').innerHTML =  description ;
  		new Effect.Appear('projInfo', { from: 0, duration: 0.4 });
  		new Effect.Appear('projYear', { from: 0, duration: 0.4 });
  		//new Effect.Appear('projDescript', { from: 0, duration: 0.4 });
  }


	function getSourceAttribute(str){
			
		//文字列から["]を削除
		var searchStr = '\"';
		var replaceStr = '';
		var re = new RegExp(searchStr,"g");
		var result = str.replace(re,replaceStr);
		
		result = result.substring(1,str.length-2);
		//alert(result);
		temp = result.split(" ");
		//alert(temp[1]);
		atr = new Array();
		var attributeArr = new Array();
		for(i=0; i<temp.length; i++){
			atr[i] = temp[i].split("=");
			attributeArr[atr[i][0]] = atr[i][1];
		}
		//alert(attributeArr["width"]);
		return attributeArr;
	}
