$(window).load(function(){
	var myimg = $('#image_container img');
	myimg.each(function(){
		var imgHeight = $(this).height();
		var imgWidth = $(this).width();
		$(this).attr('height',imgHeight);
		$(this).attr('width',imgWidth);
	});
	var myPageImg = $('#page_image img.page-image');
	myPageImg.each(function(){
		var imgHeight = $(this).height();
		var imgWidth = $(this).width();
		$(this).attr('height',imgHeight);
		$(this).attr('width',imgWidth);
	});
});
//_________ end image height width _________\\
$(document).ready(function() {
	$('#content.inner input').each(function(){
		var inputItem = $(this);
		var inputType = $(this).attr('type');
		inputItem.addClass(inputType);
	});
//_________ end input addClasses based off of type _________\\
	$('#page_image img.page-image').hover(function(){
		$(this).next('#page_image_caption').slideDown(500);
	}, function(){
		$(this).next('#page_image_caption').slideUp(500);
	})
//_________ end page image hover _________\\
	Cufon.replace('#site_slogan h2');
	Cufon.replace('#slider_description p');
	Cufon.replace('div.slide-desc');
	Cufon.replace('div.slide-title');
	//$('div.slide-title').css('opacity', 0.9);
	Cufon.replace('#left_nav a', { hover: true });
	Cufon.replace('#inner_content h2');
	Cufon.replace('#inner_content h3');
	Cufon.replace('#media_forms h3');
	Cufon.replace('div.tert-nav a', { hover: true });
	Cufon.replace('#page_image span');
	Cufon.replace('#page_image_caption');
	Cufon.replace('div.attention-grabber a', { hover: true });
//_________ end Cufon _________\\
	if($('#page_image_link').length === 0){
		$('#page_image').removeClass('gallery');
	}
//_________ end page image class removal _________\\
	$('#about_us div.name-title').click(function(){
		$(this).next().slideToggle(500);
	});
//_________ end about sliders _________\\
	$('#page_image.gallery').click(function(){
		$('#did_you_know_pop_up').modal({
			opacity:80,
			overlayCss: {backgroundColor:"#efefef"},
			overlayClose:true,
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.data.hide();
					dialog.container.fadeIn('fast', function () {
						dialog.data.fadeIn('fast');
					});
				});
			},
			onClose: function (dialog) {
				dialog.data.fadeOut('slow', function () {
					dialog.container.hide(200, function () {
						dialog.overlay.fadeOut(100, function () {
							$.modal.close();
						});
					});
				});
			}
		});
	});
//_________ end did you know gallery pop up _________\\
	$('#videos a.video-thumb', this).click(function(){
		$(this).next('div.video-modal').modal({
			opacity:80,
			overlayCss: {backgroundColor:"#000000"},
			overlayClose:true,
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.data.hide();
					dialog.container.fadeIn('fast', function () {
						dialog.data.fadeIn('fast');
					});
				});
			},
			onClose: function (dialog) {
				dialog.data.fadeOut('slow', function () {
					dialog.container.hide(200, function () {
						dialog.overlay.fadeOut(100, function () {
							$.modal.close();
						});
					});
				});
			}
		});
	});
	
	function fade_in(ctx){
		var speed = 200;
		$('.phase-one-title',ctx).fadeIn(speed);
		$('.phase-one',ctx).fadeIn(speed, function(){
			$('.phase-two',ctx).fadeIn(speed, function(){
				$('.phase-three-desc',ctx).fadeIn(speed, function(){
					$('.phase-three',ctx).fadeIn(speed, function(){
						$('.phase-four',ctx).delay(2500).toggle(250, function(){
							$('.phase-five',ctx).toggle(250, function(){
								setTimeout(function() {
									fade_out(ctx);
								}, 2500);
							});
						});
					});
				});
			});
		});
	}
	function fade_out(ctx){
		var speed = 200;
		$('.phase-five', ctx).fadeOut(speed, function(){
			$('.phase-four',ctx).toggle(speed);
			$('.phase-three-desc',ctx).fadeOut(speed);
			$('.phase-three',ctx).fadeOut(speed, function(){
				$('.phase-two',ctx).fadeOut(speed, function(){
					$('.phase-one-title',ctx).fadeOut(speed);
					$('.phase-one',ctx).fadeOut(speed, function(){
						// loop!
						var i = ctx.attr('class').match(/slide-([^\s]+)/)[1];
						i = parseInt(i);
						i++;
						if(i > $('div.home-slide').length) i = 1;
						fade_in($('div.slide-' + i));
					})
				})
			})
		});
	}
	fade_in($('div.slide-1'));
