﻿// JavaScript Document

$(function(){
	var tabs=new Array();
	$("[type=nstabs]").each(function(){
		var group=$(this).attr("group");
		if(!tabs.exists(group)){
			initTabs(group);
			tabs.push(group);
		}
	});
	var s=document.getElementById('bigImg');
	if(s){
		setInterval("ImageLocker(500,600,'bigImg')",100);
	}
	var html=$("#popupad").html();
	$("#popupad").html('');
	$("#popupad").html(html);
	$("#popupad").slideDown("slow");
	
	// init();
});
function initTabs(group){
	if(!group)return;
	var tabs=$("[group="+group+"]");
	if(tabs.length<1) return;
	var activeTab=$(tabs).filter("[ifocus=yes]")[0] ||tabs[0];
	$(tabs).bind("mouseover",function(){showTabs(this);})
	showTabs(activeTab)
}
function showTabs(obj){
	var group=$(obj).attr("group") || null;
	if(!group)return;
	$("[group="+group+"]").attr("ifocus","no").removeClass("focus").each(function(){
		$("#"+$(this).attr("pannel")).hide();
	});
	
	$(obj).attr("ifocus","yes");
	$(obj).addClass("focus");
	$("#"+$(obj).attr("pannel")).show();
}
Array.prototype.exists=function(k){for(var i=0;i<this.length;i++){if(this[i]==k)return true;}	return false;}

function ImageLocker(w,h,s){
	var p=new Image();
	p.src=document.getElementById(s).src;
	if(w==0 && h==0)return;
	if(p.width>0 && p.height>0){
		var r=(w/p.width < h/p.height)?w/p.width:h/p.height;
		if(w==0){ r=h/p.height;}
		if(h==0){r=w/p.width;}
		if(r <= 1){	
			document.getElementById(s).width = p.width*r;
			document.getElementById(s).height =p.height*r;
		}else{
			document.getElementById(s).width = p.width;
			document.getElementById(s).height =p.height;
		}
	}
}

function PopupAd(){
	$("#popupad").slideUp("slow"); 
}

function init(){
	
	var html="<div class='floatad' id='float_left'><a href='http://special.runhua.com.cn/'><img src='images/140x280.jpg'/></a><a href='#' class='floatclose'>关闭</a></div><div class='floatad' id='float_right'><a href='http://special.runhua.com.cn/'><img src='images/140x280.jpg'/></a><a href='#' class='floatclose'>关闭</a></div>";
	$(document.body).append(html);
	$(".floatad").css({width:'140px',height:'300px',overflow:'hidden',border:'1px solid #CCC',position:'absolute',top:'20px'});
	
	
	$(".floatad a.floatclose").css({ display:'block', 'text-align':'center', 'line-height':'20px', 'font-size':'12px', 'text-decoration':'none'}).click(function(){$(".floatad").hide();return false;});
	setInterval("setFloadAdPos()",100);
}
function setFloadAdPos(){
	var pos=$(".toplogin").position();
	$("#float_left").css({left:pos.left-150});
	$("#float_right").css({left:pos.left+965});
	$(".floatad").css("top",$(window).scrollTop()+10);
}