var baseURL = "/";

topnavigation = function()
{
	$("#top-navigation ul").hide("fast");
		
	$("#top-navigation li.first-level").each(function()
	{
		var navhover = $(this);
		$(navhover).hover(function()
		{
			$(navhover).css({"opacity":0.9});
			$(navhover).addClass("active");
			$("ul", navhover).slideDown(200);//.fadeTo("normal", 1);
		},
		function()
		{
			if ($("ul", navhover)[0])
			{
				$(navhover).css({"opacity":1});
				$("ul", navhover).slideUp(200, function()
				{//.fadeTo("normal", 0, function(){
					$("ul", navhover).hide("fast");
					$(navhover).removeClass("active");
				});
			} 
			else 
			{
				$("ul", navhover).hide("fast");
				$(navhover).removeClass("active");
			}
		})
	})
}


sifrrun = function()
{
	sIFR.replaceElement("#section-title", named({sFlashSrc:baseURL+"flash/font_dax_light.swf", sColor:"#cc8d02", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent"}));
	sIFR.replaceElement("#section-subtitle", named({sFlashSrc:baseURL+"flash/font_dax_light.swf", sColor:"#cc8d02", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent", sFlashVars:"offsetTop=-3"}));
	sIFR.replaceElement("#left-column h1, #left-column h3", named({sFlashSrc:baseURL+"flash/font_dax_regular.swf", sColor:"#414400", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent"}));
	sIFR.replaceElement("#left-column h2", named({sFlashSrc:baseURL+"flash/font_dax_regular.swf", sColor:"#cc8d02", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent"}));
	sIFR.replaceElement("#right-column h4", named({sFlashSrc:baseURL+"flash/font_dax_regular.swf", sColor:"#414400", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent"}));
}


function applyCufon()
{
	Cufon.replace('#top-navigation a.first-level', { fontFamily: 'DaxMedium' });
	Cufon.replace('#top-navigation small', { fontFamily: 'DaxRegular' });
	Cufon.replace('#top-navigation li li', { fontFamily: 'DaxMedium', hover:'true', letterSpacing:'-0.2px' });		
	Cufon.replace('h1', { fontFamily: 'DaxRegular' });
	Cufon.replace('h2', { fontFamily: 'DaxRegular' });
	Cufon.replace('#breadcrumbs a', { fontFamily: 'DaxRegular', hover:'true' });
	Cufon.replace('h3#section-subtitle', { fontFamily: 'DaxLight' });
	Cufon.replace('#content h2', { fontFamily: 'DaxRegular' });
	Cufon.replace('#content h3', { fontFamily: 'DaxRegular', hover:'true' });
	Cufon.replace('#content.homepage div#headline a', { fontFamily: 'DaxMedium', hover:'true' });
	Cufon.replace('#section-description p', { fontFamily: 'DaxRegular' });
	Cufon.replace('#content h4.related-links', { fontFamily: 'DaxRegular' });
	Cufon.replace('#content.homepage div#highlights div.column h4', { fontFamily: 'DaxRegular' });	
	Cufon.replace('input#user-poll-submit', { fontFamily: 'DaxMedium', hover:'true' });	
	Cufon.replace('.compendios .cell h4', { fontFamily: 'DaxLight' });
	Cufon.replace('.compendios .cell a', { fontFamily: 'DaxMedium', hover:'true' });	
	Cufon.replace('#right-navigation li', { fontFamily: 'DaxMedium', hover:'true' });
	Cufon.replace('#right-column h4.top-content-list', { fontFamily: 'DaxRegular' });		
	Cufon.replace('#footer-top-inner .column h4', { fontFamily: 'DaxMedium' });
	Cufon.replace('#footer-top-inner .column p', { fontFamily: 'DaxRegular' });
	//Cufon.replace('#footer-top-inner .column .imc', { fontFamily: 'DaxLight' });
	Cufon.replace('#footer-top-inner .column li', { fontFamily: 'DaxRegular' });
	Cufon.replace('#footer-top-inner .column a', { fontFamily: 'DaxMedium', hover:'true' });
	Cufon.replace('#footer-contacts p', { fontFamily: 'DaxMedium' });
	Cufon.replace('#footer-contacts a', { fontFamily: 'DaxMedium', hover:'true' });
	Cufon.replace('#footer-bottom', { fontFamily: 'DaxMedium', hover:'true' });
	Cufon.replace('#footer-bottom-navigation a', { fontFamily: 'DaxMedium', hover:'true' });
}

vermais = function()
{
	$(".vermais").each(function()
	{
		var vermais = $(this);
		var button = $('<p class="ver-mais"><a href="#">Ver mais</a></p>');
		button.click(function()
		{
			vermais.slideDown(500, function(){
				button.fadeTo("normal", 0.01);
			});
			return false;
		})
		$(this).slideUp(1).after(button);
	})
}

function trackGA(url)
{
	if (_gaq) _gaq.push(['_trackPageview', url]);
}

pagebg = function()
{
	var pagebgclass = Array()
	pagebgclass[0] = "girassol1";
	pagebgclass[1] = "girassol2";
	pagebgclass[2] = "milho1";
	pagebgclass[3] = "milho2";
	pagebgclass[4] = "soja1";
	randompagebg = Math.floor(Math.random()*pagebgclass.length);
	$("#page-bg").addClass(pagebgclass[randompagebg]);
}


checkHash = function()
{ 
	var location = window.location.href;
	var hash = "";
	if(location.indexOf("#") != -1) {
		var hash = location.substring(location.indexOf("#"), location.length);
	}
	return hash;
}


main = function()
{
	topnavigation();
	//sifrrun();
	applyCufon();
	//pagebg();
}



//CONTENT

function homepage()
{
	
	$("#content.homepage div#highlights div.feed div.feed-holder").jwSlider({ pause:10000 });
	
	$("#user-poll").submit(function(evt)
	{
		evt.preventDefault();
		
		var option = $(this).find("input[name=option]:checked").val();
		if (option != "")
		{
			//TODO: preloader show
			$.post("services/poll_vote_async.php", $(this).serialize(), function(data, status)
			{
				$("#poll-container").fadeOut(100, function()
				{
					//TODO: preloader hide & animate results
					$(this).html(data);
					$(this).fadeIn(100);					
				});
			});
		}
	});	
}

proteinas = function()
{
	vermais();
}

acidosgordos = function()
{
	vermais();
}

tiposvitaminas = function()
{
	$(".toggle").slideUp(1);
	
	/*$("h3").each(function(){
		var h3 = $(this);
		h3.click(function(div){
			var div = $("a", this).attr("href") + "-toggle";
			alert(div);
			$(div).slideToggle();
			return false;
		})
	})*/
		
	
	var lastHash = "#0";
	setInterval(function()
	{
		var hash = checkHash();
		if(hash.length && hash != lastHash)
		{
			div = hash + "-toggle";
			$(div).slideToggle();
			lastHash = hash;
		}
	}, 300);
}

tiposminerais = function()
{
	tiposvitaminas();
}




imc = function()
{
	var flashvars = {};
	var params = {};
	var attributes = {};
	swfobject.embedSWF(baseURL+"flash/calculadores_imc.swf", "calculador-imc", "390", "370", "9.0.0","../flash/expressInstall.swf", flashvars, params, attributes);
}



contactos = function()
{
	contactosLabel = function(field)
	{
		if($(".input", field).val() != "") $("label", field).hide();
		
		$(".input", field).focus(function()
		{
			$("label", field).hide();
		}).keydown(function()
		{
			$(".input", field).removeClass("error");
		})
		
		$(".input", field).blur(function()
		{
			if ($(".input", field).val() == ""){
				$("label", field).show();
			}
		})
	}
	
	contactosLabel(".name");
	contactosLabel(".email");
	contactosLabel(".subject");
	contactosLabel(".message");

}



mapasite = function()
{
	sIFR.replaceElement("#sitemap a.first-level", named({sFlashSrc:baseURL+"flash/font_dax_regular.swf", sColor:"#414400", nPaddingTop:"0", nPaddingRight:"0", nPaddingBottom:"0", nPaddingLeft:"0", sWmode:"transparent"}));
}
