﻿/*
 * **********************************************************************
 * -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
 * -- Author: mymingming
 * -- QQ: 154674958
 * -- Msn: chongchong2008@msn.com
 * -- Web: http://www.yc330.net
 * -- Date: 2008-08-30
 * -- LastDate: 2008-09-02
 * -- Note: 
 * -- Copyright(C) 2008 mymingming  7# YanJiang Road YiChang HuBei CHINA                   
 * **********************************************************************
 */

var __WEBPARTZONE_GROUP = window.WEBPARTZONE_GROUP = true;
var webPartTarget;
var webPartEventID;
var webPartHeight;
var webPartOldHeight;
var isShowZone;
var webPartSpeedInit,webPartSpeedStep,webPartSpeed;
var webPartItems = [];
initSpeed();

function initSpeed(){
    webPartSpeedInit = 0.03;
    webPartSpeedStep = 0.16;
    webPartSpeed = 0.001;
}

function webPart(eventSource,targetID){
	var target = document.getElementById(targetID) ;
        webPartTarget = target;
	if(!isShowZone){
		webPartOldHeight = webPartTarget.style.posBottom + webPartTarget.offsetHeight;		
                //alert("webPartTarget.style.margin : " + webPartTarget.childNodes[0].childNodes[0].childNodes[0].offsetTop);
	}

        webPartHeight = webPartOldHeight;
	
	if( target.style.display != "none" )
	{
		var objTarget = {};
        	objTarget.id = targetID;
		objTarget.height = webPartTarget.offsetHeight;
        	webPartItems.push(objTarget);

		webPartEventID = setInterval(webPartHide,100);
		eventSource.firstChild.src = __global.webSite.root + "Resources/Image/partzone_show.gif";
                eventSource.firstChild.alt = "展开";
	}
	else
	{
		webPartEventID = setInterval(webPartShow,100);
		target.style.display = "";
		eventSource.firstChild.src = __global.webSite.root + "Resources/Image/partzone_hide.gif";
		eventSource.firstChild.alt = "折叠";
	}
}

function webPartHide(){
        webPartSpeedInit += webPartSpeedStep;
        webPartSpeed += webPartSpeedInit;

        webPartHeight -= (webPartSpeed * webPartOldHeight);

        if(webPartHeight <= 0){
		initSpeed();
		webPartTarget.style.height = 0;
		webPartTarget.style.display = "none" ;
		clearInterval(webPartEventID);
		isShowZone = true;
	}
	else{		
		webPartTarget.style.height = webPartHeight;
		//webPartTarget.filters.alpha = ;
	}
}

function webPartShow(){
	//alert("webPartHeight : " + webPartHeight);
	//alert("webPartOldHeight : " + webPartOldHeight);
	for(var item =0; item<webPartItems.length; item++){
		if(webPartItems[item].id == webPartTarget.id){
			webPartOldHeight = webPartItems[item].height;
		}
	}

        webPartSpeedInit += webPartSpeedStep;
        webPartSpeed += webPartSpeedInit;
        webPartHeight += (webPartSpeed * webPartOldHeight);
	
        if(webPartHeight >= webPartOldHeight){
		initSpeed();
		webPartTarget.style.height = webPartOldHeight;
		webPartTarget.style.display = "" ;
		clearInterval(webPartEventID);
		isShowZone = false;

		for(var item =0; item<webPartItems.length; item++){
			if(webPartItems[item].id == webPartTarget.id){
				webPartItems.splice(item,1);
                        }
		}

	}else{
		webPartTarget.style.height = webPartHeight;
	}
}


function webPartZoneGroupEventHandler(selectedMenuIndex){
    var oWebPartZoneGroups = document.getElementsByTagName("div");
    for(var i=0;i<oWebPartZoneGroups.length;i++){
        if(oWebPartZoneGroups[i].className == "webpartzonegroup"){
            webPartZoneGroupBarsEventHandler(oWebPartZoneGroups[i],selectedMenuIndex);
        }
    }
}

function webPartZoneGroupBarsEventHandler(oWebPartZoneGroup,selectedMenuIndex){
    //默认活动项索引
    var defaultMenuIndex = selectedMenuIndex;
    if(oWebPartZoneGroup){
        var oGroups = oWebPartZoneGroup.childNodes;
        var oGroupBars = oGroups[0].childNodes[0];
        var oGroupContents = oGroups[1];
        var noneSelected = 1;

        //遍历菜单项集合，索引从1开始，跨过dt标签
        if(oGroupBars.childNodes.length >0){
            for(var i=1; i<oGroupBars.childNodes.length; i++){

                //记录当前索引
                oGroupBars.childNodes[i].id = i;

                //为非活动项设置样式类和绑定MouseOver鼠标事件
                if(oGroupBars.childNodes[i].className != "actived_webpartzone"){
		    noneSelected ++;
                    oGroupBars.childNodes[i].className = "default_webpartzone";                    
                    oGroupBars.childNodes[i].onmouseover = function() {
                        //激活菜单项
                        this.className = "actived_webpartzone";
                        this.style.cursor = "hand";
                        //this.style.paddingBottom = 4;

                        //遍历菜单项，为非当前项设置样式类，使其未激活
                        for(var j=1; j<oGroupBars.childNodes.length; j++){
                            if( j != event.srcElement.id){
                                oGroupBars.childNodes[j].className = "default_webpartzone";
                                //oGroupBars.childNodes[j].style.paddingBottom = 3;
                            }
                        }

                        //设置当前要显示的内容
                        webPartZoneGroupContentsEventHandler(oGroupContents, event.srcElement.id);
	            }
                    
                    //鼠标离开激活对象                     
                    oGroupBars.childNodes[i].onmouseout = function(){                       
                        //this.className = "default_webpartzone";
                        this.style.cursor = "";                        
                    }
	        }
            }

            //设置默认活动项
            if(defaultMenuIndex <= oGroupBars.childNodes.length - 1){
	        if(noneSelected != oGroupBars.childNodes.length - 1){
                    oGroupBars.childNodes[defaultMenuIndex].className = "actived_webpartzone";
                    //oGroupBars.childNodes[defaultMenuIndex].style.paddingBottom = 5;	    
                    //oGroupBars.childNodes[defaultMenuIndex].onmouseover = oGroupBars.childNodes[defaultMenuIndex].onmouseout = null; 
                }
            }
        }

        //设置默认显示内容
        if(oGroupContents.childNodes.length >0){
            for(var k=0; k<oGroupContents.childNodes.length; k++){
                if(k == defaultMenuIndex - 1){
                    oGroupContents.childNodes[k].style.display = "";
                }
            }
        }
    }
}

function webPartZoneGroupContentsEventHandler(oGroupContents, menuIndex){
    var defaultContent = "没有相关数据...";
    if(menuIndex > oGroupContents.childNodes.length){
        var oTemp = document.createElement("div");
        oTemp.innerHTML = defaultContent;
        oTemp.className = "html_skin";
        oGroupContents.appendChild(oTemp);
        //oGroupContents.insertBefore(oTemp,oGroupContents.childNodes[menuIndex-2]);
    }

    for(var i=0; i<oGroupContents.childNodes.length; i++){
        if( i == menuIndex - 1 ){
            if(oGroupContents.childNodes[i].innerHTML.length <= 0){
                oGroupContents.childNodes[i].innerHTML = defaultContent;
            }
            oGroupContents.childNodes[i].style.display = '';
        }else{
            oGroupContents.childNodes[i].style.display = 'none';
        }
    }
    
}


