﻿// JavaScript Document
var target_arr = [];
var all_a = document.getElementsByTagName('a');
var all_input = document.getElementsByTagName('input');

function addTargetArr(arr){
	var testString = /^#PB_inline\?width=\d{1,4}&height=\d{1,4}&inlineId=\w{1,30}$/;
	for(var i=0;i<arr.length;i++){
		if(arr[i].className == 'phoenixbox' && testString.test(arr[i].getAttribute('alt'))){
			target_arr.push(arr[i]);
		}
	}
}
addTargetArr(all_a);
addTargetArr(all_input);

for(var i=0;i<target_arr.length;i++){
	target_arr[i].onclick = function(){showPhoenixBox(this)};
}
function showPhoenixBox(obj){

	var z =  obj.getAttribute('alt').split('?')[1];
	var _z = z.split('&');
	if(document.getElementById(_z[2].split('=')[1]))
	{
		document.getElementById(_z[2].split('=')[1]).style.display = '';
		if(/MSIE 6.0/ig.test(navigator.appVersion))
		{
			var PB_iframe = document.createElement('iframe');
			PB_iframe.setAttribute('id','PB_iframe');
			PB_iframe.setAttribute('frameborder','0');
			document.body.appendChild(PB_iframe);
		}
		var PB_window = document.createElement('div');
		PB_window.setAttribute('id','PB_window');

		var PB_overlay = document.createElement('div');
		PB_overlay.setAttribute('id','PB_overlay');

		document.body.appendChild(PB_window);
		var boxTitle = document.createElement('div');
		var boxClose = document.createElement('span');
		var boxH1 = document.createElement('h1');

		boxTitle.setAttribute('id','PB_boxTitle')
		boxClose.innerHTML = "<a href=javascript:PB_close('"+_z[2].split('=')[1]+"');>关闭</a>";
		boxH1.innerHTML = obj.getAttribute('title');

		boxTitle.appendChild(boxClose);
		boxTitle.appendChild(boxH1);
		PB_window.appendChild(boxTitle);
		document.body.appendChild(PB_overlay);

		document.getElementById(_z[2].split('=')[1]).setAttribute('class','PB_boxIn');
		document.getElementById(_z[2].split('=')[1]).setAttribute('className','PB_boxIn');

		PB_window.appendChild(document.getElementById(_z[2].split('=')[1]));


		PB_window.style.width = _z[0].split('=')[1] +'px';
		PB_window.style.height = _z[1].split('=')[1] +'px';
		PB_window.style.marginLeft = 0-(PB_window.clientWidth/2) +'px';
		if (! (/MSIE 6.0/ig.test(navigator.appVersion)) )
		PB_window.style.marginTop = 0-(PB_window.clientHeight/2) +'px';

	}
}
function PB_close(obj){
	document.body.appendChild(document.getElementById(obj));
	document.getElementById(obj).style.display = 'none';
	if(/MSIE 6.0/ig.test(navigator.appVersion)) document.body.removeChild(document.getElementById('PB_iframe'));
	document.body.removeChild(document.getElementById('PB_overlay'));
	document.body.removeChild(document.getElementById('PB_window'));
}