$(document).ready(function(){
	
	// **************************************************************************************************************************
	// GENERAL ACTIONS
	
	// 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;
	});
	
	
	// JUMP MENU
	$("select.jump-menu").change(function(x){
		var url = $("option:selected", this).attr("title");
		if (url.length) {
			window.location.href = url;
		}
	});
	
	

	
	// clear inputs
	$(".form-clear-input .textInput, .form-clear-input .textarea").each(function(i){
		var inputValue = $(this).val();
		var inputTitle = $(this).attr("title");
		
		if (inputValue=="" || inputValue==inputTitle) {
			$(this).focus(function(){ 
				if ($(this).val()==inputValue) {
					$(this).val("");
				}
			});
			$(this).blur(function(){ 
				if ($(this).val()=="") {
					$(this).val(inputValue);
				}
			});
		}
		
	});
	
	
	// Header error message
	$(".errorMsg-overlay, .errorMsg-after").hide();
	$(".errorMsg-overlay, .errorMsg-after").fadeIn(300, function(){ 
		var elem = $(this);
		setTimeout(function(){
			$(elem).fadeOut(300);
		}, 1200);
	});
	
	
	// Fading links
	$(".fading-link img").fadeTo(1000, 0.50);
	$(".fading-link").hover(
		function(){
			$("img", this).fadeTo(50, 1);
		},
		function(){
			$("img", this).fadeTo(50, 0.50);
		}
	);
	
	
	

	// END GENERAL ACTIONS
	// **************************************************************************************************************************
	
	// TABS
	var firstTabElement = $("ul.tabs li a.link-tabs:first");
	var firstTabElementName = $(firstTabElement).attr("id");
	$(firstTabElement).addClass("link-tabs-active");
	$("div.panel").hide();
	$("#panel-" + firstTabElementName).fadeIn(500);
	
	$("ul.tabs li a.link-tabs").click(function(){
		$("ul.tabs li a.link-tabs").removeClass("link-tabs-active");
		$(this).addClass("link-tabs-active");
		
		var thisElementName = $(this).attr("id");
		$("div.panel").hide();
		$("#panel-" + thisElementName).fadeIn(500);
		
		return false;
	});
	
	
	$("#social-links a img").hover(
        function(){
            $(this).css({ opacity: 0.5 });
        },
        function(){
            $(this).css({ opacity: 1 });
        }
    );
	
	// Cufon Text Replacement
	Cufon.replace('.replace', {fontFamily: 'Bello Script' } );
	Cufon.replace('.whitney', {fontFamily: 'Whitney HTF' } );
	
});
/*function startVideo() {
		
	$.blockUI({
		message: $('#buzz-video'), 
		css: {
			cursor: 'default',
			width: '977px',
			left: '50%',
			top: '10%',
			//margin: '0 0 0 -550px',
			margin: '0 0 0 -488px',
			padding: '1px',
			background: 'transparent',
			border: '0'
		},
		overlayCSS: { cursor: 'default' }
	}); 
	$('.blockOverlay').attr('title','Click to close').click(function(){
		$("#video-flash").remove();
		$("#video-flash-wrapper").remove();
		$.unblockUI();
	});
}*/
