﻿/*
date:2011.6
*/

//menu
var menu = {
	init:function(){
		var self = this;
		var m = $("#two_nav");
		this.a = m.find("a");
		this.a.bind("mouseover",function(){
			self.setBg($(this).attr("l"),$(this).attr("w"));				 
		});
		m.bind("mouseleave",function(){
			self.outBg();				 
		});
	},
	setBg:function(l,w){
		var w = w || 115;
		var l = l || -500;
		$("#br_nav .bg").stop();
		$("#br_nav .bg").animate({left:l,width:w},250);
	},
	outBg:function(){
		$("#br_nav .bg").animate({left:-500,width:115},250);
	}
};


//自定义滚动条
function ScrollFn(o,c,t,f){
    //o:盒子对象,h:内容高度
    this.o = o;
    this.c = c;
    this.t = t;
    this.me = $("#"+this.o);
	if(f){
		this.f = true;
	};
	if(this.f){
		this.li = this.me.find("li");
		this.li_w = this.li.outerWidth(true);
		this.h = this.me.outerWidth(true);    
	}else{
		this.h = this.me.outerHeight(true);
		
	};
	
    this.html = this.me.html();
    this.createScroll();
}
ScrollFn.prototype.createScroll = function(){
    var self = this;        
    this.scrollCon = $("#"+this.c);//内容div
    this.scrollTool = $("#"+this.t);//滚动条div
	
	if(this.f){
		this.scrollCon.width(this.li_w*this.li.length);
		this.scrollCon_h = this.scrollCon.outerWidth(true)-this.h;    //内容高度		
	}else{
		this.scrollCon_h = this.scrollCon.outerHeight(true)-this.h;    //内容高度	
		
	};
    
    if(this.scrollCon_h <= 0)return false;//如果内容没有超高则退出下面的操作;
	if(this.f){
		 this.scrollTool_h = this.scrollTool.outerWidth(true);//滚动条高度
	}else{
		 this.scrollTool_h = this.scrollTool.outerHeight(true);//滚动条高度
	};
     this.scroll_y = this.h - this.scrollTool_h;//滚动范围
     this.move_y = this.scrollCon_h/this.scroll_y;
    this.scrollTool.bind("mousedown",function(e){self.mouseDownFn(e);});
    document.documentElement.onmouseup = function(){
        document.documentElement.onmousemove = null;
        self.scrollTool.unbind("mouseup");    
    }
};
ScrollFn.prototype.mouseDownFn = function(e){
    var self = this;
    var e = e || event;
	if(this.f){
		 this.scrollTool_t = e.clientX - parseInt(this.scrollTool.css("left"));	
	}else{
		 this.scrollTool_t = e.clientY - parseInt(this.scrollTool.css("top"));	
	};
    document.documentElement.onmousemove = move;
    function move(e){
        var e = e || event;
		if(self.f){
			   var t = e.clientX - self.scrollTool_t;
			}else{
			   var t = e.clientY - self.scrollTool_t;
		};
        if(t<0) t = 0;
        if(t>self.scroll_y) t = self.scroll_y;
		if(self.f){
			   self.scrollTool.css({"left":t});
     		   self.scrollCon.css({"left":-t * self.move_y});
			}else{
			   self.scrollTool.css({"top":t});
       		  self.scrollCon.css({"top":-t * self.move_y});
		};
    }
};

// 打开层
 function openLayer(o,w,h){
	 var w = w || 500;
	 var h = h || 300;
	 $.openLayer({
		width:w+"px",
		height:h+"px",
		target:o, //对象
		type:'_id' //选择类型，如果是外部加载则类型为 ajax
	});
  };
//关闭层
function closeLayer(){
	$.closeLayer();	
};

//新闻
//function openNews (){
//	openLayer('openNews',584,294);
//	var myScroll = new ScrollFn('scrollBox','scrollCon','scrollTool');//自定义滚动条
//}

function openNews (m,o){
	openLayer('openNews'+o,834,522);
	$(".newsList").hide();
	$("#openNews .title h3").html($(m).attr("title"));
	$("#openNews .title span").html($(m).attr("time"));
	
	var myScroll = new ScrollFn('scrollBox','scrollCon','scrollTool');//自定义滚动条
}


//主导航
var nav = {
	init:function(o){
		var li = $(o).find("li");	
		li.hover(function(){
					$(this).find(".cur").animate({top:0},200);
				},function(){
					$(this).find(".cur").animate({top:-33},200);
			});
	}	
};

//首页banner
var index_banner  =  {
	init:function(s,o){
		var self = this;
		this.s = $(s);
		this.o = $(o);
		this.sli = this.s.find("li");
		this.sli.hover(function(){
						$(this).addClass("cur");			
					},function(){
						$(this).removeClass("cur");			
					});
		/*for(var i = 0;i<this.sli.length;i++){
				this.sli.eq(i).attr("num",i);
			var li = document.createElement("li");	
				li.style.backgroundImage = "url("+this.sli.eq(i).attr("bSrc")+")";
				if(i==0){
					//this.sli.eq(i).addClass("cur");
					//li.style.display = "block";
				}else{
					li.style.display = "none";
				};
				self.o.append(li);
		};*/
	}	
}

//地产
var dc = {
	init:function(o){
		this.li = $(o).find(".m");	
		this.li.find(".sub").find("li").hover(function(){
					$(this).addClass("cur");						   
				},function(){
					$(this).removeClass("cur");
			});
		this.li.hover(function(){
				$(this).addClass("cur");
			},function(){
				$(this).removeClass("cur");
		});
	}	
};

//tab
function tabShow(m,c,id,l){
	for(var i = 1;i<=l;i++){
		$("#"+m+i).removeClass("cur");	
		$("#"+c+i).hide();
	};
	$("#"+m+id).addClass("cur");	
	$("#"+c+id).show();
	if(id==0){
		var myScroll = new ScrollFn('scrollBox','scrollCon','scrollTool');//自定义滚动条
		var myScroll2 = new ScrollFn('scrollBox2','scrollCon2','scrollTool2',1);//自定义滚动条
	}else{
		var myScroll3 = new ScrollFn('scrollBox3','scrollCon3','scrollTool3');//自定义滚动条	
	}
}


























