/*
    Version: 2.0
    Author: dingo
    Author URI: http://imdingo.com
*/

function getTag() {
    var strHref = window.location.href
    var strCurrentTag = strHref.substr((strHref.indexOf('#') + 1));
    var strSub = strCurrentTag.split('/')
    return strSub;
}

function UpdateStyle(id) {


    var y = document.getElementById('cclist').getElementsByTagName('div');
    for (var i = 0;i < y.length; i++)
    {
        if(y[i].className == "itemthis")
        {
            y[i].className = "item";
        }
    }
	
    document.getElementById(id).className = "itemthis";
}

function UpdateStyle2(id) {


    var y = document.getElementById('nlistDier').getElementsByTagName('div');
    for (var i = 0;i < y.length; i++)
    {
        if(y[i].className == "itemthis")
        {
            y[i].className = "item";
        }
    }
	
    document.getElementById(id).className = "itemthis";
}

function getTransport() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
}

function appear(content, value) {
    if (typeof value == 'undefined') value = 0;
    if (value > 1) return;
    var property = content.filters ? 'filter' : 'opacity';
    content.style[property] = content.filters ? 'alpha(opacity=' + value*100 + ')' : value;
    setTimeout(function () {appear(content, value + .1)} , 50);
}

function updateChange(xhr,xhrTag) {


    if (xhrTag){
		var result = window.ccontent!=null&&ccontent.tagName=="DIV";
		if(result)
		{
        updateDIV = 'ccontent';
		}
		else
		{
			
		updateDIV = 'main';	
		}

    } else {
        updateDIV = 'main';
    }
	
	
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            var content = document.getElementById(updateDIV);
            if (com.asual.util.Browser.isIE()) {
                var _content = document.getElementById(updateDIV);
                if (_content == null) {
                    var _content = content.cloneNode(false);
                    _content.id = updateDIV;
                    _content.style.position = 'absolute';
                    _content.style.top = content.offsetTop;
                    _content.style.left = '50%';
                    _content.style.width = content.offsetWidth;
                    _content.style.marginLeft = -content.offsetWidth/2;
                    document.body.appendChild(_content);
                }
                _content.innerHTML = xhr.responseText;
                content.style.height = _content.offsetHeight;
                //appear(_content);
            } else {
                content.innerHTML = xhr.responseText;
                appear(content);
            }
        } else {
            //alert('Error: ' + xhr.status + '!');
        }
    }
}

function handleChange(event) {
    var strCurrentTag = getTag();
    var strNewTag = event.path.split('/');
    var strTimeStamp = Math.round(Math.random()*10000);
	var strURIgo = 'main.asp?m=' + strNewTag[1] + '&s=' + strNewTag[2];
	var strURIgo2 = 'main.asp?m=' + strNewTag[1] + '&s=' + strNewTag[2] + '&id=' + strNewTag[3];
    var strURI = 'main.asp?m=' + strNewTag[1] + '&s=' + strNewTag[2] + '&id=' + strNewTag[3] + '&t=' + strTimeStamp;
    var strURIP = 'main.asp?m=' + strNewTag[1] + '&s=' + strNewTag[2] + '&id=' + strNewTag[3] + '&p=item' + '&t=' + strTimeStamp;
    var xhr = getTransport();
    		
    xhr.onreadystatechange = function() {

		if (strNewTag[4]=='')
		{
			updateChange(xhr,true);
		}
		
		else
		{
			updateChange(xhr,false);
		}
    }
    
if (com.asual.util.Browser.isIE()){
	    if (strNewTag[1] == ''){
        xhr.open('get', 'main.asp?m=news&s=all&t=' + strTimeStamp, true);

		
    } else if (strNewTag[2] == 'page') {
        xhr.open('get', strURI, true);
		
		
    }else if (strCurrentTag[1] != strNewTag[1]) {
        xhr.open('get', strURIgo, true);
		
    }else if (strCurrentTag[1] == strNewTag[1] && strCurrentTag[2] !='' && strCurrentTag[2] != strNewTag[2]) {
        xhr.open('get', strURI, true);
		
    }else if (strCurrentTag[1] == strNewTag[1] && strCurrentTag[2] == strNewTag[2]&& !(document.getElementById('ccontent') == null) ) {
        xhr.open('get', strURIP, true);
		
    }else if (strCurrentTag[1] == strNewTag[1] && !(document.getElementById('ccontent') == null) && strCurrentTag[2] != strNewTag[2]) {
        xhr.open('get', strURIP, true);
	
    } else if (strCurrentTag[1] == strNewTag[1] && !(document.getElementById('ccontent') == null)) {
		//alert(strCurrentTag[1]);
        xhr.open('get', strURIP, true);
	
    } else if (strCurrentTag[1] == '') {
        xhr.open('get', strURI, true);

    } else if (strCurrentTag[1] == strNewTag[1] && strCurrentTag[2] == strNewTag[2] && strCurrentTag[3] =='')  {
        xhr.open('get', strURIgo, true);

    } else if (strCurrentTag[1] == strNewTag[1] && strCurrentTag[2] == strNewTag[2] && strCurrentTag[3] == strNewTag[3] && strCurrentTag[2] !='')  {
        xhr.open('get', strURIgo2, true);

    } else {
        xhr.open('get', strURIgo, true);

    }
	
}else{

    if (strNewTag[1] == ''){
        xhr.open('get', 'main.asp?m=news&s=all&t=' + strTimeStamp, true);
    } else if (strNewTag[2] == 'page') {
        xhr.open('get', strURI, true);
    } else if (strCurrentTag[1] == strNewTag[1] && !(document.getElementById('detail') == null) && strCurrentTag[2] != strNewTag[2]) {
        xhr.open('get', strURI, true);
    } else if (strCurrentTag[1] == strNewTag[1] && !(document.getElementById('detail') == null)) {
        xhr.open('get', strURIP, true);
    } else if (strCurrentTag[1] == '') {
        xhr.open('get', strURIP, true);
    } else {
        xhr.open('get', strURI, true);
    }
}

    xhr.setRequestHeader('If-Modified-Since','0'); 
    xhr.send(null);
}

SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);