/*
Hi there!
This is the global javascript for all of my sites.
Some doubt? I can nicely bring some help, contact me: camo.mx
Date: June 12, 2011
*/

$(function(){
	
	// Global behaviour
	$('header nav input[name="s"]').click(function(){
		if(this.value == 'Buscar') {
			this.value = '';
		}
		if(this.value != 'Buscar' && this.value != '') {
			$(this).select();
		}
	});
	$('header nav input[name="s"]').blur(function(){
		if(this.value == '') {
			this.value = 'Buscar';
		}
	});
	
	// This ones for adriacatl.com
	if($('.site-adriacatl').length && !$.browser.msie) {
		
		// Behaviour and environment modification
		$('header a').css('color', '#FAE5E5');
		$('.post-content').hide(0);
		$('article.post').height($(window).height() - 180);
		// Depends on jquery.ui.js
		$('header.adriacatl').hover(function(){
			$('header.adriacatl a:animated').stop();
			$('header.adriacatl a').animate({color: '#CA0000'}, 500);
		}, function() {
			$('header.adriacatl a:animated').stop();
			$('header.adriacatl a').animate({color: '#FAE5E5'}, 500);
		});
		
		// Scrolling!
		$(window).scroll(function(){
			var scroll_top = $(window).scrollTop();
			if(scroll_top > 60) {
				$('nav.subnav').addClass('fixed');
				$('.articles').addClass('after-fixed');
			}
			if(scroll_top < 60) {
				$('nav.subnav').removeClass('fixed');
				$('.articles').removeClass('after-fixed');
				$('nav.subnav .description').text('Agua como símbolo de paz y guerra, el mar que da la vida.');
			}
			
			$('article.post').each(function(i, item){
				if(scroll_top > $(item).offset().top - 100 && scroll_top > 60) {
					var excerpt =  $(this).find('.post-content').text();
					$('nav.subnav .description').text(excerpt);
				}
			});
		});
		
	}
	$('.flag:empty').hide();
	// This ones for camo.mx
	if($('.site-camo').length) {
		// Depends on jquery.qtip.js
		$('.bookmarks li a').qtip({
			position: {
			  corner: {
				 target: 'topMiddle',
				 tooltip: 'bottomMiddle'
			  }
		   }
		});
	}
});

