$(document).ready(function(){	
	
	$.preloadCssImages({statusBarEl: '#statusbar'});
	
	
	/************************
	PORTFOLIO TAG
	************************/
	//$('#portfolio-tag').hover(
		//function(){
			//$(this).animate({'backgroundColor':'#48bcff'}, 'normal');
		//},
		//function(){
		//$(this).stop().animate({'backgroundColor':'#FFFFFF'}, 'normal');
	//});
	
	$('#quotationtag .content').hide();	
	$('.frame a.open_quotation, #quotationtag .tag, #quotationtag .content a.fechar').click(function(){
		$('#quotationtag .content').slideToggle();
		return false;
	});
	
	$('#footer .view-awards, #footer #awards-panel a.fechar').click(function(){
		$('#awards-panel').slideToggle();
		return false;
	});
	
	$('#footer li .newsletter, #newsletter a.fechar').click(function(){
		$('#newsletter').slideToggle();
		return false;
	});
	
	
	$('#footer #awards #cda, #footer #awards-panel li a').prepend('<span></span>').hover(function(){
		$(this).find('span').stop().animate({opacity:'0'});
	},function(){
		$(this).find('span').stop().animate({opacity:'1'});
	});
			
	
	/************************
	MENU HOVER
	************************/
	
	$('#topheader #navigation li').prepend('<span></span>');
	$('#topheader #navigation li span').hide();
	 
	$('#topheader #navigation li a').hover(
	function(){
		$(this).css({'color':'#000000'});
		$(this).parent().find('span').slideToggle('fast');
		
	},
	function(){
		if($.address.value() == '/portfolio') {
		$(this).css({'color':'#000000'});
		}
		else {
		$(this).css({'color':'#FFFFFF'});
		}
		$(this).parent().find('span').slideToggle('fast');
	}
	);
	
	$('.scrollable-area span.yellow').hide();
	
	$('.scrollable-area').hover(
	function(){
		$(this).find('h1').css({'color':'#000000'});
		$(this).find('span.yellow').slideDown('fast');
	},
	function(){
		$(this).find('h1').css({'color':'#FFFFFF'});
		$(this).find('span.yellow').slideUp('fast');
	}
	);
	

	function loadURL(url) {
		console.log("loadURL: " + url);
		$("#contentpanel").load(url);
	}

	// Event handlers
	$.address.init(function(event) {
		$.address.strict(true);
		$.address.crawlable(true);
	}).change(function(event) {
		if(event.path.indexOf("portfolio") != '-1') {
			$('a.back').removeClass('cboxElement');
			
			$('#contentpanel').animate({opacity:'hide', marginLeft:'-600px'},'normal');			
			$('#portfolio-panel .middle-section').show();	
			
			$("#fooweb").carouFredSel({
				items: 3,
				scroll:{
					items : 1
				},
				direction: "left",
				auto: false,
				prev : "#fooweb_prev",
    			next : "#fooweb_next"
			}).find(".item a").hover(
				function() { $(this).find(".info").slideDown('fast'); $(this).find("img").stop().animate({height: '200', 'margin-left': '-40px', 'margin-top': '-20px', width: '290'}, 'fast'); },
				function() { $(this).find(".info").slideUp('fast'); $(this).find("img").stop().animate({height: '160', 'margin-left': '0px', 'margin-top': '0', width: '250'}, 'fast'); }
			).click(function(){ $(this).find(".info").hide(); });
			
			$("#foodesign").carouFredSel({
				items: 3,
				scroll:{
					items : 1
				},
				direction: "left",
				auto: false,
				prev : "#foodesign_prev",
    			next : "#foodesign_next"
			}).find(".item a").hover(
				function() { $(this).find(".info").slideDown('fast'); $(this).find("img").stop().animate({height: '200', 'margin-left': '-40px', 'margin-top': '-20px', width: '290'}, 'fast'); },
				function() { $(this).find(".info").slideUp('fast'); $(this).find("img").stop().animate({height: '160', 'margin-left': '0px', 'margin-top': '0', width: '250'}, 'fast'); }
			).click(function(){ $(this).find(".info").hide(); });
	
			
			
			//entrada do portfolio
			$('.scrollable-area span.yellow').hide();
			$('#portfolio-panel').animate({'width':'100%'}, 'slow', function(){
				$('#topheader #navigation li a').css({color:'#000'});
				$('.scrollable-area span.yellow').hide();
			});
			
			// Open Shadowbox
			if(event.path.indexOf("gallery") != '-1')
			{
						
				var galleryName = event.path.split('/');
				//Shadowbox opens here
				$(".scrollable-area .item a."+galleryName[3]).colorbox({
					onCleanup:function(){ $.address.value('portfolio'); $("#cboxContent .gs-link, #cboxContent .gs-share, #cboxContent .fb").remove(); },
					maxHeight: '95%',
					open: true,
					title : $("#portfolio-panel .item a."+galleryName[3]).attr('name'),
					current : '{current}/{total}',
					opacity : '.80',
					onOpen: function(){ 
					var siteURL = $("#portfolio-panel .item a."+galleryName[3]).parent().find('.site_url').text();
					if( siteURL != '' ) {
					$("#cboxContent").prepend('<div class="gs-link"><a href="'+siteURL+'" target="_blank" title="Visit website">Visit Site</a></div><div class="gs-share"><a class="mail a2a_dd" href="http://www.addtoany.com/share_save" title="Share by Email">Share</a><script type="text/javascript"> var a2a_config = a2a_config || {}; a2a_config.menu_type = "mail"; a2a_config.color_main = "000000"; a2a_config.color_border = "000000"; a2a_config.color_link_text = "333333"; a2a_config.color_link_text_hover = "ffffff";</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script><a class="fb" href="http://www.facebook.com/sharer.php?u='+escape(top.location.href)+'&t='+$("#portfolio-panel .item a."+galleryName[3]).attr('title')+' » Portfolio »" title="Share on Facebook">Share on Facebook</a></div>'); }
					else {
					$("#cboxContent").prepend('<div class="gs-share"><a class="mail a2a_dd" href="http://www.addtoany.com/share_save" title="Share by Email">Share</a><script type="text/javascript"> var a2a_config = a2a_config || {}; a2a_config.menu_type = "mail"; a2a_config.color_main = "000000"; a2a_config.color_border = "000000"; a2a_config.color_link_text = "333333"; a2a_config.color_link_text_hover = "ffffff";</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script><a class="fb" target="_blank" href="http://www.facebook.com/sharer.php?u='+escape(top.location.href)+'&t='+$("#portfolio-panel .item a."+galleryName[3]).attr('title')+' » Portfolio »" title="Share on Facebook">Share on Facebook</a></div>');
					}
					$('.cboxCurrent').remove();
				 },  // end onOpen funciton
				onComplete : function(){
					$('#cboxCurrent:hidden').parent().append('<div class="cboxCurrent">1/1</div>');
				}
				});
				
				}
			
			
		}
		
		
		else {
		
		$.colorbox.close();	
			
		/* selected effect  */
		var pageurl = event.path;
		$('#navigation a').each(function(){
			if($(this).attr('rel') == 'address:' + pageurl) {
				$(this).parent().addClass('selected');
			}
			else {
				$(this).parent().removeClass('selected');
			}
		});
				
		$('#portfolio-panel .middle-section').fadeOut(0,	function(){
			$('#contentpanel').animate({opacity:'hide', marginLeft:'-600px'},'normal', function(){
				$('#portfolio-panel').animate({'width':'0px'}, 'slow');
				$('#topheader #navigation li a').css({color:'#FFF'});
				$("#contentpanel").show().load('templates/' +$('[rel=address:' + event.value + ']').attr('href') + '.php', function(response, status, xhr){
					if (status == "error") {
						
						if(pageurl == '/')
						{
							$("#contentpanel").load('templates/home.php', function(){
								$('#contentpanel').hide().animate({opacity:'show', marginLeft:'0px'},'normal');
							});
							}
						else {
							$("#contentpanel").load('templates/404.php', function(){
								$('#contentpanel').hide().animate({opacity:'show', marginLeft:'0px'},'normal');
							});
							}
					  }
					  else {
						//novidades
						$('#newstabs').tabs({ select: function(event, ui) { $('.ui-tabs-panel').animate({paddingTop:'500px', opacity:'0'},'normal'); }, show: function(event, ui) { $('.ui-tabs-panel').animate({paddingTop:'0px', opacity:'1'},'normal'); $('.scroll-pane').jScrollPane(); } });
						$('.scroll-pane').jScrollPane();
						
						
						
						//entrada
						$('#contentpanel').hide().animate({opacity:'show', marginLeft:'0px'},'normal');
						
					  }
				});
			});
		});
		}
		
	});
	 
});

	
$(window).load(function(){
	
	$('#pageloading').fadeOut('normal', function(){
	/***********************
	Entry animation
	***********************/
	$('#header h1').delay(1000).animate({
		opacity:'show',
		marginLeft:'+=170px',
		marginTop:'+=135px'
	}, 'slow' , function(){
		$('#footer').animate({opacity:'show' },'slow');
		$('#navigation').slideDown('slow', function(){
			$('#portfolio-tag').animate({opacity:'show' },'slow');
		});
	});
	});
		
});
