$(document).ready(function(){
	
	var URL = $("link")[0].href.split('workspace')[0];

	$("body").supersleight({shim: URL + "workspace/assets/imagens/x.gif"});

	$("a[rel^='galeria']").colorbox();

	/* Newsletter */

	var newsletter = $("#newsletter");
	var formUrl = $("#menu li a:first").attr("href") + "/newsletter/";

	if (newsletter.length) {
		newsletter.submit(function(){
			$.post(formUrl, $(this).serialize(), function(data){
				if (data.errors) {
					if (data.errors.nome)
						$("#nome").prev("label").text("Nome (" + data.errors.nome + ")").animate({color: "#b30000"});
					else
						$("#nome").prev("label").text("Nome").animate({color: "#fff"});

					if (data.errors.email)
						$("#email").prev("label").text("E-mail (" + data.errors.email + ")").animate({color: "#b30000"});
					else
						$("#email").prev("label").text("E-mail").animate({color: "#fff"});
				} else {
					var size = {
						width: newsletter.css("width"),
						height: newsletter.css("height")
					};

					if (! $.data(newsletter, "cache"))
						$.data(newsletter, "cache", newsletter.html());

					newsletter.animate({opacity: 0}, "fast", "linear", function(){
						newsletter.empty();
						newsletter.css({'width': size.width, 'height': size.height});	
						newsletter.html('<h3 style="color:white">Obrigado! <br/><br/><a href="javascript:void(0);" style="color:white" id="nw_again">Cadastrar outro E-mail</a></h3>');
						newsletter.animate({opacity: 1}, "fast", "linear");

						newsletter.find('h3 a').one("click", function(){
							newsletter.animate({opacity: 0}, "fast", "linear", function(){
								newsletter.html($.data(newsletter, "cache"));
								newsletter.animate({opacity: 1});
							});
						});
					});

				}
			}, "json");

			return false;
		});
	}
	
	/* String Limiter */
	$("ul.pratos li a").each(function(){
		var string = $(this).html();
		
		if(string.length > 33){
			string = string.substring(0,33);
			$(this).html(string+' ...');
		}
	});

	/**************/

	$("a.favorito").click(function(){  
		var url = location.href;
		var title = document.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark  
				window.sidebar.addPanel(title, url,"");  
		} else if( window.external ) { // IE Favorite  
				window.external.AddFavorite( url, title);  
		} else if(window.opera) { // Opera 7+  
				return false; // do nothing - the rel="sidebar" should do the trick  
		}
	});

	/**************/

	var agent = navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	if (is_iphone){
		location.href = "http://" + location.hostname + "/iphone/";
	}

});