
$(function(){

	$(".popbox").click(function(){

		W = $(window).width();

		H = $(window).height();

		var src = $(this).attr("href") + '&w=' + H +'&h=' + W;

		$("body").prepend(framework.replace(/#w#/ig,W).replace(/#h#/ig,H));
		
		if(src.search("chnglayer")>0){
			$("div#full_pop").css("left","5%");
			$("div#full_pop").css("width","90%");
			$("div#right50").remove(); //css("visibility","hidden");
			$("div#left50").remove(); //.css("visibility","hidden");
			//$("div#right50").css("width","0%");
			//$("div#left50").css("width","0%");
			$("div#center50").css("width","100%");
		}
		
		$("iframe#popIframe").attr("src",src);
		//$("ad_header_1000x120").css("display","none");
		if(document.getElementById("ad_header_1000x120"))
		document.getElementById("ad_header_1000x120").style.display = "none";

		lastScroll = $(window).scrollTop();

		$(window).scrollTop(0);

		$("html,body").css("overflow","hidden");

		fixH();

		return false;

	});

	$(".close").live("click",function(){

		removeBox();

	});



	document.onkeydown = function(e){

		if (e == null) { // ie

			keycode = event.keyCode;

		} else { // mozilla

			keycode = e.which;

		}

		if(keycode == 27)

			removeBox();

	}

});

function openDpanel(hrefurl){
	
	W = $(window).width();
	H = $(window).height();

	var src = hrefurl + '&w=' + H +'&h=' + W;

	$("body").prepend(framework.replace(/#w#/ig,W).replace(/#h#/ig,H));
		
		if(src.search("chnglayer")>0){
			$("div#full_pop").css("left","5%");
			$("div#full_pop").css("width","90%");
			$("div#right50").remove(); //css("visibility","hidden");
			$("div#left50").remove(); //.css("visibility","hidden");
			//$("div#right50").css("width","0%");
			//$("div#left50").css("width","0%");
			$("div#center50").css("width","100%");
		}
		
		$("iframe#popIframe").attr("src",src);
		if(document.getElementById("ad_header_1000x120"))
		document.getElementById("ad_header_1000x120").style.display = "none";

		lastScroll = $(window).scrollTop();

		$(window).scrollTop(0);

		$("html,body").css("overflow","hidden");

		fixH();

	//return false;
}

function removeBox(){

	$("#full_pop,.full_screen").remove();

	$("html,body").css("overflow","");
	if(document.getElementById("ad_header_1000x120"))
	document.getElementById("ad_header_1000x120").style.display = "block";
	
	$(window).scrollTop(lastScroll);

}

function fixH(){

	if($("#full_pop").size()){

	W = $(window).width();

	H = $(window).height();

	$("#full_pop_wrapper").height(H-80);

	

	$(window).resize(function(){ // do not assign onresize at first. only assign it when the the pop is shown first time

		fixH();

	});

	} else {

		$(window).unbind();

		return false;

	}

}
