//converts RGB string to HEX - inspired by http://code.google.com/p/jquery-color-utils
  toHex = function(color){
    //valid HEX code is entered
    if(color.match(/[0-9a-fA-F]{3}$/) || color.match(/[0-9a-fA-F]{6}$/)){
      color = (color.charAt(0) == "#") ? color : ("#" + color);
    }
    //rgb color value is entered (by selecting a swatch)
    else if(color.match(/^rgb\(([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5]),[ ]{0,1}([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5]),[ ]{0,1}([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\)$/)){
      var c = ([parseInt(RegExp.$1),parseInt(RegExp.$2),parseInt(RegExp.$3)]);
      
      var pad = function(str){
            if(str.length < 2){
              for(var i = 0,len = 2 - str.length ; i<len ; i++){
                str = '0'+str;
              }
            }
            return str;
      }

      if(c.length == 3){
        var r = pad(c[0].toString(16)),g = pad(c[1].toString(16)),b= pad(c[2].toString(16));
        color = '#' + r + g + b;
      }
    }
    else color = false;
    
    return color
  }



function simulaTerminal() {
	var coloret = toHex($(".cursor").css("color"));
	if ( coloret == "#000000" ) {
		$(".cursor").css("color", "#e9e9e9")
	} else {
		$(".cursor").css("color", "#000000")
	}
}

$(document).ready(function(){
	
	// pestanyes
	$("#tabs").tabs();			
	$("#dialog_link, ul#icons li").hover(
		function() { $(this).addClass("ui-state-hover"); }, 
		function() { $(this).removeClass("ui-state-hover"); }
	);
	
	// tooltips
	$("#tabs li a").tooltip({left: 5, top: -100});

	// accordio
	$("#accordio:eq(0) > div").hide();
  	$("#accordio:eq(0) > h5").click(function() {
    $(this).next("div").slideToggle().siblings("div:visible").slideUp();
  	});
	setInterval ("simulaTerminal()", 800);
});
