﻿jQuery.fn.extend({
	getScrollTop:function(){
		IeTrueBody=function(){
			return (document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;
		};
		return $.browser.msie?IeTrueBody().scrollTop:window.pageYOffset;
	},
	docWidth:function(){
		if ($.browser.msie&&$.browser.version<7) {
			var scrollWidth=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth);
			var offsetWidth=Math.max(document.documentElement.offsetWidth,document.body.offsetWidth);
			if (scrollWidth<offsetWidth){
				return $(window).width();
			}else{
				return scrollWidth;
			};
		} else {
			return $(document).width();
		};
	},
	docHeight:function(){
		if ($.browser.msie && $.browser.version<7){
			var scrollHeight=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
			var offsetHeight=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);
			if(scrollHeight<offsetHeight){
				return $(window).height();
			}else{
				return scrollHeight;
			};
		}else{
			return $(document).height();
		};
	},
	cliWidth:function(){
		return document.documentElement.clientWidth;
	},
	cliHeight:function(){
		return document.documentElement.clientHeight;
	},
	center:function(){
		var w=$(this).width();
		var h=$(this).height();
		var cliHeight=$(document).cliHeight();
		var docHeight=(cliHeight/2-h/2)+$(document).getScrollTop();
		var docWidth=$(document).cliWidth()/2-w/2;
		$(this).css({position:'absolute',top:docHeight,left:docWidth});
	}
});
$(document).ready(function(){
	$('.proinfo img').hover(function(){
		$(this).css({border:'6px solid #d30500'});				
	},function(){
		$(this).css({border:'6px solid #ccc'});
	}).click(function(){
		var me=$(this);
		var href=me.attr('to')||me.attr('src');
		var w=me.width();
		var h=me.height();
		var x=me.offset().top;
		var y=me.offset().left;
		var mw=$(document).docWidth();
		var mh=$(document).docHeight();
		var ch=$(document).cliHeight();
		var top=(ch/2-300)+$(document).getScrollTop();
		var left=$(document).cliWidth()/2-300;
		$('.modal').remove();
		$('.imgbox').remove();
		$('body').append('<div class="modal"></div><div class="imgbox"><div class="close"></div></div>');
		$('.modal').css({width:mw,height:mh});
		$('.imgbox').css({width:1,height:1}).center();
		$('.imgbox').animate({width:600,left:'-=300px'},600,function(){
			$(this).animate({height:600,top:'-=300px'},500,function(){
				$('.imgbox').append('<img src="'+href+'" />').find('img').each(function(){
					var height=$(this).height();
					$(this).css({marginTop:(600-height)/2}).fadeIn();
				});
				$('.close').click(function(){
					$('.modal').remove();
					$('.imgbox').remove();
				});
				$(window).scroll(function(){
					$('.imgbox').center();
				});
			});
		});
		return false;
	});
	if($.browser.msie){
		$('.proimg').each(function(){
			var me=$(this);
			var src=me.attr('src');
			var w=me.width();
			var h=me.height();
			me.removeClass('proimg');
			me.attr('to',src);
			$(this).attr('src','images/blank.gif');
			$(this).css({width:w,height:h,visibility:'visible',filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="scale",src="'+src+'")'}).parent('div').css({background:'none'});
		});
	};
});