﻿var tar = null;
function boxOpen(obj,callback){
	
	tar = '#' + obj;
	boxPos();
	
	$('#boxBg').css({'display':'block','opacity':0.9});
	$(tar).css('display', 'block');
	
	$('#boxBg').bind('click', boxClose);
	
	if(callback != undefined)
		callback();
	
};
function boxPos(){
	var ww = $(window).width();
    var hw = $(window).height();
    var hd = $(document).height();
    var scrollTop = $(window).scrollTop();
    $('#boxBg').width(ww);
    $('#boxBg').height(hd);
	
	var width = $(tar).width();
	var height = $(tar).height();
	var marginLeft = -parseInt(width/2);
	var marginTop = -parseInt(height/2);
	
	if (browser() == "IE6") {
		var top = scrollTop + parseInt((hw - height)/2);
		$(tar).css({'marginLeft':marginLeft, 'top':top});
	}else{
		$(tar).css({'marginLeft':marginLeft, 'marginTop':marginTop});
	}
}
function boxClose(){
	$('#boxBg').animate({'opacity':0},200,function(){
		$(tar).css('display','none');
		$('#boxBg').css('display','none');
		$('#boxBg').unbind('click');
	});
}
$(window).resize(function(){
    boxPos();
});
$(window).scroll(function(){
    boxPos();
});
function browser(){
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = b_version.split(";");
	var trim_Version = version[1].replace(/[ ]/g,"");
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){
		return "IE7";
	}else if (browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){
		return "IE6";
	} 
}