// initialize the slideshow when the DOM is ready
$(document).ready(function() {
	// Fit height fix
	$('#material_slideshow').css('overflow', 'hidden');
	$('#collection_slideshow').css('overflow', 'hidden');
	$('.slideshow')
	.before('<div id="nav">')
	.cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pager:  '#nav',
		speed: 500,
		timeout: 4000,
		pause: 1
	});
	$(".fitheight").each(function(){
		$(this).height( $(this).parent().height());
	});
		
	$("div.quote_body p:last-child").append('<img class="endquote" align="&quot;" src="/images/testimonials-quote-end.png" />');
	$("div.quote_body p:first-child").prepend('<img class="startquote" align="&quot;" src="/images/testimonials-quote-start.png" />');
	// any input focusing
	$("input[type=text], textarea").focus(function(){
		$(this).addClass('focused', 100);
		});
	$("input[type=text], textarea").blur(function(){
		$(this).removeClass('focused', 100);
		});
	// efects for search button on input focus
	$("#search_bar input[type=text]").focus(function(){
		$("#searchsubmit").addClass('focused', 100);
		});
	$("#search_bar input[type=text]").blur(function(){
		$("#searchsubmit").removeClass('focused', 100);
		});
	
	$("tr").hover(function(){
		$(this).addClass('hover', 100);
	}, function(){
		$(this).removeClass('hover', 100);
	});
	
	$(document).bind('click', function(e){ 
		var $clicked = $(e.target); 
		if (!($clicked.is('#thevideo') || $clicked.parents().is ('#thevideo'))) { //click outside, do what you want :) 
			$("#thevideo_container").hide();
		} 
		else { 
		} 
	}); 
						
	
	
	//Menu hover
	$('#header #navigation li:not(.active), #header #switch-lang li:not(.active), #material_list_nav li:not(.active)').hoverIntent(function(){
		$(this).addClass('active');
	}, function() {
		$(this).removeClass('active');
	});
	

	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	 });
});

Cufon.replace('#header li.allcaps', { fontFamily: 'NED', textShadow: '0px 1px rgba(0, 0, 0, 1)' });
Cufon.replace('#header li:not(.allcaps)', { fontFamily: 'NED Serif Italic', textShadow: '0px 1px rgba(0, 0, 0, 1)' });
Cufon.replace('h1, h2, h3, h4, h5, h6, #footer #copyrights #company, #footer #copyrights #author, th.definition', { fontFamily: 'NED Serif Italic' });
Cufon.replace('th.term', { fontFamily: 'NED' });


