/**
 * @since Sat Mar 01 12:10:52 BRT 2008
 * @author Fábio Matavelli <fabio@dotcustoms.com>
 * @name sdc.js
 */

function fitWindow() {
	//$('#geral').height($(window).height());
	//$('#geral').width($(window).width());
	//$('#geral').height($(window).height());
}

$(window).ready(function() {
	fitWindow();
	$(window).resize(function() {
		fitWindow();
	});
});

$(document).ready(function(){
	$('#geral').hide();
	$('#loading').fadeIn('fast');
	$("dd").hide();
	
	//$('#loadModal').width($(document).width());
	//$('#loadModal').height($(document).height());
	
	$(".linkMenu").click(function(){
		$("dd:visible").slideUp("fast");
		if($(this).parent().next().html() != $("dd:visible").html()) {
			$(this).parent().next().slideDown("fast");
		}
		return false;
	});

	$('input').focus(function() {
		if($(this).attr('title')) {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('');
				$(this).css('color','#000000');
			}
		}
	});
	
	$('input').blur(function() {
		if($(this).attr('title')) {
			if($(this).val() == '') {
				$(this).val($(this).attr('title'));
				$(this).css('color','#9C9FA8');
			}
		}
	});
	
	$('textarea').focus(function() {
		if($(this).attr('title')) {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('');
				$(this).css('color','#000000');
			}
		}
	});
	
	$('textarea').blur(function() {
		if($(this).attr('title')) {
			if($(this).val() == '') {
				$(this).val($(this).attr('title'));
				$(this).css('color','#9C9FA8');
			}
		}
	});
	
	
	/**
	 * MENU
	 */
	$('.linkConteudo').click(function() {
		$('#geral').height($(document).height());
		$('#loading').ajaxStart(function() {
			$(this).fadeIn('fast');
		});
		//$('#base').fadeOut('fast');
		$('#base').load("conteudo.php" + $(this).attr('href'),function() {
			var hR = ($(this).height() + $('#topo').height());
			var hL = ($('#menu').height() + $('#logo').height());
			var h = (hR<hL)?hL:hR;
			$('#geral').animate({ height: h },'slow');
			if($('img').length > 0) {
				$('img').load(function() {
					//$('#base').fadeIn('fast');
					$('#loading').fadeOut('fast');
				});
			} else {
				//$('#base').fadeIn('fast');
				$('#loading').ajaxComplete(function() {
					$(this).fadeOut('fast');
				});
			}
		});
		return false;
	});
	
	$(document).scroll(function() {
		var topo = $(document).scrollTop();
		$('#loading').css('top',topo + 'px');
	});
	
	//$('#geral').fadeIn('fast');
	$('#loading').fadeOut('fast');
	setTimeout("$('#geral').fadeIn('normal')",500);
});