/* DOCUMENT READY */
$(document).ready(function(){
	
	// external links
	$("a[rel='external']").click(function() {
		return !window.open($(this).attr("href"));
	});
	$('.hide-with-js').hide(); // use this class to hide the message "please open this link in new window"
	
	// fade in messages
	$('.successMsg').hide();
	$('.successMsg').fadeIn(1000);
	$('.errorMsg div').hide();
	$('.errorMsg div').fadeIn(1000);
	$('.warningMsg').hide();
	$('.warningMsg').fadeIn(1000);
	
	// non-clickable links
	$(".return-false").click( function() {
		return false;
	});
	
	
	// Clear Inputs
	$("#form-newsletter input, #form-search input").each(function(i){
		var inputValue = $(this).val();
		
		$(this).focus(function(){ 
			if ($(this).val()==inputValue) {
				$(this).val("");
			}
		});
		$(this).blur(function(){ 
			if ($(this).val()=="") {
				$(this).val(inputValue);
			}
		});
	});
	
	
	// Tooltip
	$("a.tooltip").tooltipLink();
	
	
	// Fading Link
	$(".fadingLink, .gallery > li > a > img").fadeTo(300, 0.5);
	$(".fadingLink, .gallery > li > a > img").hover(
		function(){
			if( !$(this).is(':animated')) {
				$(this).fadeTo(100, 1);
			}
		},
		function(){
			$(this).fadeTo(100, 0.5);
		}
	);
	
	
	// Font replacement
	replaceFonts();
	
	
	// Gallery
	$(".gallery > li > a").fancybox({
		imageScale: true,
		overlayOpacity: 0.8,
		overlayColor: '#222',
		changeSpeed: 100,
		changeFade: 100,
		centerOnScroll: true,
		cyclic: true
	});
	
});


// Font replacement
function replaceFonts() {
	//Cufon.replace('button.submitButton', { fontFamily: 'Qlassik', hover: true, hoverables: { a: true, span: true, button: true } });
	Cufon.replace('#logo, .replace-light', { fontFamily: 'WhitneyLight', hover: true, hoverables: { a: true } });
	Cufon.replace('#main-menu a, .submit, .replace-medium', { fontFamily: 'WhitneyMedium', hover: true, hoverables: { a: true } });
}
