$(function() {
	
	$("#scraps-form div.radio label:eq(0)").addClass('green2');
	$("#scraps-form div.radio label:eq(1)").addClass('blue2');
	$("#scraps-form div.radio label:eq(2)").addClass('red');
	
	var zIndexNumber = 100;
	$('#mask div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 5;
	});
		
		//cache nav
		var nav = $("#main-nav ul");
		
		//add indicators and hovers to submenu parents
		nav.find("li").each(function() {
			if ($(this).find("div.sub-nav").length > 0) {

			//	$("<span>").text("^").appendTo($(this).children(":first"));

				//show subnav on hover
				$(this).mouseenter(function() {
					$(this).find("div.sub-nav").stop(true, true).show();
				});

				//hide submenus on exit
				$(this).mouseleave(function() {
					$(this).find("div.sub-nav").stop(true, true).hide();
				});
			}
		});	
	
	$('input, textarea').focus(function() {		
	    $(this).addClass('focus');
		if($(this).attr('title')=='Telefone') {
			$(this).mask("(99) 9999-9999", {placeholder:" "});
		}					
	});
	
	$('input, textarea').blur(function() {
	    $(this).removeClass('focus');
		if($(this).attr('title')=='Telefone') {
			$(this).unmask("(99) 9999-9999", {placeholder:" "});
		}
	});

	$('#opencomm-btn, #openform-btn').click(function(e){
		var divid = $(this).attr('href');		
		$(divid).slideToggle('normal');			
		e.preventDefault();
	});	
	
	$('.anuncio h4 a').click(function(e){
		var icon = $(this).find('.anuncio-icon');
		var linkid = $(this).attr('id');
		var divid = $(this).attr('href');
		
		$(divid).slideToggle('slow');
		
		$(icon).toggleClass('icon-plus');
		
		e.preventDefault();
	});
	
	$('input, textarea').labelify();
	
	// "o que fazer"
	$("ul.tabs").tabs("div.panes > div", {initialIndex: diaHoje()});
	
	$(".scrollable, #user-gallery .scrollable").scrollable();
	
	$('#news-highlights').css('visibility', 'visible');
	
	$('form.jqtransform div.select').jqTransform();
	
	// teste galeria
	//$(".scrollable").scrollable();

	$("#scrollable-nav .items a").click(function() {
	
		// see if same thumb is being clicked
		if ($(this).hasClass("active")) { return false; }
	
		// calclulate large image's URL based on the thumbnail URL (flickr specific)
		//var url = $(this).attr("src").replace("_t", "");
		var url = $(this).attr("href");
		
		var title = $(this).attr("title");
		
		var titlewrap = $("#title_wrap p");
	
		// get handle to element that wraps the image and make it semi-transparent
		var wrap = $("#image_wrap").fadeTo("medium", 0.5);
		
		// the large image from www.flickr.com
		var img = new Image();
		
		titlewrap.parent().slideUp('fast');	
	
		// call this function after it's loaded
		img.onload = function() {
	
			// change the image
			wrap.find("img").attr("src", img.src);
			titlewrap.text(title);
			titlewrap.parent().slideDown();
			
			// make wrapper fully visible
			wrap.fadeTo("fast", 1);
	
		};

		// begin loading the image from www.flickr.com
		img.src = url;	
		
		/*	
		wrap.fadeTo("normal", .1, function() {
			
			titlewrap.parent().slideUp('fast');		
			
			$(this).find("img").attr("src", url);			
			
			$(this).fadeTo("normal", 1, function(){
				titlewrap.text(title);
				titlewrap.parent().slideDown();
			});	
		});	
		*/	
		// activate item
		$("#scrollable-nav .items a").removeClass("active");
		$(this).addClass("active");
		
		return false;
	
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();
});

function diaHoje(){
	var d=new Date();
	var weekday=new Array(7);
	weekday[0]=6;
	weekday[1]=0;
	weekday[2]=1;
	weekday[3]=2;
	weekday[4]=3;
	weekday[5]=4;
	weekday[6]=5;	
	return weekday[d.getDay()];
}

