// east_bj_20101227.js


/**input_focus**/
jQuery.fn.selectCity = function(targetId) {
	var _seft = this;
	var targetId = $(targetId);
 
	this.click(function(){
		var A_top = $(this).offset().top + $(this).outerHeight(true);  //  1
		var A_left =  $(this).offset().left;
		targetId.bgiframe();
		targetId.slideDown().css({"position":"absolute","top":A_top+"px" ,"left":A_left+"px"});
	});
 
	targetId.find("#selectItemClose").click(function(){
		targetId.slideUp();
	});
 
	/*targetId.find("#selectSub :radio").click(function(){		
		targetId.find(":radio").attr("checked",false);
		$(this).attr("checked",true);	
		_seft.val( $(this).val() );
		targetId.slideUp();
	});*/
 
	$(document).click(function(event){
		if(event.target.id!=_seft.selector.substring(1)){
			targetId.slideUp();	
		}
	});
 
	targetId.click(function(e){
		e.stopPropagation(); //  2
	});
 
    return this;
}




$(function(){
		   
	//课程列表下拉
	$("#channel_system h1 a").addClass('hover_down');
	
	//滚动新闻
	setInterval('AutoScroll("#scroll_news")',3000);
		   
	//slide
	$("#slideshow").slideshow({
		pauseSeconds: 4,
		width: 470,
		height: 257,
		caption: false
	});
	
	//idTabs
	$(".tab_ul li:first").addClass("selected"); //为第一个SPAN添加当前效果样式 
	$(".tab div:not(:first)").hide(); //隐藏其它的UL 
	$(".tab_ul li a").mouseover(function() { 
		$(".tab_ul li a").removeClass("selected"); //去掉所有SPAN的样式 
		$(this).addClass("selected"); 
		$(".tab div").hide(); 
		$($(this).attr("tab")).show(); 
	});
	
	
	//搜索框
	$("#key").selectCity("#search_form");

	//课程体系下拉
	$("#course_system li").hover(function(){
		$(this).find("ul.hide").stop(false,true).show();
	},function(){
		$(this).find("ul.hide").stop(false,true).hide();	
	})
	
	
	//展开课程体系
	var t1 , t2;
	$("#channel_system").mouseenter(function(){
		clearTimeout(t2);
		t1 = setTimeout("$('.channel_system_box').stop(false,true).slideDown()" , 200);
	})
	$("#channel_system").mouseleave(function(){
		clearTimeout(t1);
		t2 = setTimeout("$('.channel_system_box').stop(false,true).slideUp()" , 200);
	})
	
	


	//查看厂商更多详情
	$(".con_more").toggle(function(){
		$(this).next(".con_more_form").stop(false,true).slideDown();					   
	},function(){
		$(this).next(".con_more_form").stop(false,true).slideUp();					   
	})


	//频道顶部滚动banner特效
	$("#slider").easySlider({
		controlsBefore:	'<p id="controls">',
		controlsAfter:	'</p>',
		auto: true, 
		continuous: true
	});


	//开课计划，多行展示
	$("#course_list ul").hover(
		function(){
			var lee = $(this).children().size();
			$(this).css({"height":lee*25,"border":"1px solid #0061a7","background-color":"#FFFFFF","z-index":"2000"});
		},function(){
			$(this).css({"height":"23px","border":"0","background-color":"#FFFFFF","color":"#666666","z-index":"2"});
		}
	);
	
	$("#course_list ul li").hover(
		function(){
			$(this).css({"background-color":"#0061a7","color":"#FFFFFF"});							   
		},function(){
			$(this).css({"background-color":"#FFFFFF","color":"#0061a7"});
		}
	)
	
	
	//微软展开下级课程
	$(".cs_list li").toggle(
		function(){
			$(this).find("dl").show();
		},function(){
			$(this).find("dl").hide();								
		}
	)


	//首页消除链接
	$("#slideshow a[href='###']").addClass("no_link");

});



/***************/
/***************/
/***************/

//滚动新闻
function AutoScroll(obj){
	$(obj).find("ul:first").animate({
		marginTop:"-25px"
    },500,function(){
       	$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
    });
}


//根据所在页面ID展开对应课程
function showCourseList(c_id){
	$("#"+c_id).find("ul.hide").css("color","red").show();	
}



function accordion(cz){
    this.prototype=create();
    function create(){
        $('.mic_Accordio dd').hide();
        $('.mic_Accordio dt').click(function(){
            var content = $(this).next();
            var others = content.parent().find("dd:visible");
            if (others.length&&others.html()!=content.html()){
                others.slideUp('fast', function() {
                    content.slideToggle('fast');
                });
            }else{content.slideToggle('fast');}
        });
    }
}





/*
*   speed //元素移动速度
*   xPos  //元素一开始左距离
*   yPos  //元素一开始上距离
*   $('#div1').imgFloat({speed:30,xPos:10,yPos:10});  
*   $('#div2').imgFloat();   //不给参数默认（speed:10,xPos:0,yPos:0）                      
*/

