var isLandscape;

$(document).ready(function(){

	//ウェブフォント読込時間を考慮したローディング処理等
	
	//イベントの設定
	
	//リサイズイベント
	window.onresize = onWindowResized;

	//ローテーションチェンジのイベント設定
    if( getDeviceType() != false )
    {
        //document.addEventListener("touchmove", onTouchMove, false);
        document.body.onorientationchange = onOrientationChanged;
		onOrientationChanged();
	}
	else
	{
		onWindowResized();	
	}

	//その他実行したい処理
	setDomPosition("div.roundRectS","#articleListSection",18,"#articleListSection");
});

/*
 * INIT onload
 */
function onloaded()
{
	//ローテーションチェンジのイベント設定
    if( getDeviceType() != false )
    {
        document.body.onorientationchange = onOrientationChanged;
		onOrientationChanged();
	}

}


/*
 * ORIENTATION CHANGED
 */
function onOrientationChanged()
{
	if(getDeviceType()!=false)
    {
        window.scrollTo(0,0);
        var orient = ( Math.abs(window.orientation) === 90 ) ? 'landscape' : 'portrait';
        isLandscape = (orient == 'landscape')?true:false;
        orient+=getDeviceType();
        document.body.className = orient;
		
		onWindowResized();
    }
}

/*
 * SET DOM POSITION
 */
function setDomPosition(
	_targetDomQuery, 
	_targetDomParentQuery,
	_m,
	_parentDomQuery
	)
{
		var doms = $(_targetDomQuery,_targetDomParentQuery);
		
		var len = doms.length;
		var lmax=0;
		var rmax=0;
		for(var i = 0; i < len; i++)
		{
			var dom = $(doms[i]);
			dom.css("position", "absolute");

			//偶数
			if(i%2)
			{
				dom.css("right", "0px");
				if(rmax!=0)
				{
					rmax += 10+_m;
				}
				dom.css("top", rmax+"px");
				rmax += dom.height();
			}
			//奇数
			else
			{
				dom.css("left", "0px");
				if(lmax!=0)
				{
					lmax += 10+_m;
				}
				dom.css("top", lmax+"px");
				lmax += dom.height();
			}
		}
//		alert(rmax + " : " + lmax);
		var h = Math.max(rmax, lmax)+_m+10;
		$(_parentDomQuery).css("height", h+"px");
}

/*
 * WINDOW RESIZE
 */
function onWindowResized()
{
	/*
	var w = "d.width: " + $(document).width() +"<br>";
	w += "d.height: " + $(document).height() +"<br>";
	w += "w.width: " + $(window).width() +"<br>";
	w += "w.height: " + $(window).height();
*/
	var ww = $(window).width();
	var str="";

	if( ww >= 930)
	{
		str = "c930";
		$("#bside").css("height", "");
		$("#footerBody").css("height", "");
	}
	else if(ww >= 610 && 929 >= ww)
	{
		str = "c610";
		
		//ここで対象のアイテムのCSSを操作
		setDomPosition("div.roundRectS","#articleListSection",18,"#articleListSection");
		setDomPosition("div.insidebox","#bside",8,"#bside");
		setDomPosition("div.roundRectInset","#footerBody",28,"#footerBody");
	}
	else
	{
		str = "c300";
		$("#footerBody").css("height", "");
	}
	$("#page").attr("class", str);
	/*
	w += "<br>Class: "+str;
	$("#debug").html(w);
	*/
}
