function trim(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
//TODO: optimize this function, it lets the browser freeze for 3-5 secs
function reparseCss(file) {
   $.get(file, function(info){
      info = info.replace(/[\n]/g, '').replace(/\/\*.*?\*\//g, '');
      info = info.match(/[^\}]*?\{.*?\}/g);
      for (var i = 0; i < info.length; i++) {
         var css = info[i].match(/(.*)\{(.*)\}/);
         var element = trim(css[1]).replace(/[^,]*:(hover|active|visited|link)/, '');
         var styles = css[2].match(/.*?:.*?;/g);
         if (styles) {
            for (var j = 0; j < styles.length; j++) {
               var style = styles[j].match(/(.*?):(.*?);/);
               var type = trim(style[1]);
               var value = trim(style[2]);
               if (type != 'background-image') { //TODO: rebuild this
                  $(element).css(type, value);
               }
               if (type == 'height' && value == '100%') {
                  $(element).css('margin-bottom', '-5px'); //TODO: figure out this
               } else if (type == 'height') {
                  if (parseInt($(element).css('font-size')) > parseInt($(element).css('height'))) {
                     $(element).css('overflow-y', 'hidden');
                  }
               }
               if (type == 'border-spacing' && value == '0px') {
                  $(element).attr('cellspacing', 0);
               }
               if (type == 'min-width') {
                  $(element).each(function(){
                     $(this).children('.__FIX_min-width').remove();
                     $('<div class="__FIX_min-width"></div>').css({
                        'width': value,
                        'height': '1px',
                        'overflow': 'hidden'
                     }).appendTo(this);
                  });
               }
            }
         }
      }
   });
}
$(document).ready(function() {
   if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
      reparseCss('media/css/style.css');
      window.onresize = function() {
         var ie6width = '1000px';
         if (document.body.clientWidth > 1000)
            ie6width = document.body.clientWidth + 'px';
         $('.logo_hide').css('width', ie6width);
      };
      window.onresize();
      $('.title a.top').remove();
      $('.title').height(20);
   }
});
window.onload = function() {
   if ($.browser.msie && $.browser.version.substr(0,1) < 8) {
      $('.textWidthHolder').each(function(){
         $(this).find('.picInfo').css('width', $(this).find('.pic').width());
      });
   }
}