(function($) {
    jQuery.fn.imgFloat = function(options) {
        var own = this;
        var xD = 0;
        var yD = 0;
        var i = 1;
        var settings = {
            speed: 10,
            xPos: 0,
            yPos: 0
        };
        jQuery.extend(settings, options);
        var ownTop = settings.xPos;
        var ownLeft = settings.yPos;
        own.css({
            position: "absolute",
            cursor: "pointer"
        });
        function imgPosition() {
            var winWidth = $(window).width() - own.width();
            var winHeight = $(window).height() - own.height();
            if (xD == 0) {
                ownLeft += i;
                own.css({
                    left: ownLeft
                });
                if (ownLeft >= winWidth) {
                    ownLeft = winWidth;
                    xD = 1;
                }
            }
            if (xD == 1) {
                ownLeft -= i;
                own.css({
                    left: ownLeft
                });
                if (ownLeft <= 0) xD = 0;
            }
            if (yD == 0) {
                ownTop += i;
                own.css({
                    top: ownTop
                });
                if (ownTop >= winHeight) {
                    ownTop = winHeight;
                    yD = 1;
                }
            }
            if (yD == 1) {
                ownTop -= i;
                own.css({
                    top: ownTop
                });
                if (ownTop <= 0) yD = 0;
            }
        }
        var imgHover = setInterval(imgPosition, settings.speed);
        own.hover(function() {
            clearInterval(imgHover);
        },
        function() {
            imgHover = setInterval(imgPosition, settings.speed);
        });
    }
})(jQuery);





/*任意位置浮动固定层*/
/*没剑(http://regedit.cnblogs.com) 2009-03-04*/
/*说明：可以让指定的层浮动到网页上的任何位置，当滚动条滚动时它会保持在当前位置不变，不会产生闪动*/
/*2009-06-10修改：重新修改插件实现固定浮动层的方式，使用一个大固定层来定位
/*2009-07-16修改：修正IE6下无法固定在top上的问题
/*09-11-5修改：当自定义层的绝对位置时，加上top为空值时的判断
这次的方法偷自天涯新版页
经多次测试，基本上没bug~
有问题的朋友欢迎到偶的博客http://regedit.cnblogs.com上提出
*/
/*调用：
1 无参数调用：默认浮动在右下角
$("#id").floatdiv();

2 内置固定位置浮动
//右下角
$("#id").floatdiv("rightbottom");
//左下角
$("#id").floatdiv("leftbottom");
//右下角
$("#id").floatdiv("rightbottom");
//左上角
$("#id").floatdiv("lefttop");
//右上角
$("#id").floatdiv("righttop");
//居中
$("#id").floatdiv("middle");

另外新添加了四个新的固定位置方法

middletop（居中置顶）、middlebottom（居中置低）、leftmiddle、rightmiddle

3 自定义位置浮动
$("#id").floatdiv({left:"10px",top:"10px"});
以上参数，设置浮动层在left 10个像素,top 10个像素的位置
*/
jQuery.fn.floatdiv=function(location){
		//判断浏览器版本
	var isIE6=false;
	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
	if(Sys.ie && Sys.ie=="6.0"){
		isIE6=true;
	}
	var windowWidth,windowHeight;//窗口的高和宽
	//取得窗口的高和宽
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	return this.each(function(){
		var loc;//层的绝对定位位置
		var wrap=$("<div></div>");
		var top=-1;
		if(location==undefined || location.constructor == String){
			switch(location){
				case("rightbottom")://右下角
					loc={right:"0px",bottom:"0px"};
					break;
				case("leftbottom")://左下角
					loc={left:"0px",bottom:"0px"};
					break;	
				case("lefttop")://左上角
					loc={left:"0px",top:"0px"};
					top=0;
					break;
				case("righttop")://右上角
					loc={right:"0px",top:"0px"};
					top=0;
					break;
				case("middletop")://居中置顶
					loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};
					top=0;
					break;
				case("middlebottom")://居中置低
					loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"};
					break;
				case("leftmiddle")://左边居中
					loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("rightmiddle")://右边居中
					loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("middle")://居中
					var l=0;//居左
					var t=0;//居上
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					top=t;
					loc={left:l+"px",top:t+"px"};
					break;
				default://默认为右下角
					location="rightbottom";
					loc={right:"0px",bottom:"0px"};
					break;
			}
		}else{
			loc=location;
			//alert(loc.bottom);
			var str=loc.top;
			//09-11-5修改：加上top为空值时的判断
			if (typeof(str)!= 'undefined'){
				str=str.replace("px","");
				top=str;
			}
		}
		/*fied ie6 css hack*/
		if(isIE6){
			if (top>=0)
			{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
			}else{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
			}
		}
		$("body").append(wrap);
		
		wrap.css(loc).css({position:"fixed",
			z_index:"999"});
		if (isIE6)
		{
			
			wrap.css("position","absolute");
			//没有加这个的话，ie6使用表达式时就会发现跳动现象
			//至于为什么要加这个，还有为什么要加nothing.txt这个，偶也不知道，希望知道的同学可以告诉我
			$("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");
		}
		//将要固定的层添加到固定层里
		$(this).appendTo(wrap);
	});
};


