$(document).ready(
	function()
	{
		// Shows the full bio for a sitter
		$('a.read_more').live('click', function(e)
		{
			e.preventDefault();
			$('#short_bio').hide();
			$('#bio_more').hide();
			$('#bio_hide').show();
		});

		// Format the care type Attributes section into distributed columns
		$('#ct_attributes h3').addClass('dontend');
		$('#ct_attributes li:not(:last-child)').addClass('dontend');
		$('#ct_attributes').columnize({columns:3});

		// Ajaxify the caretype tabs
		$('.profile_ct_tabs a').live('click', function(e)
		{
			e.preventDefault();

			$('ul.profile_ct_tabs li').removeClass('current');
			$(this).parent('li').addClass('current');

			var base = $('meta[name=base]').attr('content');
			var href = $(this).attr('rel');
			$('.pane_ct_content').fadeOut(
				'slow',
				function()
				{
					$('.pane_ct_content').html('<img src="/static/img/ajax-loader.gif" alt="loading..." class="ajax_loader" />');
					$('.pane_ct_content').fadeIn('fast');
					$.ajax(
					{
						url: base+href,
						success: function(data)
						{
							$('.pane_ct_content').fadeOut(
								'fast',
								function()
								{
									$('.pane_ct').html(data.left);
									$('.pane_ct_content').hide();
									var heading = data.heading;
									var html_heading = '<h1>'+heading.heading+'<span>'+heading.subheading.span+'.</span></h1><h2>'+heading.subheading.main+'</h2>';
									$('.header_name').html(html_heading);
									$('.pane_ct_content').fadeIn('slow');
								}
							);
						}
					});
				}
			);
		});
	}
);

/*
	swapPhoto()
		-Swaps the primary photo with one of the thumbnails
*/

function swapPhoto( thumbFrame )
{
	var primaryPhoto	= document.getElementById( 'primary_photo' ).getElementsByTagName( 'img' );
	var thumbPhoto		= thumbFrame.getElementsByTagName( 'img' );
	var thumbnails		= document.getElementById( 'thumbnails' ).getElementsByTagName( 'li' );

	for( var i = 0; i < thumbnails.length; i++ )
	{
		if( thumbnails[ i ].className.indexOf( 'frame_selected' ) != -1 )
		{
			thumbnails[ i ].className = 'frame_sm';
		}
	}

	thumbFrame.className = 'frame_sm frame_selected'
	primaryPhoto[0].src = thumbPhoto[0].src;
	prepXlResultPhotos( primaryPhoto[0] );
}

/*
	scrollProfileThumbs()
		-Scroll between sets of thumbnails
*/

function scrollProfileThumbs( direction )
{
	var thumbContainer 	= document.getElementById( 'thumbnails' );
	var maxScroll		= parseInt( document.getElementById( 'thumb_scroll_max' ).value );
	var curPosition		= parseInt( document.getElementById( 'thumb_scroll_cur' ).value );
	var prevLink		= document.getElementById( 'thumb_prev' );
	var moreLink		= document.getElementById( 'thumb_next' );

	if( direction == "right" )
	{
		thumbContainer.style.top = ( curPosition - 70 ) + "px";
		document.getElementById( 'thumb_scroll_cur' ).value = curPosition - 70;
	}
	else if( direction == "left" )
	{
		thumbContainer.style.top = ( curPosition + 70 ) + "px";
		document.getElementById( 'thumb_scroll_cur' ).value = curPosition + 70;
	}

	curPosition = parseInt( document.getElementById( 'thumb_scroll_cur' ).value );

	if( curPosition + maxScroll == 0 )
	{
		moreLink.className = "disabled";
		moreLink.onclick = '';
	}
	else
	{
		moreLink.className = '';
		moreLink.onclick = function() { scrollProfileThumbs( 'right' ); };
	}

	if( curPosition == 0 )
	{
		prevLink.className = "disabled";
		prevLink.onclick = '';
	}
	else
	{
		prevLink.className = '';
		prevLink.onclick = function() { scrollProfileThumbs( 'left' ); };
	}

}

/*
validateReportForm()
	-When blocking or reporting a sitter, ensure that at least one checkbox is selected
*/

function validateReportForm(form)
{
var reportBox		= document.getElementById( 'report_block_lightbox' );
var reportInputs	= reportBox.getElementsByTagName( 'input' );
var reportForm		= form
var valid			= false;

for( var i = 0; i < reportInputs.length; i++ )
{
	if( reportInputs[i].type == 'checkbox' )
	{
		if( reportInputs[i].checked == true )
		{
			valid = true;
		}
	}
}

if( valid )
{
	reportForm.submit();
}
else
{
	alert( 'Please select an option before submitting, or click "cancel" if you no longer wish to block or report this sitter.' );
}

}

function unlockPhoneNumber()
{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
		xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	    document.getElementById("phone").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET","http://local.integration.sittercity.com/babysitters/il/chicago/406967/unlockphone.html",true);
	xmlhttp.send();
	return false;
}


