/* global */

$("document").ready( function() {
	
	
////////// index functions ////////////////////////////////////////

// call slider function
$("#slider").easySlider();

//indexImage links
$('.indexThumbs a').click(
	function() {
		var theTarget = $('#launchVideo');
		var theContent = $("#launchVideo > *");
		var theSource = $(this).attr("href");
		var theRel = $(this).attr("rel");
		var	theReplacement = "<img src=\""+theSource+"\" />";
			
			$(".indexThumbs a.active").toggleClass("active");
			$(this).toggleClass("active");
			
			theContent.css("z-index","101"); //move current way up in stacking order
	
			if( theRel == "image" ) {
				//alert(theTarget.html());
				theTarget.append(theReplacement);
				theContent.animate({opacity:1}, 400).fadeOut('slow', function(){ theContent.trigger("unload").unbind().remove() });
			} else if ( theRel == "video" ) {
				theContent.trigger("unload").unbind().remove();
				theTarget.append("<div id=\"ajax\"></div>");
				var theVid = $(this).attr("id")
				$("div#ajax").load("/loadVid.php?vid="+theVid+"");
				//alert("/loadVid.php?vid="+theVid+"");
				theContent.animate({opacity:1}, 400).fadeOut('slow', function(){ theContent.trigger("unload").unbind().remove() });
			}

		return false;
	} // close click function
);//close click


// let's find <br>'s
var theBreak = $("#questionClips br");

theBreak.each(
	function() {
		$(this).replaceWith("</p><p>");
	}
);

// let's find different <br>'s
var theOtherBreak = $("#metaBlock br");

theOtherBreak.each(
	function() {
		$(this).replaceWith("&nbsp;&nbsp;|&nbsp;&nbsp;");
	}
);


// success fadeout
$('#requestDiv .success').animate({ opacity: 1 }, 2600,
	function () {
		$('.success').fadeOut(600);
	}// close callback
);

// error closer
$('.error a, .success a').click(
	function () {
		$(this).parent('div').fadeOut(600);
		return false;
	}// close callback
);


/// question form functions /////////////////////////////////////////

	$('#comment textarea').textHint();



//// test comment ajax pagination

$('.next a, .prev a').live("click", function() {
	
	var inner = $("#responseDiv");
	var outer = $("#responses");
	var theSource = $(this).attr("href");
		
	outer.height(inner.height());
	
	outer.block({
		fadeIn:  800,
		timeout: 0,
		message: '<p>foo</p>',
		css: {
			borderWidth: 0,
			padding: 0,
			margin: 0,
			cursor: 'wait',
			backgroundColor: "transparent",
			"background-image": "url(/images/ntc_processing_page.gif)",
			"background-repeat" : "no-repeat",
			width: '240px',
			height: '33px',
			left: '50%'
		}
	 });

			$.ajax({
				url: theSource,
				success: function(html){
					setTimeout( 
						function() { 
							inner.html(html);
							outer.unblock({ fadeOut: 800 });
							outer.animate({opacity: 1}, 800).animate({ "height": inner.height() }, "slow");
						}, 2000);
				}
			});
	
	return false;
}); // close live function



/// test new comment background fade

//$('.newest').newest();

/// request form functions /////////////////////////////////////////

$('#requestForm label').hide();

$('input[title!=""], #requestForm textarea[title!=""]').hint();

//$('#requestForm textarea').textHint('blur', 'Materials requested');



$('#requestDiv form').submit(function() {
	$('.processing').show();
});

$('#responseForm form').submit(function() {
	$('.processingResponse').show();
});

//// video popper functions

$('#aboutClips a.thumb').popper();// close click


});






























