//Initial js functions to run when js document is loaded
   checkBrowserWidth();
//Load when the page is ready - Using jQuery to run events
$(document).ready(function(){
$(window).resize(checkBrowserWidth);

 $.tabs('container_news');
 $.tabs('container_mz',2);
 $.tabs('container_dept');
 $.tabs('container_dqjs');
 $.tabs('container_kyjx');
 
 // $.tabs('container_dept_index');
 
 //优化页面加载性能，放到首页
// $.tabs('container_mzxx');
// $.tabs('container_dept');
// $.tabs('container_dept_index');
// $.tabs('container_dqjs');
// $.tabs('container_kyjx');
//$.tabs('container_nurse_index');


}
);



///////////////////////////  ajax call to get code off the server for display dependent code ///////////////////////////////////////
function parseCode(o,placement){
	$.get(o,function(code){										  	   
		  code=code.replace(/&/mg,'&#38;');
		  code=code.replace(/</mg,'&#60;');
		  code=code.replace(/>/mg,'&#62;');
		  code=code.replace(/\"/mg,'&#34;');
		  code=code.replace(/\t/g,'  ');
		  code=code.replace(/\r?\n/g,'<br>');
		  code=code.replace(/<br><br>/g,'<br>');
		  code=code.replace(/ /g,'&nbsp;');
		 $('#'+placement).html(code);
	}
	);
 }


///////////////////////////  resolution dependent code ////////////////////////////////////////////////////////////////////////////////
function checkBrowserWidth(){
	var theWidth = getBrowserWidth();
	if (theWidth == 0){
		var resolutionCookie = document.cookie.match(/(^|;)tmib_res_layout[^;]*(;|$)/);

		if (resolutionCookie != null){
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
			}
	
		$(document).load(checkBrowserWidth);
		return false;
	}

	if (theWidth > 900){
		setStylesheet("1024 x 768");
		document.cookie = "tmib_res_layout=" + escape("1024 x 768");
	}else{
		setStylesheet("");
		document.cookie = "tmib_res_layout=";
	}
	return true;
};




function getBrowserWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth != 0){
		return document.documentElement.clientWidth;}
	else if (document.body){
		return document.body.clientWidth;
	}
	return 0;
};




function setStylesheet(styleTitle){
	var currTag;

	if (document.getElementsByTagName){
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++){
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")){
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle){
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};



//////////////////// tabs jquery plugin ////////////////////////////////////////////////////////////////////////////
$.tabs = function(containerId, start) {
    var ON_CLASS = 'on';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:eq(' + i + ')').css({display:"block"});
    $(id + '>ul>li:nth-child(' + (i+1) + ')').addClass(ON_CLASS);
      // add by whq for 'more'
        $(id + '>ul>li>span').css({display:"none"});
        $(id + '>ul>li>span.whq1').css({display:"block"}); 
      //end add

    $(id + '>ul>li>a').mouseover(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);          
            if (target.size() > 0) {
                $(id + '>div:visible').css({display:"none"});
                target.css({display:"block"});
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS); 
                
                //add by whq for 'more'                  
                  var ws=re.exec(this.href)[1].substring(10,11) ;
                  $(id + '>ul>li>span').css({display:"none"});
                  $(id + '>ul>li>span.whq' + ws).css({display:"block"});
                //end add
            } else {
                alert('There is no such container.');
            }
        }
        return false;
    });
};







