// JavaScript Document
$(document).ready(function(){
    if($('.clickImg').is('a')){
        $('.clickImg').click(function(){
          popupImage($(this).attr('value'));
          return false;
        })
        
      }

	//<img src="images/fpress-img.gif">
	$('.qdf').mouseover(function(){
		$('#showimg').html('<img src="'+$(this).attr('value')+'">');
	});
	$('.qdf').mouseout(function(){
		$('#showimg').html('');
	});
	
	$('.cilImg').click(function(){
	//alert($(this).prev("strong") .attr('value'));
		$('#popup').remove();
		$('body').append('<div id="popup"><img  src="'+$(this).prev("strong") .attr('value')+'"></div>');
		//alert(document.body.clientWidth);
		//alert(document.body.offsetWidth);

		$('#popup').css({'position':'absolute','top':0,'left':0,'height':'100%','width':'100%','background':'#fff'});
		$('#popup').find('img').load(function(){
			var imgH=$(this).height();
			var imgW=$(this).width();
			var webW=parseInt(document.body.clientWidth);
			var webH=parseInt(document.body.clientHeight);
			var pleft;
			var ptop;
			if(imgW>webW){ 
				pleft='0px';
				$('body').css({'width':imgW+'px'});
				$('#popup').css({'width':imgW+'px'});
			}else {pleft=(webW-imgW)/2+'px';}
			if(imgH>webH){ 
				ptop='0px';
				$('body').css({'height':imgH+'px'});
				$('#popup').css({'height':imgH+'px'});
			}else{ ptop=(webH-imgH)/2+'px';}
			var pp=ptop+" 0 0 "+pleft;
			$('#popup').find('img').css({'position':'static','border':'1px solid #666','margin':pp});
		});
		
		
		
		
		//$('#popup').css({'padding':pp});
		$('#popup').click(function(){$(this).hide();$('body').css({'height':'','width':''});});
	});
	
	if($('#sImg').offset()) $('#lImg').css({'top':($('#sImg').offset().top-135)+'px'});
	if($.browser.msie){
		if(($.browser.version)=='6.0'){
			if($('#sImg').offset()) $('#lImg').css({'top':($('#sImg').offset().top-139)+'px'});
		}
		
	}else{
		if($('#sImg').offset())
		$('#lImg').css({'top':$('#sImg').offset().top+'px','left':'550px'});
	}
	if($('#sImg').height()<400) {
		$('#minH').height(400-$('#sImg').height());
													
	}else $('#minH').height(0);
	//alert();//293 325 182
	var dfH=0;
	$('#sImg > a').mouseover(function(){
		//if($.browser.msie)	var dfH=182;
		//else var dfH=312;
		$('#lImg').find('img').attr('src',$(this).attr('value'));
		if(dfH==0) dfH=parseInt($('#lImg').css('top'));
		
		var ind=$('#sImg > a').index(this)+1;
		if(ind%2>0)
			ind=Math.floor(ind/2)+1;
		else
			ind=Math.floor(ind/2);
		ind -=1;
		indH=dfH+ind*98;
		
		var limgH=$('#lImg').height()+40;
		var okH=$('#sImg').height()-12;
		var ah=$('#minH').height()+$('#sImg').height();
		if(limgH>ah){
			$('#minH').height(limgH-$('#sImg').height());
		}else if($('#minH').height()>0){
			$('#minH').height(limgH-$('#sImg').height());
		}
		//if($('#minH').height()<($('#lImg').height()+40)) $('#minH').height($('#lImg').height()+40);
		//var limgTop=($('#lImg').offset().top-143);
		//$('#lImg').css({'top':indH+'px'});
		
		$('#lImg').stop();
		if((limgH+indH-dfH)<okH){
			$('#lImg').animate({top: indH+'px'}, 500);
		}else if(okH-limgH>0)
			$('#lImg').animate({top: (okH-limgH+dfH)+'px'}, 500);
		else
			$('#lImg').animate({top: dfH+'px'}, 10);
		//Math.floor(ind/2)//316-173 = 143 414
		//alert($(this).offset().top );
	});
	
	$('#lImg').find('img').load(function(){
		var bh=$('#lImg').height()+40;
		var ah=$('#minH').height()+$('#sImg').height();
		if(bh>ah)
			$('#minH').height(bh-$('#sImg').height());
	});
});

      function popupImage(img){
        var mstr = "<HTML><HEAD><LINK REL='stylesheet' TYPE='text/css' HREF='/common.css?'><script language='javascript' type='text/javascript' src='/js/jquery.js'></script><script language='javascript' type='text/javascript' src='/js/init.js'></script></HEAD><BODY><CENTER><TABLE>";
          mstr+= "<TR><TD ALIGN=CENTER><A CLASS=redlnk HREF='javascript:window.close()' style='color:#d20010; font-size:11px;'>Close</A></TD></TR>";
          mstr+= "<TR><TD ALIGN=CENTER HEIGHT=10>&nbsp;</TD></TR>";
          mstr+= "<TR><TD ALIGN=CENTER><IMG SRC='"+img+"' BORDER=0 ></TD></TR>";
          mstr+= "</TABLE></CENTER></BODY></HTML>";
                      if ((navigator.appName=="Netscape")&& (parseInt(navigator.appVersion)<=4)) {
                              winwidth = screen.availWidth;
                              winheight = screen.availHeight
                   }
          msg=window.open("","","top=0,left=0,scrollbars=yes,resizable=yes");
          msg.document.write(mstr);
          return false;
        }

