

// Function to find out size of an object.
Object.size = function(obj) {
  var size = 0, key;
  for(key in obj) {
    if(obj.hasOwnProperty(key)) size++;
  }  
  return size;
}

// Function to return sub-objects keys.
Object.keys = function(obj) {
  var keys = new Array(), key, i=0;
  for(key in obj) {
      if(obj.hasOwnProperty(key)) keys[i++] = key;
  }
  return keys;
}

/*
  var a = "";
  var keys = Object.keys(myObject);
  if(keys.length > 0) {
    for(var index in myObject) {
      a += " ["+index+"] => "+ui.index;
    }
  }
  alert(a);
*/

/**
 * Market flashnews. Show/hide comment when user do a click onto a title.
 */ 
function marketFlashnews() {
  if ($("#block-market-flashnews-content").html() != '') {

    // find out which title should be clickable
    $("#block-market-flashnews-content .rollover h5").each(function() {
      var content = $(this).parent().children("p").html();
      if (jQuery.trim(content) != '') {
        var str  = $(this).html();
        $(this).html("<a>" + str + "</a>");
      }
    });
  
    // clickable items can roll over the content boxes
    $("#block-market-flashnews-content .rollover h5 a").click(function() {
      if ($(this).parent().parent().children("p").is(":hidden")) {
        $("#block-market-flashnews-content .rollover p").slideUp("fast");
        $(this).parent().parent().children("p").slideDown("fast");
      } else {
        $(this).parent().parent().children("p").slideUp("fast");
      }
    });
  
  }
}

/**
 * Initialize the tabs on a whole document.
 */
$(document).ready(function(){ 
  $("div.ui-tabs").tabs(); 
});

/**
 * Change the button for an active section in the main menu.
 * @see http://www.hunlock.com/blogs/The_Complete_Javascript_Strings_Reference 
 */
$(document).ready(function(){ 
  var uri = window.top.location.href;
  var host = window.top.location.hostname;
  var path = window.top.location.pathname;  
  var elem = uri.split("/");
  var rawe = elem[3].split("?");
  var objname = rawe[0].replace(/<([^>]+)>/g,''); // stripTags()
  if ($.Q.p != '') {
    objname = $.Q.p;
  } else {
    if (objname == '') objname = 'front';
  }

  $("#menu li").each(function() {
    if ($(this).attr("cid") == objname || $(this).attr("id") == "section-"+objname) {
      $(this).addClass("active");
    }
  });
});

/**
 * Rooll over block.
 */
$(document).ready(function(){ 
  $("fieldset.collapsible legend").click(function() {
    var wrapper = "#" + $(this).parent().attr("id") + " div.fieldset-wrapper";
    if ($(wrapper).is(":hidden")) {
      $(wrapper).slideDown("fast");
      $(this).parent().removeClass("collapsed");
    } else {
      $(wrapper).slideUp("fast");
      $(this).parent().addClass("collapsed");
    }
  });
});

