
/**
* add a value into a input box  jQuery('input#IDINPUT').hint();
* <input type="text" name="urlinput" id="urlinput" title="For example: http://www.youtube.com/watch?v=R7yfISlGLNU">
* jQuery('input#urlinput').hint();
*
*/

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) {
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};


/**
* convert seconds to minutes 
*
*/
function secondsToString(seconds)
{

    var numdays = Math.floor(seconds / 86400);
    var numhours = Math.floor((seconds % 86400) / 3600);
    var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
    var numseconds = parseInt((seconds % 86400) % 3600) % 60;
    result = '';
    if(numdays > 0){
        result = numdays + " days ";
    }
    if(numhours > 0){
        result += numhours + ":";
    }

    numminutes = (numminutes > 9)?numminutes:'0' + numminutes;
    result += numminutes + ":";

    numseconds = (numseconds > 9)?numseconds:'0' + numseconds;
    result += numseconds ;

    return result; //numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds";

}

function objectTest(obj)
{
    for (var i in obj){
     alert(i)
    }
}

/*
 * retorna el id del video parandole la URL
 */
function getVideoId(url)
{
     uri = url.split("=")[1];
     uri = uri.split("&")[0];
     return uri;
}

/*
 * retorna la imagen de youtube
 * imgUrl_big   = getScreen("uVLQhRiEXZs");
 * imgUrl_small = getScreen("uVLQhRiEXZs", 'small');
 */
function getScreen( url, size )
{
  if(url === null){ return ""; }

  size = (size === null) ? "big" : size;
  var vid;
  var results;

  results = url.match("[\\?&]v=([^&#]*)");

  vid = ( results === null ) ? url : results[1];

  if(size == "small"){
    return "http://img.youtube.com/vi/"+vid+"/2.jpg";
  }else {
    return "http://img.youtube.com/vi/"+vid+"/0.jpg";
  }
}

function openwindowifr(uri,title,width,height)
{
    width  = (width != '' || width == 'undefined')?width:'80%';
    height = (height != '' || height == 'undefined')?height:'80%';
    jQuery.fn.colorbox({width:width, height:height,iframe:true,href:uri,open:true,title:title})
}

function openwindow(uri,title,width,height)
{
     width  = (width != '' || width == 'undefined')?width:'80%';
     height = (height != '' || height == 'undefined')?height:'80%';
     jQuery.fn.colorbox({width:width, height:height,href:uri,open:true,title:title})
}

function openwindowInline(id,title,width,height)
{
     width  = (width != '' || width == 'undefined')?width:'80%';
     height = (height != '' || height == 'undefined')?height:'80%';
     jQuery.fn.colorbox({width:width, height:height,href:id,open:true,inline:true})
}
function getcache()
{
   randomx = new Date().getTime();
   return randomx;
}

function resetvars()
{
     current_song = 0;
     last_id      = -2;
}
