//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
//*********************************************************************************************************
//	Functions for image gallery
//*********************************************************************************************************
function next_image()
{
	if(current_img >= total_images )
	{
		// at end stop and make link gray
		//current_img	= 	total_images;
		//document.getElementById('next_link').src = '/images/next0.gif';
		//reached_end = true;

		// at end go to first
		current_img	= 1;
	
	}
	else
	{
		current_img	++;
	}

	// if the first image  was reached when clicking on the prev btn, reactivate the next image
	if( reached_first )
	{
		document.getElementById('prev_link').src = '/images/prev.gif';
	}
	
	img		=	'image_' + current_img;
	
	show_image(img);

}

function prev_image()
{
	if(current_img == 1)
	{
		// if this is the first image, stay there and make link gray.
		//current_img	= 	1;	
		//document.getElementById('prev_link').src = '/images/prev0.gif';
		//reached_first = true;

		// if this is the first image, to to the last image
		current_img	= total_images	;	
	}
	else
	{
		current_img	--;
	}

	// if the end was reached when clicking on the next btn, reactivate the next image
	if( reached_end )
	{
		document.getElementById('next_link').src = '/images/next.gif';
	}
	

	img		=	'image_' + current_img;

	show_image(img);
}
//*********************************************************************************************************
//	End Functions for image gallery
//*********************************************************************************************************

//*********************************************************************************************************
//	scrolling div functionality
//*********************************************************************************************************
// var for storing the current position.

// function to load scrollable. If the scrollable area needs a scroll up / down button. then show the scrollable button. 
	var top_of_div		  = 0;
	
	// if you change this u should als ochange height of div inside scrollable_div 
	var scrollarea_height = 261;
	var keep_scrolling = 0;
function load_scrollable()
{
	try
	{
		scroll_area = document.getElementById('scrollable_area');
		
	//alert(' scroll area = '+ scroll_area.clientHeight);
		//alert('scroll area '+ scroll_area.clientHeight + '  scrollarea height'+ scrollarea_height);
		if(scroll_area.clientHeight > scrollarea_height )
		{
			document.getElementById('scrollable_move_down').style.visibility = ''; 
			//document.getElementById('scrollable_move_up').style.visibility	= ''; 
		}
		
	}
	catch (err)
	{
		alert(err);
	}

}


function move_up_down(direction)
{
	keep_scrolling = 1;
	//scroll_area = document.getElementById('scrollable_area');

	//alert(printProps(this,'button'));
	var move_by = 70;
	var move_up	= document.getElementById('scrollable_move_up');
	var move_down = document.getElementById('scrollable_move_down');

	if( direction == 'up')
	{
		top_of_div += move_by;
		
		if( top_of_div >= 0)
		{
			top_of_div = 0;
			move_up.style.visibility = 'hidden';
		}
			move_down.style.visibility = 'visible';
	}	
	else if(direction == 'down' )
	{
		top_of_div -= move_by;
		var bottom = (scroll_area.clientHeight- scrollarea_height ) * -1;	
		
		if( top_of_div <= bottom )
		{
			top_of_div = bottom;
			move_down.style.visibility = 'hidden';
		}	
			move_up.style.visibility = 'visible';	
	}
	scroll_area.style.top = top_of_div + 'px';	
}

//	Scroll to a particular object
function scrollToObj(id)
{
	obj = document.getElementById(id);
	scroll_area = document.getElementById('scrollable_area');
	
	var top_of_div = findtop(obj);
	var diff = parseInt(top_of_div) + parseInt(scroll_area.style.top);
	//alert('scroll area top= '+scroll_area.style.top +"\n"+'top of div = '+top_of_div+"\n"+diff );
	
	if( diff < 0 )
	{
		scroll_area.style.top = '-' + top_of_div + 'px';
		
	}
	load_scrollable();
}

//	Find Position of element
function findtop(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		curtop = obj.offsetTop
	}
	return [curtop];
}


//*********************************************************************************************************
//	end scrolling div functionality
//*********************************************************************************************************

// debug func to show props of obj
function  printProps(obj, objName) {
  var output = "" ;
  for (var prop in obj) {
    output += objName + "." + prop + " = " + obj[prop] + "\n</br>" ;
  //  output += objName + "." + prop + " = " + obj[prop] + "\n" ;
  }

  return output ;
}

//---------------------------------------------------------------------------------------------------------
//	js function for dropdown contact us
 //---------------------------------------------------------------------------------------------------------
	function check_other(obj)
	{
		
		var hear_about_us_div = document.getElementById('hear_about_us_other');
		var other = document.getElementById('other');

		if( obj.options[obj.selectedIndex].value == 'Other' )
		{
			if( other.value == "n/a" )
			{
				other.value = "";
			}	
			hear_about_us_div.style.display="";	
			other.focus();
			
		}
		else
		{
			hear_about_us_div.style.display='none';

			if( other.value == "" )
			{
				other.value = "n/a";
			}	
		}
	}