$(document).ready(function(){

  $.preloadCssImages();
  
  //rounded table corners
  var tables = $("table");
  for(i = 0; i < tables.length; i++)
  {
    var t = tables.eq(i);
    var c = $("<div class='table'></div>");
    
    var margin = {
            T: parseInt(t.css('marginTop'))||0,     R: parseInt(t.css('marginRight'))||0,
            B: parseInt(t.css('marginBottom'))||0,  L: parseInt(t.css('marginLeft'))||0
    };
    var width = parseInt(t.width())||0;
    
    c.css("margin", margin.T+'px '+margin.R+'px '+margin.B+'px '+margin.L+'px');
    t.css("margin", 0);
    c.css("width", width+'px');
    
    t.wrap(c);
  }
  $(".table").corner("round 10px");
  
  //rounded news corners
  $(".news_img").wrapInner("<div class='news_img_inner'></div>");
  $(".news_img_inner").corner("round 3px").parent().css({padding: '1px'});
  $(".news_img").corner("round 5px");
 /* 
  //rounded image borders and image align with right margin
  var images = $("#cnt2 img");
  for(i = 0; i < images.length; i++)
  {
    var t = images.eq(i);
    var c = $("<span class='cnt_image_border'></span>");
    var floated = t.attr("align")||t.css("float");
    var margin = {
            T: parseInt(t.css('marginTop'))||0,     R: parseInt(t.css('marginRight'))||0,
            B: parseInt(t.css('marginBottom'))||0,  L: parseInt(t.css('marginLeft'))||0
    };
    var border = {
            T: parseInt(t.css('borderTopWidth'))||0,     R: parseInt(t.css('borderRightWidth'))||0,
            B: parseInt(t.css('borderBottomWidth'))||0,  L: parseInt(t.css('borderLeftWidth'))||0
    };
    var width = parseInt(t.width())||0;

    c.css("float", floated);
    t.css("float", "left");//Fix
    c.css("margin", margin.T+'px '+margin.R+'px '+margin.B+'px '+margin.L+'px');
    t.css("margin", 0);
    
    if(floated == "left")
      c.css("marginLeft", "0px");
    else if(floated == "right")
      c.css("marginRight", "0px"); 
     
    //Some browser issues
    if(width > 0)
      c.css("width", width+ border.L+border.R +"px");
    if(width > 0 && $.browser.msie && $.browser.version == "6.0")
      c.css("width", width+"px");
    
    //IE anchor fix
    if($.browser.msie)
      t.closest("a").click( function(){location.href = $(this).attr('href'); return false;} );
     
    t.wrap(c); 
  }
  $(".cnt_image_border").corner("7px");
  */
  
  // initialize scrollable 
  $("div.scrollable").scrollable({size: 3});
  $(".items img").click(function() {
    var url = $(this).attr("src").replace("100x75", "280x230");
    var alt = $(this).attr("alt");
    var wrap = $("#image_wrap").fadeTo("medium", 0.5); 

    var img = new Image(); 
    img.onload = function() {  
        wrap.find("img").attr("src", url);
        wrap.find("img").attr("alt", alt);
        wrap.find("img").attr("title", alt);
        wrap.fadeTo("fast", 1); 
    }; 
    img.src = url; 
  }).filter(":first").click();
  
  
  // --- Chem Search: TABY
  
  $('#search_parameters_button').click( function() {
  		
  		$('#search_machines').hide();
  		$('#search_parameters').show();
  		$('#search_machines_button').removeClass('hover');
  		$(this).addClass('hover');
  });
  
  $('#search_machines_button').click( function() {
  		
  		$('#search_machines').show();
  		$('#search_parameters').hide();
  		$('#search_parameters_button').removeClass('hover');
  		$(this).addClass('hover');
  });
  
  if(typeof clickSearchTab == 'function') { 
  		clickSearchTab();
  }
  
  // --- END CHEM SEARCH
  
});
