function isIE(){
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function clearSearchField(input){
	if(input.value == "Buscar..."){
		input.value = "";
	}
}

function fillSearchField(input){
	if(input.value == ""){
		input.value = "Buscar...";
	}
}

function updateVideo(section,url,title){
	$('player').update('<h4>'+title+'</h4><div class="aligncenter" style="width:566px;"><div class="outlined"><object type="application/x-shockwave-flash" width="556" height="385" data="http://www.youtube.com/v/'+url+'&hl=en&fs=1&rel=0"><param name="movie" value="http://www.youtube.com/v/'+url+'&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param></object></div></div>');
}

function styleRadio(radio){
	if(!isIE()){
		radio = document.getElementById(radio);
		var name = radio.name;
		var form = radio.form;
		var radioGrp = form.getInputs('radio', name);
		
		for(i=0; i < radioGrp.length; i++){
			if (radioGrp[i].checked == true) {
				radioGrp[i].addClassName('radio-checked');
			}else{
				radioGrp[i].removeClassName('radio-checked');
			}
		}
	}
}

function GetTopLeft(elm){ // Copyright 2006-2007 javascript-array.com
        var x, y = 0;
    //set x to elm’s offsetLeft
    x = elm.offsetLeft;
    //set y to elm’s offsetTop
	y = elm.offsetTop;
    //set elm to its offsetParent
    elm = elm.offsetParent;
    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent
    while(elm != null){
        x = parseInt(x) + parseInt(elm.offsetLeft);
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
     }
    //here is interesting thing
    //it return Object with two properties
    //Top and Left
    return {Top:y, Left: x};
}

function MouseXY(e){
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	return {mX: posx, mY: posy};
}


function hideTT(){
	if(!isIE()){
		tooltip = $('tooltip');
	}
	new Effect.Fade(tooltip, { duration: 0.001 });
}

function showTT(text,elm,evento){	
	x = MouseXY(evento).mX;
	y = GetTopLeft(elm).Top;
	if(!isIE()){
		tooltip = $('tooltip');
	}
	$('tooltip').update('<div class="ttip"></div><p>'+text+'</p>');
	tooltip.style.left = x-30+'px';
	tooltip.style.top = y+30+'px';
	new Effect.Appear(tooltip, { duration: 0.2 });
}

function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<li>'+status+'<span class="date"> - '+relative_time(twitters[i].created_at)+'</span></li>');
  }
  document.getElementById('latest-tweets').innerHTML = statusHTML.join('');
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'Hace menos de 1 minuto';
  } else if(delta < 120) {
    return 'Hace poco más de 1 minuto';
  } else if(delta < (60*60)) {
    return 'Hace ' + (parseInt(delta / 60)).toString() + ' minutos';
  } else if(delta < (120*60)) {
    return 'Hace menos de 1 hora';
  } else if(delta < (24*60*60)) {
    return 'Hace ' + (parseInt(delta / 3600)).toString() + ' horas';
  } else if(delta < (48*60*60)) {
    return 'Hace 1 d&iacute;a';
  } else {
    return 'Hace ' + (parseInt(delta / 86400)).toString() + ' d&iacute;as';
  }
}

function slideWidget(elm1,elm2,elm3){
	var display = $(elm1).getStyle('display');
	if (display == 'none'){
		new Effect.BlindDown(elm1, {duration: 0.5});
		new Effect.BlindUp(elm2, {duration: 0.5});
		new Effect.BlindUp(elm3, {duration: 0.5});
	}
}