$(document).ready(function () {
// --onload
$('#content')[0].scrollTop = 0;
window.scrollTop = 0;
document.scrollTop = 0;

$('#navigation-items > li > a').hover(
	function () {
		$(this).animate({backgroundColor: '#5D2524'}, 300);
	},
	function () {
		$(this).stop().css({backgroundColor: '#350B16'});
	}
).css({backgroundColor: '#350B16'});

$.ui.accordion.animations.easeOut = function(options) {
	this.slide(options, {
		easing: "easeOutCubic",
		duration: 650
	});
};


var accordion_opts = {
	header: 'h3',
	animated: "easeOut",
	fillSpace: true
}

// if( window.location.hash.length > 0 && !( $.browser.msie && $.browser.version.split('.')[0] == 6 ) ){
if( window.location.hash.length > 0 ){
   accordion_opts.active = window.location.hash.replace('#pg-','#') + ' h3';
}

$("#content").bind("accordionchange", function(event, ui) {
	window.location.hash = '#pg-' + $(ui.newContent).parent().parent().attr('id');
});


$('#content:has(.sub-page)').accordion( accordion_opts );

//For some reason feeding the hash as the active div to the accordion plugin does not automatically show it's content div.
// if( window.location.hash.length > 0 ){
//    $(window.location.hash.replace('#pg-','#')).find('div.content').show();
// }

$("#content").bind("accordionchange", function(event, ui) {
   $(ui.newContent).css('overflow', 'auto');
});

$("#content .sub-page").css('position', 'relative');

$('.sub-page .content.text').wrapInner('<div class="scrollbarfix"></div>');


$('#phases > li > div').hide();
$('#phases > li a.phase').click( function () {
   $(this).parents('li').find('div').toggle();
   return false;
})



// Collapsable sections
var $headings = $('body:not(*)'); //Empty jQuery
//Find all the collapsable 
$('h6').each(function () {
   var  $this = $(this);
   if( $this.text().charAt(0) == '+' ) {
      var contents = $this.text();
      $this.addClass('collapse-head');
      // $this.text( contents.substring(1, contents.length) );
      $headings = $headings.add(this);
   }
});

$headings.each( function () {
   var $container = $('<div>').attr('id', 'collapsed_' + $headings.index(this)).addClass('collapse-section');
   var $this = $(this);
   var $nextElem = $(this).next();

   while( $nextElem.not('h1,h2,h3,h4,h5,h6,hr').length != 0 ) {
      $nextElem.appendTo($container);
      $nextElem = $(this).next();
   }

   $container.hide();
   $this.after($container);
   $this.click(function () {
      $container.toggle();
   });
   
});



// Footer Testimonials
$('#footer #testimonials').css('overflow','hidden').cycle({timeout: 5000, pause: true});
$('#footer .testimonial').css('cursor', 'pointer').click(function () { window.location = "http://whitneyblair.com/accolades.cfm#pg-referrals"} );


// Flash Lightbox
$('#flash-thumb').show().colorbox({inline: true, href: "#flvMovie"});



// --end onload
})

