/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    function setExpand(timg){
            if (timg.parent().get(0).tagName=='A') return;
            var o_height=timg.height();
            var o_width= timg.width();
            var myhref= timg.attr('src');
            var alt=timg.attr("alt");
            if (jQuery.browser.msie){
                var imgs = new Image();
                imgs.src = myhref;

                var n_height=imgs.height;
                var n_width=imgs.width;
            }
            else{
                var n_height=timg.attr("naturalHeight");
                var n_width= timg.attr("naturalWidth");
                var imgs=timg.clone();
                imgs.height(n_height);
                imgs.width(n_width);
                imgs.attr("hspace",0);
                imgs.attr("vspace",0);
            }
            if(n_height>o_height || n_width>o_width){
               var expandimg=jQuery("<div></div>");
               timg.css("cursor","pointer" );
               timg.click(function(){
                   var w_w=jQuery(window).width();
                   var w_h=jQuery(window).height();
                   var ratio=1.0;
                   if (n_width+50 > w_w) ratio=w_w/(n_width+50);
                   if (n_height+70 > w_h){
                     ratio2=w_h/(n_height+70);
                     if (ratio>ratio2) ratio=ratio2;
                   }
               
                   n_height = n_height*ratio;
                   n_width = n_width*ratio;
                   if (jQuery.browser.msie){
                       imgs.height=n_height;
                       imgs.width=n_width;
                   }
                   else{
                       imgs.height(n_height);
                       imgs.width(n_width);
                   }
                   var div=jQuery("<div></div>");
                   div.dialog({
                    title:alt,
                    width:n_width+7,
                    height:n_height+12,
                    overlay:{opacity:0, background:'#000000'}
                  }).append(imgs);
               });
            }
    }

    function checkSize(timg,maxwidth){
        var o_height=timg.height();
        var o_width= timg.width();
        if(o_width>maxwidth){
            var newheight=(o_height*maxwidth)/o_width;
            timg.height(newheight);
            timg.width(maxwidth);
        }
    }

    jQuery(window).load(function(){
        //jQuery("td.story-container img").each(function(i){
        //    checkSize(jQuery(this),440);
        //    setExpand(jQuery(this));
        //});
        jQuery(".maintext img").each(function(i){
            checkSize(jQuery(this),440);
            setExpand(jQuery(this));
        });
        jQuery(".comment img").each(function(i){
            setExpand(jQuery(this));
        });
    });
   