//_________ The new sequence is: big image, small image + description, get info phrase 1 -> pause for 2000 -> phrase 2 -> pause 2000 reverse fade in sequence. _________\\
//_________ The new sequence is below and starts to break and loop in erraic ways after the last slide. _________\\
	// function fade_in(ctx){
	// 	$('.phase-one-title',ctx).fadeIn(500);
	// 	$('.phase-one',ctx).fadeIn(500, function(){
	// 		$('.phase-two, .phase-three-desc',ctx).fadeIn(500, function(){
	// 			//$('.phase-three-desc',ctx).fadeIn(500);
	// 			$('.phase-three',ctx).fadeIn(250, function(){
	// 				$('.phase-four',ctx).delay(3000).toggle(250, function(){
	// 					$('.phase-five',ctx).delay(500).toggle(250, function(){
	// 						console.log('fade out timer start');
	// 						setTimeout(function() {
	// 							console.log('fade out timer end');
	// 							fade_out(ctx);
	// 						}, 2000);
	// 					});
	// 				});
	// 			});
	// 		});
	// 	});
	// }
	// function fade_out(ctx){
	// 	var speed = 500;
	// 	$('.phase-five, .phase-four, .phase-three', ctx).fadeOut(speed, function(){
	// 		//$('.phase-four',ctx).toggle(speed);
	// 		$('.phase-three-desc',ctx).fadeOut(speed);
	// 		//$('.phase-three',ctx).fadeOut(speed, function(){
	// 			$('.phase-two',ctx).fadeOut(speed, function(){
	// 				$('.phase-one-title',ctx).fadeOut(speed);
	// 				$('.phase-one',ctx).fadeOut(speed, function(){
	// 					// loop!
	// 					var i = ctx.attr('class').match(/slide-([^\s]+)/)[1];
	// 					i = parseInt(i);
	// 					i++;
	// 					if(i > $('div.home-slide').length) i = 1;
	// 					fade_in($('div.slide-' + i));
	// 					//clearTimeout();
	// 					console.log("fadeout func " + i	); //this gets called 2-3 times, probably causing some issues with the timer above.
	// 				})
	// 			})
	// 		//})
	// 	});
	// }
	// fade_in($('div.slide-1'));
//_________ end video pop up _________\\
	/*
	$('#home_gallery').cycle({ 
	    fx:    'fade', 
	    timeout: 10000,
	    speed: 2000,
		slideExpr: '.home-slide',
		pause: true,
		after: onAfter
	});
	*/

//_________ /home feature _________\\
});
//_________ end Document Ready _________\\

function onAfter(curr, next, opts) {
	// console.log(opts.currSlide);
    $('#home_gallery .phase-one').fadeIn(500, function(){
		$('#home_gallery .phase-two').delay(300).fadeIn(500, function(){
			$('#home_gallery .phase-three').delay(300).fadeIn(500, function(){
				$('#home_gallery .phase-four').delay(2500).fadeOut(300, function(){
					$('#home_gallery .phase-five').delay(800).fadeIn(500, function(){
						$('#home_gallery .phase').fadeOut(500);
					});
				});
			});
		});
	});
	//$('.phase').delay(9600).hide(100);
}
