var $ = function(id){ return document.getElementById(id)};

var wa = new Array();
var ha = new Array();

window.onload=function(){
    fResizeImg(800, 600, 'pic');
}
	
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}
function PictureShowUp(i,l,t){
		var ii = i.substr(5,i.length);
		var cont = $('pic');
		var picbtn = getElementsByClassName('csson','span',cont)
		// alert();
		//alert(ii);
		//picbtn[ii].style.left = l + 10;
		//picbtn[ii].style.top = t + 10;
		picbtn[ii].style.display = ""
		picbtn[ii].onmouseover = function(){ this.style.display = ""}
		picbtn[ii].onclick = function(){  FullSize(ii) }
}
			
function PictureShowDown(i){
	var ii = i.substr(5,i.length);
	var cont = $('pic');
	var picbtn = getElementsByClassName('csson','span',cont)
	picbtn[ii].style.display = "none"
}
			
function FullSize(imgid){
	//alert(imgid);
	$("dialog").style.display = $("mask").style.display = "";
	obj=$('pic').getElementsByTagName('img');
	imgsrc = obj[imgid].src;
	$("dialog").innerHTML = "<img src="+imgsrc+" title='Click to close'>";
	$("dialog").style.width = wa[imgid] + "px";
	$("mask").style.width = wa[imgid] + 28 + "px"
	//alert(wa[imgid]);
	//alert(imgid);
	
	//alert(h[imgid]);
	$("dialog").style.height = ha[imgid] + "px";
	$("mask").style.height = ha[imgid] + 52 + "px";
	
	$("mask").style.marginLeft = -wa[imgid]/2- 14 + "px"
	$("dialog").style.marginLeft = -wa[imgid]/2  + "px"
	//alert(mask.style.marginLeft);
	
	$("mask").style.top = document.body.scrollTop + 205 + "px"
	$("dialog").style.top = document.body.scrollTop + 218 + "px"
	
		$('dialog').onclick = function(){
			$('dialog').style.display = "none"
			$('mask').style.display = "none"
		}

}
			
		
function fResizeImg(w, h, id){
	var img='';
	var obj;
	var mask = $('mask');
	var dialog = $('dialog');
	var cont = $('pic');
	var picbtn = getElementsByClassName('csson','span',cont)

	
	if(id==undefined)obj=document.images;
	else obj=$(id).getElementsByTagName('img');
	for(var i=0; i<obj.length; i++){
		img=obj[i];
		img.id = "imgid" + i;
		p=picbtn[i];
		//alert(obj[i].offsetLeft);
		
		//w1 = img.width;
		//alert(w1+"266");
		
		wa[i] = img.width;
		ha[i] = img.height;
		//alert(wa[i]);
		//alert(ha[i]);

	var span = document.createElement( "span" );
			var a = document.createElement( "a" );
			span.className = "csson";
			span.style.display = "none";
			span.style.position = "absolute";
			a.innerHTML = "Full size";
			span.appendChild( a );
			
			if(img.parentNode.nodeName == "A"){
				img.parentNode.parentNode.appendChild( span );	
			}else{
				img.parentNode.appendChild( span );	
			}
		
		
		if(img.width>w && (img.height<img.width)){
			img.height=img.height-(img.height/(img.width/(img.width-w)))
			img.width=w;

		
						
				img.onmouseover = function(){ 
				PictureShowUp(this.id,this.offsetLeft,this.offsetTop); 
				}
				
				img.onmouseout = function(){
				PictureShowDown(this.id); 
				}
		}else if(img.width>w &&img.height>h && (img.height>img.width)){
			img.width=w
			img.height=img.height-(img.height/(img.width/(img.width-w)))
			
			
			img.onmouseover = function(){ 
				PictureShowUp(this.id,this.offsetLeft,this.offsetTop); 
				}
				
				img.onmouseout = function(){
				PictureShowDown(this.id); 
				}
		}

        

		
		

	} // shawl.qiu script
}



//go to top
(function() {

function $(id) {
	return document.getElementById(id);
}

function setStyleDisplay(id, status) {
	$(id).style.display = status;
}

function goTop(acceleration, time) {
	acceleration = acceleration || 0.1;
	time = time || 10;

	var dx = 0;
	var dy = 0;
	var bx = 0;
	var by = 0;
	var wx = 0;
	var wy = 0;

	if (document.documentElement) {
		dx = document.documentElement.scrollLeft || 0;
		dy = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		bx = document.body.scrollLeft || 0;
		by = document.body.scrollTop || 0;
	}
	var wx = window.scrollX || 0;
	var wy = window.scrollY || 0;

	var x = Math.max(wx, Math.max(bx, dx));
	var y = Math.max(wy, Math.max(by, dy));

	var speed = 1 + acceleration;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var invokeFunction = "MGJS.goTop(" + acceleration + ", " + time + ")"
		window.setTimeout(invokeFunction, time);
	}
}

function switchTab(showPanels, hidePanels, activeTab, activeClass, fadeTab, fadeClass) {
	$(activeTab).className = activeClass;
	$(fadeTab).className = fadeClass;

	var panel, panelList;
	panelList = showPanels.split(',');
	for (var i = 0; i < panelList.length; i++) {
		var panel = panelList[i];
		if ($(panel)) {
			setStyleDisplay(panel, 'block');
		}
	}
	panelList = hidePanels.split(',');
	for (var i = 0; i < panelList.length; i++) {
		panel = panelList[i];
		if ($(panel)) {
			setStyleDisplay(panel, 'none');
		}
	}
}

window['MGJS'] = {};
window['MGJS']['$'] = $;
window['MGJS']['setStyleDisplay'] = setStyleDisplay;
window['MGJS']['goTop'] = goTop;
window['MGJS']['switchTab'] = switchTab;

})();




