/*NUEVO MENU*/
$(document).ready(function() {
	$("ul#menu li a").wrapInner("<span></span>");
	$("ul#menu li a span").css({"opacity" : 0});
	$("ul#menu li a").hover(function(){
	$(this).children("span").animate({"opacity" : 1}, 400);
        }, function(){
	$(this).children("span").animate({"opacity" : 0}, 400);
	});
	});
/*NUEVO MENU*/

$(".tiip").tipTip();

/**Fade*/
$().ready(function(){

$('#feed_subscribe_form').submit(function(){
  var email = $(this).children('[name=email]').val();
  if (!email)
    return false;
  $.ajax({
    url: '/blog/subscribe.json',
    data: {email:email}
  });
  window.open('http://feedburner.google.com/fb/a/mailverify?uri=TutomaxBlog', 'popupwindow', 'scrollbars=yes,width=550,height=520');
});

$('#blogpost a').click(function(){
  href = $(this).attr('href');
  if (!href.match(/^#$|^\/|^(http:\/\/)?www\.tutomax\.com/)) {
    window.open(href, '_blank');
    return false;
  }
});

/**
 * Paginator
 */
$('#paginator_pages').click(function(){
  $('#paginator_pages span').hide();
  $('#paginator_pages form').css('display', 'inline');
  $('#paginator_pages form [type=text]').focus();
  $('#paginator_pages form [type=text]').select();
});

$('#paginator_pages form [type=text]').blur(function(){
  $('#paginator_pages span').show();
  $(this).parent().hide();
});

$('#paginator_pages form').submit(function(){
  var np = parseInt($(this).children('[type=text]').val());
  if (isNaN(np) || np === paginator_page || np < 1)
    return false;
  href = window.location.href;
  q = href.match(/\/(\?.*)$/) ? href.replace(/(.*)\/\?.*$/, '') : null
  if (np == 1)
    href = href.replace(/pagina-[\d]+\//, '');
  else if (href.match(/pagina-[\d]+/))
    href = href.replace(/pagina-[\d]+/, 'pagina-'+np);
  else
    href += 'pagina-'+np+'/';
  if (q)
    href += q;
  window.location = href;
  return false;
});
/**
 * Login form
 */
$('#loginform_show').click(function(){
  $('#tabs_container').show();
  $('#login_form_name').focus();
  $(this).addClass('active');
});

$('#tabs_container').hover(function(){ 
  hide_loginform = false; 
}, function(){ 
  hide_loginform = true;
});

$("body").mouseup(function(){
  if (hide_loginform) {
    hide_loginform && $('#tabs_container').hide();
    $('#loginform_show').removeClass('active');
  }
});
/**
 * Tabs functionality
 */
$('#tabs_container .tabs div').click(function(){
  $(this).parent().children('.selected').removeClass('selected');
  $(this).addClass('selected');
  var index = String($(this).index()+1);
  var c =  $(this).parent().parent().children('.content');
  c.children().hide();
  c.children('div:nth-child('+index+')').show();
});
});
/*PLACE HOLDER FIX*/
$(function() {
	var input = document.createElement("input");
    if(('placeholder' in input)==false) {
		$('[placeholder]').focus(function() {
			var i = $(this);
			if(i.val() == i.attr('placeholder')) {
				i.val('').removeClass('placeholder');
				if(i.hasClass('password')) {
					i.removeClass('password');
					this.type='password';
				}
			}
		}).blur(function() {
			var i = $(this);
			if(i.val() == '' || i.val() == i.attr('placeholder')) {
				if(this.type=='password') {
					i.addClass('password');
					this.type='text';
				}
				i.addClass('placeholder').val(i.attr('placeholder'));
			}
		}).blur().parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var i = $(this);
				if(i.val() == i.attr('placeholder'))
					i.val('');
			})
		});
	}
});
/*PLACE HOLDER FIX*/

