document.createElement('header');
document.createElement('footer');
document.createElement('section');
document.createElement('article');
document.createElement('aside');
document.createElement('nav');

jQuery(document).ready(function(){
	
	$('#homepage_tout_0').mouseenter(function(e){
		e.preventDefault();
		
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image img').stop().delay(50).animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'153px', width:'262px', left:'16px', top:'16px'}, 300, 'easeOutSine', function() {  });
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
	});
	$('#homepage_tout_1').mouseenter(function(e){
		e.preventDefault();
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'153px', width:'262px', left:'16px', top:'16px'}, 300, 'easeOutSine', function() {  });
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
	});
	$('#homepage_tout_2').mouseenter(function(e){
		e.preventDefault();
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image img').stop().delay(50).animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:.3}, 950, 'easeOutExpo');
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'153px', width:'262px', left:'16px', top:'16px'}, 300, 'easeOutSine', function() {  });
		
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
	});
	
	$('#homepage_tout_0, #homepage_tout_1, #homepage_tout_2').mouseleave(function(e){
		e.preventDefault();
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:1}, 950, 'easeOutExpo');
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:1}, 950, 'easeOutExpo');
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image img').stop().animate({opacity:1}, 950, 'easeOutExpo');
		
		$('#homepage_tout_0 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
		$('#homepage_tout_1 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
		$('#homepage_tout_2 .home_tout_navigation_image .tout_cut_image').dequeue().stop().animate({ height:'136px', width:'245px', left:'24px', top:'24px'}, 400, 'easeOutExpo', function() {  });
	});
	
	$('#homepage_tout_0').click(function(e){
		e.preventDefault();
		window.location = 'specialized-programs';
	});
	$('#homepage_tout_1').click(function(e){
		e.preventDefault();
		window.location = 'about-rhi';
	});
	$('#homepage_tout_2').click(function(e){
		e.preventDefault();
		window.location = 'healthcare-professionals';
	});
	
	/*   Navigation   */
	/*$('.topNav ul li').click(function(e){
		if($(this).parents('.sub_menu').length == 0){
			e.preventDefault();
			window.location = $(this).children('a').attr('href');
		}
	});*/
	
	$('.topNav ul.sub_menu li').click(function(e){
		console.log("test");
		e.preventDefault();
		window.location = $(this).children('a').attr('href');
		
	});
	if( $('.current-menu-item .sub-menu').children().length==0 && $('.current-menu-ancestor .sub-menu').children.length==0 ) {
		console.log($('.current-menu-item .sub-menu').children().length);
		$('#header_container_sub').css('height', "35");
		$('#top_nav_container .specialized-programs_contact').css('margin-top', '0')
	}
	
	
	
	$("#page_slider_container").slides({
			container: 'page_slider',
			effect: 'fade',
			play: 5000,
			pause: 2500,
			hoverPause: true
		});
	
	/*  Specialized Programs Slider */
	$(function(){
		$('#specialized_products_slides').slides({
			preload: true,
			pagination: false,
			generatePagination: false,
			effect: 'fade',
			crossfade: true,
			preloadImage: '/wp-content/themes/rhi/images/specialized-programs/loading.gif',
			play: 8000,
			
			pause: 2500,
			hoverPause: true
		});
	});
	
	var $groupChildren = $('#li--5items').children();    
	for(var i=0, len = $groupChildren.length; i < len; i+=2){
		$groupChildren.slice(i, i+2).wrapAll('<div class="checkbox_group_wrapper"/>');
	}    
	
	$('#about_slider_nav_0').click(
		function(e) {
			e.preventDefault();
			$('#panel_0').fadeIn();
			$('#panel_1').fadeOut();
			$('#panel_2').fadeOut();
		}
	)
	
	$('#about_slider_nav_1').click(
		function(e) {
			e.preventDefault();
			$('#panel_0').fadeOut();
			$('#panel_1').fadeIn();
			$('#panel_2').fadeOut();
		}
	)
	
	$('#about_slider_nav_2').click(
		function(e) {
			e.preventDefault();
			$('#panel_0').fadeOut();
			$('#panel_1').fadeOut();
			$('#panel_2').fadeIn();
		}
	)
	
	$('#specialized_programs_nav_0, #specialized_programs_nav_1, #specialized_programs_nav_2, #specialized_programs_nav_3, #specialized_programs_nav_4, #specialized_programs_nav_5').click(
		function(e) {
			e.preventDefault();
			window.location = $(this).children("a").attr('href');
		}
	)
	
	// begin calendar stuff
	$('#cboxClose').attr('title', 'Close this event box.');
	$('#eventCheck0').click(function() {
		if ($(this).attr('checked')) {
			$('input.otherCheckboxes').attr('checked', 'checked');
			$('span.event-block').show();
		} else {
			$('input.otherCheckboxes').attr('checked', '');
			$('span.event-block').hide();
		}
	});
	// end calendar stuff
	
	$('.who_we_are_careers_button').click(
		function() {
			if(!$(this).hasClass('light_box_launch'))
				window.location = '/careers/';
		}
	);

	if($('#who_we_are_collage_wrapper img').length > 0){
		$.ajax({
			url : '/ajax-image-processor/',
			data : '',
			type : 'GET',
			cache: false,
			success : function(d){
				$('#who_we_are_collage_wrapper img').attr('src', d);
				var holders = new Array();
				for(var i=0; i < 105; i++)
					holders[i] = 'holder_' + (i + 1);
				
				holders.shuffle();
				for(var k=0; k < 105; k++){
					var $delay = randomFromTo(250, 2000);
					var $time_period =  randomFromTo(500, 3000);
					$('.' + holders[k]).delay($delay).animate({opacity: 0}, $time_period, 'easeOutQuad')
				}
			}
		});
	}
	

	$('.posts blockquote').append('<span style="margin: -28px -38px 0 0; float: right;display: block; background: url(/wp-content/themes/rhi/images/category/end_quote.png) 0 0 transparent no-repeat; width: 24px; height: 25px;"></span><div class="clr"></div>');
	$('#page_copy blockquote').append('<span style="margin: -10px -38px 0 0; float: right;display: block; background: url(/wp-content/themes/rhi/images/category/end_quote.png) 0 0 transparent no-repeat; width: 24px; height: 25px;"></span><div class="clr"></div>');

	$('a.light_box_launch').click(function(){
			thisLightbox = $(this);
			lightboxContent = $(thisLightbox).attr('rel');
			lightboxTitle = $(thisLightbox).attr('title');
			$.colorbox({inline:true, href:lightboxContent}, function(){
				$('#cboxLoadedContent').prepend('<div class="specialized_lightbox_title">' + lightboxTitle + '</div>');
				$.colorbox.resize();
			});
			
			return false;
	});
	
	leftColBg();
	
	jQuery('.the_excerpt p').each(function() {
		var excerptArray = jQuery(this).html().split("<br>",2);
		var excerptBtn = excerptArray.pop();
		if(excerptArray[0] !== '' && excerptArray[0] !== undefined && excerptArray[0] !== null ){
			var excerptContent = excerptArray[0].split(" ");
			
			excerptContent[excerptContent.length-2] += "&nbsp;" + excerptContent[excerptContent.length-1];
			excerptContent.pop();
			jQuery(this).html(excerptContent.join(" ") + "<br>" + excerptBtn);
		}
	});
	
	if(main_nav_item !== false){
		var top_level = $('#menu-item-' + main_nav_item.parent.post_id);
		var sec_level = $('#menu-item-' + main_nav_item.child.post_id);
		
		if(top_level.find('.sub-menu').length){
			top_level.addClass('current-menu-parent');
			top_level.find('.sub-menu').css('display', 'block');
		}else{
			top_level.addClass('current-menu-item');
		}
		
		if(sec_level.length > 0)
			sec_level.addClass('current-menu-item');
	}
});

$(document).bind('cbox_complete', function(){
	$.colorbox.resize();
});
		
if (!Array.prototype.shuffle) {
	Array.prototype.shuffle = function() {
 	var len = this.length;
	var i = len;
	 while (i--) {
	 	var p = parseInt(Math.random()*len);
		var t = this[i];
  	this[i] = this[p];
  	this[p] = t;
 	}
};
}

function randomFromTo(from, to){
       return Math.floor(Math.random() * (to - from + 1) + from);
    }
function leftColBg() {
	var heightOne = $('#header_content').height();
	var heightTwo = $('#wrapper').height();
	var heightThree = heightOne + heightTwo + "px";
	
	$('#page_left_col_bg').css({
		'height': heightThree
	});	
}

