/* content scrollbar */
function scrollbar_init()
{
	xMoveTo('content-text',0,0);
	xMoveTo('content',content_left, content_top);
	xResizeTo('content',content_width, content_height);
	xMoveTo('scroll_outer',xLeft('content')+xWidth('content')+6,xTop('content'));
	xMoveTo('scroll_inner',0,0);
	xResizeTo('scroll_outer',8,content_height-10);
	xMoveTo('content_shade',content_left,content_top + content_height - 15);
	xResizeTo('content_shade',content_width,15);
	xEnableDrag('scroll_inner',false,dragger,false);
	xAddEventListener('scroll_outer','mousedown',slideme,false);
	c_height = content_height - xHeight('content-text');
	s_height = content_height - 18;
	s_factor = c_height / s_height;	
	if (c_height < 0)
	{
		xShow ('scroll_inner');
		xShow ('scroll_outer');
	}
}

function dragger(ele,x,y)
{
        content_y = y * s_factor;
        xMoveTo(ele,xLeft(ele), xTop(ele) + y);
        xMoveTo('content-text',xLeft('content-text'),xTop('content-text')+content_y);
        if (y < 0) xShow('content_shade');
        if (xTop(ele) > s_height)
        {
                xMoveTo(ele,xLeft(ele),s_height);
                xMoveTo('content-text',xLeft('content-text'),c_height);
                xHide('content_shade');
        }
        if (xTop(ele) < 0)
        {
                xMoveTo(ele,xLeft(ele),0);
                xMoveTo('content-text',xLeft('content-text'),0);
        }
}

function slideme(evt)
{
		offset = xPageY('framediv');
		if (xIE4Up) offset = offset / 2;
        if (evt && evt.clientY > content_top + xTop('scroll_inner') + offset + 20)
        {
               slide_down();
        } else if (evt && evt.clientY < content_top + xTop('scroll_inner') + offset) {
               slide_up();
        }
}


function slide_down()
{

        xMoveTo('scroll_inner',0,(xTop('content-text')-content_height+10)/s_factor);
        if (xTop('scroll_inner') > s_height)
        {
                xMoveTo('scroll_inner',0,s_height);
                xSlideTo('content-text',0,c_height,1000);
                xHide('content_shade');
        } else {
                xSlideTo('content-text',0,xTop('content-text')-content_height+10,1000);
        }
}

function slide_up()
{
        xShow('content_shade');
        xMoveTo('scroll_inner',0,(xTop('content-text')+content_height-10)/s_factor);
        if (xTop('scroll_inner') < 0)
        {
                xMoveTo('scroll_inner',0,0);
                xSlideTo('content-text',0,0,1000);
        } else {
                xSlideTo('content-text',0,xTop('content-text')+content_height-10,1000);
        }
}

/* lower section image scroller */
var moving = 1;

function bottom_scroll()
{
        pos = xLeft('bottom_images');
        if (pos < -(xWidth('bottom_images') / 2)) pos = 0;
        xLeft('bottom_images',pos - 2);
        if (moving) setTimeout('bottom_scroll()',50);
}

function stop_bottom_scroll(img)
{
    moving = 0;
	imagelist = xGetElementsByClassName('bottom_scroll_image');
	for (var i=0; i < imagelist.length; ++i)
	{
		setOp(imagelist[i],50);
	}
	setOp(img,100);
}

function start_bottom_scroll()
{
	moving=1;
	imagelist = xGetElementsByClassName('bottom_scroll_image');
	for (var i=0; i < imagelist.length; ++i)
	{
		setOp(imagelist[i],100);
    }       
	setOp('image1',100);
	bottom_scroll();
}

/* lower section people scroller */
var moving = 1;
var personshowing = 0;
var stickpeople = 0;
var highlighted_person = 0;



xLeft('people_bottom_images',0);
function people_bottom_scroll()
{
        pos = xLeft('people_bottom_images');
        if (pos < -(xWidth('people_bottom_images') / 2)) {
        		pos = 0;
        	}
        xLeft('people_bottom_images',pos - 2);
        //people_bottom_scroll();
        if (moving) setTimeout('people_bottom_scroll()',50);
}

function people_stop_bottom_scroll(person)
{
	if (!stickpeople)
	{	
   moving = 0;
   //xHide("blurb"); // leave the top blurb on the initial mouseover behavior
	xHide('bio'+personshowing);
	document.getElementById('name'+personshowing).style.color = "black";
	personshowing = person;
	document.getElementById('name'+person).style.color = "#0a509b";
	setOp('image'+person,100);
	setOp('image'+person+"a",100);
	setOp('imagex'+person,100);
	xShow('bio'+person);
	
	}
}


function highlight_person(person)
{
	xHide("blurb");
	imagelist = xGetElementsByClassName('bottom_scroll_image');
	for (var i=0; i < imagelist.length; ++i)
	{
		setOp(imagelist[i],50);
   } 
   moving = 0;
	xHide('bio'+personshowing);
	document.getElementById('name'+personshowing).style.color = "black";
	personshowing = person;
	document.getElementById('name'+person).style.color = "#0a509b";
	setOp('image'+person,100);
	setOp('image'+person+"a",100);
	setOp('imagex'+person,100);
	xShow('bio'+person);
}

