var timer;
var show;
var hide;
var counter;
////////////////////////////////
var slideTextTimer;
var slideTextTimerFlag=true;
var marginTop=0;
////////////////////////////////
var slideNewsTimer;
var slideNewsFlag=true;
var newsMarginTop=0;
////////////////////////////////
var slidePrjTimer;
var slidePrjFlag=true;
var prjMarginTop=0;
////////////////////////////////
var lastProjectImg=1;

function onLoad()
{
	 startSlideShow();
	 
	slideWhy('why');

	slideNews('news');

	slidePrj('prj');

}
function showBuyText(buyText)
{
	var i = 1;
	var id = 'buy_text_'+i;
	while(document.getElementById(id) != null)
	{
		document.getElementById(id).className = 'buy_text_hidden';
		i++;
		id = 'buy_text_'+i;
	}
	document.getElementById(buyText).className = 'buy_text_visible';
}
function changeProjectImg(imgNum)
{
	document.getElementById('project_img_'+lastProjectImg).className='project_img_hidden';
	lastProjectImg=imgNum;
	document.getElementById('project_img_'+lastProjectImg).className='project_img';
}
function showProjectImgs()
{
	document.getElementById('thumb_selector2').className='thumb_selector';
	document.getElementById('thumb_selector1').className='thumb_selector_selected';

	document.getElementById('thumbs_plan_container').style.display='none';
	document.getElementById('thumbs_img_container').style.display='inline-block';
	
}
function showProjectPlans()
{
	document.getElementById('thumb_selector1').className='thumb_selector';
	document.getElementById('thumb_selector2').className='thumb_selector_selected';

	document.getElementById('thumbs_img_container').style.display='none';
	document.getElementById('thumbs_plan_container').style.display='inline-block';
}
function startSlideShow()
{
	show=2;
	hide=1;
	counter=0;
	setTransparency();
}

function setTransparency()
{
	var t_show='action_img_'+show;
	var t_hide='action_img_'+hide;
	document.getElementById(t_show).style.opacity=counter/100;
	document.getElementById(t_show).style.filter= 'alpha(opacity=' + counter + ')';
	document.getElementById(t_hide).style.opacity=(100-counter)/100;
	document.getElementById(t_hide).style.filter= 'alpha(opacity=' + (100-counter) + ')';
	counter+=10;
	if(counter<=100)
	{	
		timer=setTimeout("setTransparency()",200);
	}
	else
	{
		counter=0;
		show++;
		hide++;
		t_show='action_img_'+show;
		t_hide='action_img_'+hide;
		if(document.getElementById(t_show) == null)show=1;
		if(document.getElementById(t_hide) == null)hide=1;
		timer=setTimeout("setTransparency()",5000);
	}
}






var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

function slideWhy(id)
{
	var height= document.getElementById(id).offsetHeight;
	if(slideTextTimerFlag)
	{
	document.getElementById(id).style.marginTop=marginTop+'px';
	marginTop-=1;
	if(marginTop<-height)marginTop=document.getElementById(id+'_container').offsetHeight;
	}
	slideTextTimer=setTimeout("slideWhy('"+id+"')",50);
	
}
function stopWhy()
{
	slideTextTimerFlag=false;
}
function resumeWhy()
{
	slideTextTimerFlag=true;
}

function slidePrj(id)
{
	var height= document.getElementById(id).offsetHeight;
	if(slidePrjFlag)
	{
	document.getElementById(id).style.marginTop=prjMarginTop+'px';
	prjMarginTop-=1;
	if(prjMarginTop<-height)prjMarginTop=document.getElementById(id+'_container').offsetHeight;
	}
	slidePrjTimer=setTimeout("slidePrj('"+id+"')",50);
	
}
function stopPrj()
{
	slidePrjFlag=false;
}
function resumePrj()
{
	slidePrjFlag=true;
}

function slideNews(id)
{
	var height= document.getElementById(id).offsetHeight;
	if(slideNewsFlag)
	{
	document.getElementById(id).style.marginTop=newsMarginTop+'px';
	newsMarginTop-=1;
	if(newsMarginTop<-height)newsMarginTop=document.getElementById(id+'_container').offsetHeight;
	}
	slideNewsTimer=setTimeout("slideNews('"+id+"')",50);
	
}
function stopNews()
{
	slideNewsFlag=false;
}
function resumeNews()
{
	slideNewsFlag=true;
}

///////////////////////////////////////////// Project ////////////////////////////////////////////////////////////


function closeShow()
{
	document.getElementById('opac').style.display='none';
	document.getElementById('opac_container').style.display='none';
}
function openShow()
{
	document.getElementById('opac').style.display='inline-block';
	document.getElementById('opac_container').style.display='inline-block';
}
////////////////////////////////////////// Ajax /////////////////////////////////////

var xmlhttp;
function imgRequest(prjNum, imgName)
{
var url='responseImg.php?type=ajax&cmd=imgReq&prjNum='+prjNum+'&imgName='+imgName;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		return;
	}
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		if(xmlhttp.responseText != 'false')
		{
			openShow();
			var itemContainer = document.getElementById('opac_img_container');
			itemContainer.innerHTML = '';
			itemContainer.innerHTML = xmlhttp.responseText;
			xmlhttp=NULL;
		}
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}