function people_start_bottom_scroll()
{
	if (!stickpeople)
	{
	moving=1;
	//xHide('bio'+personshowing);
	document.getElementById('name'+personshowing).style.color = "black";
	imagelist = xGetElementsByClassName('bottom_scroll_image');
	for (var i=0; i < imagelist.length; ++i)
	{
		setOp(imagelist[i],50);
    } 
	people_bottom_scroll();
	}
}

function stick_people(person)
{
	stickpeople = 1;
	//alert(xOffsetLeft('imagediv'+person));
	if (xOffsetLeft('imagediv'+person) > 0) xSlideTo('people_bottom_images',- (xOffsetLeft('imagediv'+person) - 300),0,1500);
	highlight_person(person);
}



/* project navigation functions */

var ps = 1;



function stickme(section)
{
	if (!ps)
	{
		window.location = "projectsub.php?nav=" + section;
		//return false;
	}
	ps = 0;
	content_display = xInnerHtml("proj_" + section + "_content");
	xInnerHtml('content-text',content_display);	


	if (section != 'homeren')
	{
		xMoveTo('proj_homeren',309,170);
		xSlideTo('proj_homeren',309,436,1000);
		setTimeout("xSlideTo('proj_homeren',234,436,1000)",1050);
	}

	if (section != 'newres')
	{
		xMoveTo('proj_newres',309,140);
		xSlideTo('proj_newres',309,436,1000);
		setTimeout("xSlideTo('proj_newres',73,436,1000)",1050);
	}

	if (section != 'kitchens')
	{
		xMoveTo('proj_kitchens',309,200);
		xSlideTo('proj_kitchens',309,436,1000);
		setTimeout("xSlideTo('proj_kitchens',412,436,1000)",1050);
	}

	if (section != 'clubhouses')
	{
		xMoveTo('proj_clubhouses',309,230);
		xSlideTo('proj_clubhouses',309,436,1000);
		setTimeout("xSlideTo('proj_clubhouses',522,436,1000)",1050);
	}
	if (section != 'bs')
	{
		xMoveTo('proj_bs',309,260);
		xSlideTo('proj_bs',309,436,1000);
		setTimeout("xSlideTo('proj_bs',650,436,1000)",1050);
	}
	scrollbar_init();
	scrollbar_init();
}





function proj_subload(proj,id)
{
	xMoveTo('yablock',240,67);
	xSlideTo('yablock',240,454,1000);
	setTimeout("window.location='projectsub.php?nav=" + proj + "&subnav=" + id + "'",1050);
}

function proj_transition(subnav)
{
	xSlideTo('subnav'+sub,0,subpos,1000);
	setTimeout("window.location='projectsub.php?nav=" + nav + "&subnav=" + subnav + "'",1100);
}
	

	




/* opacity functions */
function getOp(obj)     { 
tempobj=xGetElementById(obj); 
if (tempobj.filters) { return tempobj.filters.alpha.opacity } 
else if (tempobj.style.opacity) { return tempobj.style.opacity * 100; } 
else if (tempobj.style.MozOpacity) { return tempobj.style.MozOpacity * 100; } 
}
function setOp(objname, opacity) { 
obj = xGetElementById(objname); 
if (obj) {
	opacity = (opacity == 100)?99.999:opacity; 
	obj.style.filter = "alpha(opacity:"+opacity+")"; 
	obj.style.KHTMLOpacity = opacity/100; 
	obj.style.MozOpacity = opacity/100; 
	obj.style.opacity = opacity/100; 
}
}


/* soopa rollovers */
function soopaSetup() {
	var img, sh, sn, sd
	for (var i = 0; (img = document.images[i]); i++) {
		if (img.getAttribute) {

			sn = img.getAttribute("src");
			sh = img.getAttribute("hsrc");
			sd = img.getAttribute("dsrc");

			if (sn != "" && sn != null) {
				img.n = new Image();
				img.n.src = img.src;
			
				if (sh != "" && sh != null) {
					img.h = new Image();
					img.h.src = sh;
					img.onmouseover = soopaSwapOn
					img.onmouseout  = soopaSwapOff
				}

				if (sd != "" && sd != null) {
					img.d = new Image();
					img.d.src = sd;
					img.onmousedown = soopaSwapDown
				}
			}
		}
	}
}

function soopaSwapOn() {
	this.src = this.h.src;
}

function soopaSwapOff() {
	this.src  = this.n.src;
}

function soopaSwapDown() {
	this.src  = this.d.src;
	this.temp = typeof(document.onmouseup) != 'undefined' && typeof(document.onmouseup) != 'unknown' ? document.onmouseup : "";
	soopaSwapUp.img = this;
	document.onmouseup = soopaSwapUp;
}

function soopaSwapUp() {
	var ths = soopaSwapUp.img;
	ths.src = ths.n.src;
	if (ths.temp) document.onmouseup = ths.temp;
}

function pxShow(id) {
	content_id = "proj_" + id + "_content";
	nav_id = "proj_" + id + "_subnav";
	content_display = xInnerHtml(content_id);
	xInnerHtml('content-text',content_display);
	scrollbar_init();
	scrollbar_init();	
	xHide('proj_newres_subnav');
	xHide('proj_homeren_subnav');
	xHide('proj_kitchens_subnav');
	xHide('proj_clubhouses_subnav');
	xHide('proj_bs_subnav');					
	xShow(nav_id	);
}
	
	
