﻿var $ = function(v){return document.getElementById(v);}
//图片滚动开始
var stopscroll = false;
var scrollupflag=true;
var scrollElem;
var leftElem;
var currentTop = 0; 
var preTop;
var scrollspeed=30;//滚动速度
var isIE=document.all? true:false;

 var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        if (window.ActiveXObject)
             Sys.ie = /msie ([\d.]+)/.test(ua);
        else if (document.getBoxObjectFor)
             Sys.firefox = /firefox\/([\d.]+)/.test(ua);
        else if (window.MessageEvent && !document.getBoxObjectFor)
             Sys.chrome = /chrome\/([\d.]+)/.test(ua);
        else if (window.opera)
             Sys.opera = /opera.([\d.]+)/.test(ua);
        else if (window.openDatabase)
             Sys.safari = /version\/([\d.]+)/.test(ua);
        


function init_srolltext(){
    scrollElem=document.getElementById("andyscroll");
    if( scrollElem!=null)
    {
        scrollElem.onmouseover = new Function('stopscroll = true');
        scrollElem.onmouseout  = new Function('stopscroll = false');
        scrollElem.scrollLeft = 0;
        leftElem = document.getElementById("scrollmessage");
        
        if(scrollElem.clientWidth>scrollElem.clientHeight){                
            preTop =document.getElementById("sdf").offsetWidth-scrollElem.clientWidth+10;
            setInterval('scrollleft()',scrollspeed);
        }else{
            preTop =leftElem.offsetHeight-scrollElem.clientHeight+10;
            setInterval('scrollUp()',scrollspeed);
        }
    }         
}
function scrollUp(){
    if(stopscroll) return;             
    if(scrollupflag){
        currentTop += 1;　　                     
        if(currentTop> preTop)
            scrollupflag=false;　　                     
        scrollElem.scrollTop =currentTop;
    }else{
        currentTop -= 1;
        if(currentTop<0)
            scrollupflag=true;　　                     
        scrollElem.scrollTop=currentTop;
    }
}         
function scrollleft(){
    if(stopscroll) return;             
    if(scrollupflag){
        currentTop += 1;　　                     
        if(currentTop> preTop)
            scrollupflag=false;　　                     
        scrollElem.scrollLeft =currentTop;
    }else{
        currentTop -= 1;
        if(currentTop<0)
            scrollupflag=true;　　                     
        scrollElem.scrollLeft=currentTop;
    }
}//图片滚动结束


//显示菜单图片简介
function menuover(event,imgurl,content){
    var ei=document.getElementById("menuimgdiv");
    if(ei==null) ei=createDiv();
    event = event || window.event;
	if(imgurl.length==0&&content.length==0) return false;
    ei.style.display = "block";
	if(imgurl.length>0)
		ei.innerHTML = '<img src="' + imgurl + '" />';
	if(content.length>0)
		ei.innerHTML+='<h5>'+content+'</h5>';
	
	var ch;
	if(Sys.opera) ch=document.documentElement.clientHeight;
	else ch=document.body.clientHeight;

	if( ei.offsetHeight + document.documentElement.scrollTop + event.clientY + 10 >ch )
		ei.style.top=document.documentElement.scrollTop + event.clientY - ei.offsetHeight+ "px";
    else 
    	ei.style.top  = document.documentElement.scrollTop + event.clientY + 10 + "px";
    ei.style.left = document.documentElement.scrollLeft + event.clientX + 10 + "px";
}
function menuout(){
    var ei=document.getElementById("menuimgdiv");
    if(ei==null) 
    {    
    	return;
    }
    else
    {
    	ei.innerHTML = "";
    	ei.style.display = "none";
    }
}

/*定时跳转*/
function DelayJump(url,time){
	if(url.length>0&&time>0)
		setTimeout("location.href='"+url+"';",time);		
}

//调用函数开始=======================================================================================
if (document.all){
	window.attachEvent('onload',init);//IE中
}else{
	window.addEventListener('load',init,false);//firefox
}

function getPageScroll(){
			var yScroll;
			if (self.pageYOffset) {
			    yScroll = self.pageYOffset;
			}else if (document.documentElement && document.documentElement.scrollTop){
			    yScroll = document.documentElement.scrollTop;
		    }else if (document.body) {
		        yScroll = document.body.scrollTop;
		    }
			return yScroll;
}

function mymove()
{
    var a=getPageScroll()+window.screen.availHeight-document.getElementById("menuindex").clientHeight-150;
    document.getElementById("menuindex").style.top=a+'px';
    setTimeout("mymove();",100);
}

function changeView(status){
  if(status==true){
    var margintop=document.getElementById("menuindex").offsetTop;
    var width=500;
    if(isIE){
        width=document.getElementById("menuindex").offsetWidth;
    }
    else{
        width=document.getElementById("menuindex").clientWidth;
    }
    document.getElementById("menuindex").className='followindex clearfix';
    document.getElementById("menuindex").style.width=width+'px';
    mymove();
  }
  else{
    document.getElementById("menuindex").className='';
  }
}

function handoff(objname){
	var obj=document.getElementById(objname);
	if(obj.className=="title")
		obj.className="title_close";
	else
		obj.className="title";
}

function init(){
    init_srolltext();
    
    var musicLayer=document.getElementById("musicControl");     
    if(musicLayer!=null)
    {
        setInterval('document.getElementById("musicControl").style.bottom="0px";',300);
    }    
}

function createDiv(){
    ei = document.createElement( "div");
    ei.setAttribute( "id", "menuimgdiv");
    document.body.appendChild(ei);
    return ei;
}
function outPutMusic(musicPageUrl)
{
    var mdiv=document.createElement('div');
    mdiv.setAttribute('id','musicControl');
    mdiv.innerHTML='<input type="checkbox" id="musicCtrlBox" onclick="toggleMusic()" /><span id="musicCtrlStatus"></span>';
        
    if (document.all)
    {
	    window.attachEvent('onload',function(){_appendMusicRel(mdiv);});//IE中
    }
    else
    {
	    window.addEventListener('load',function(){_appendMusicRel(mdiv);},false);//firefox
    }
	
}
function _appendMusicRel(obj)
{
    document.body.appendChild(obj);
    
    document.getElementById('musicControl').className='musicctrldiv';
    if(isMusicEnable())
	{   
	    document.getElementById('musicCtrlStatus').innerHTML='Music On';
	    document.getElementById('musicCtrlBox').checked=true;
	    _appendMusicIframe();
	}
	else
	{
	    document.getElementById('musicCtrlBox').checked=false;
	    document.getElementById('musicCtrlStatus').innerHTML='Music Off';
	}
}
function _appendMusicIframe()
{
    var iframe=document.createElement('iframe');
            iframe.setAttribute('id','musicframe');
            iframe.setAttribute('scrolling','no');
            iframe.setAttribute('frameborder',0);
            iframe.setAttribute('allowTransparency','true');            
            iframe.setAttribute('marginheight',0);
            iframe.setAttribute('marginwidth',0);
            iframe.setAttribute('src',musicPageUrl);
            document.body.appendChild(iframe);
}
function isMusicEnable()
{
    var st=getCookie('musicdisable');
    return playmusic && (st==undefined || st!=1);
}
function toggleMusic()
{
    var cb=document.getElementById('musicCtrlBox');

    if(cb.checked)
    {
        enableMusic();
        var musicNode=document.getElementById('musicframe');
        if(musicNode==null || musicNode==undefined)
        {
            _appendMusicIframe();
        }
    }
    else
    {
        disableMusic();
    }
}
function enableMusic()
{
    addCookie('musicdisable','false');
    document.getElementById('musicCtrlStatus').innerHTML='Music On';
}
function disableMusic()
{
    addCookie('musicdisable',1);
    document.getElementById('musicCtrlStatus').innerHTML='Music Off';
    var musicNode=document.getElementById('musicframe');
    musicNode.parentNode.removeChild(musicNode); 
}
function addCookie(objName,objValue,objHours){//添加cookie
    var str = objName + "=" + escape(objValue);
    if(objHours > 0){//为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours*3600*1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    str+='; path=/';
    document.cookie = str;
}

function getCookie(objName){//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++){
        var temp = arrStr[i].split("=");
        if(temp[0] == objName) return unescape(temp[1]);
    }
}
//===================================================================================================

function GetUrlAct(){
	var url,actindex,actword,act;
	url=window.location.href;
	if(url.substring(url.length)=='/')
		url=url.substring(0,url.length-1);
	actindex=url.lastIndexOf('/')+1;
	actword=url.substring(actindex,url.length).toLowerCase();
	switch(actword){
		case 'menu':act=2;break;
		case 'environment':act=3;break;
		case 'map':act=4;break;
		case 'coupon':act=5;break;
		case 'contact':act=6;break;
		case 'culture':act=7;break;
		default:act=1;
	}
	return act;
}

//获取URL参数
function GetUrlParms(parms)    
{
    var args=new Object();   
    var query=location.search.substring(1);
    var pairs=query.split("&"); 
    for(var i=0;i<pairs.length;i++)   
    {   
        var pos=pairs[i].indexOf('=');   
        if(pos==-1)   continue;
		if(pairs[i].substring(0,pos)==parms)
			return unescape(pairs[i].substring(pos+1));
    }
    return args;
}

//控制图片大小  obj=对象,w=最大宽度
function thumbimg(obj,w){
        //eval('var obj=document.getElementById("'+objname+'");');
        if(obj.width>w)obj.width=w;
}

//判断是否选择Coupon
function check_couponform(){
	var theNum=0;
	for(var i=0;i<document.getElementsByName("coup[]").length;i++){
		if(document.getElementsByName("coup[]")[i].checked) theNum++; 
	}
	for(var i=0;i<document.getElementsByName("coup_t[]").length;i++){
		if(document.getElementsByName("coup_t[]")[i].checked) theNum++; 
	}
	for(var i=0;i<document.getElementsByName("coup_r[]").length;i++){
		if(document.getElementsByName("coup_r[]")[i].checked) theNum++; 
	}
	if(theNum==0){
		alert("Please choose coupon!");
		return false;
	}
}
//检查Contact表单
function check_add_contact(){
	firstname=document.contact.F_FirstName.value;
	lastname=document.contact.F_LastName.value;
	organname=document.contact.F_OrganizationName.value;
	address=document.contact.F_StreetAddress.value;
	city=document.contact.F_City.value;
	state=document.contact.F_State.value;
	zip=document.contact.F_ZipCode.value;
	phone=document.contact.F_Phone1.value;
	subject=document.contact.F_UserSubject.value;
	message=document.contact.F_TextField1.value;
    validate=document.contact.validate.value;
	if(firstname==""){
			alert("Please enter your First name!");
			document.contact.F_FirstName.focus();
			return false;
		}
	if(lastname==""){
			alert("Please enter your Last name!");
			document.contact.F_LastName.focus();
			return false;
		}
	if(organname==""){
			alert("Please enter your Organization name!");
			document.contact.F_OrganizationName.focus();
			return false;
		}
	if(address==""){
			alert("Please enter the Street address!");
			document.contact.F_StreetAddress.focus();
			return false;
		}
	if(city==""){
			alert("Please enter the Town/City!");
			document.contact.F_City.focus();
			return false;
		}
	if(state==""){
			alert("Please enter the State/Province!");
			document.contact.F_State.focus();
			return false;
		}
	if(zip==""){
			alert("Please enter the Postal/Zip code!");
			document.contact.F_ZipCode.focus();
			return false;
		}
	if(phone==""){
			var patrn=/^[0-9]{10}$/;
			if(!patrn.exec(phone)) {
			alert("Please enter the Work phone number!");
			document.contact.F_Phone1.focus();
			return false;
		}
	}
	if(subject==""){
			alert("Please enter the Subject!");
			document.contact.F_UserSubject.focus();
			return false;
		}		
	if(message==""){
			alert("Please enter the Message!");
			document.contact.F_TextField1.focus();
			return false;
		}		
	if(validate==""){
			alert("Please enter the correct confirmation code!");
			document.contact.validate.focus();
			return false;
		}	
	return true;

}

var $$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var CurrentStyle = function(element){
	return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

var Bind = function(object, fun) {
	var args = Array.prototype.slice.call(arguments).slice(2);
	return function() {
		return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
	}
}

var forEach = function(array, callback, thisObject){
	if(array.forEach){
		array.forEach(callback, thisObject);
	}else{
		for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); }
	}
}

var Tween = {
	Quart: {
		easeOut: function(t,b,c,d){
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		}
	},
	Back: {
		easeOut: function(t,b,c,d,s){
			if (s == undefined) s = 1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		}
	},
	Bounce: {
		easeOut: function(t,b,c,d){
			if ((t/=d) < (1/2.75)) {
				return c*(7.5625*t*t) + b;
			} else if (t < (2/2.75)) {
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			} else if (t < (2.5/2.75)) {
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			} else {
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		}
	}
}


//容器对象,滑动对象,切换数量
var SlideTrans = function(container, slider, count, options) {
	this._slider = $$(slider);
	this._container = $$(container);//容器对象
	this._timer = null;//定时器
	this._count = Math.abs(count);//切换数量
	this._target = 0;//目标值
	this._t = this._b = this._c = 0;//tween参数
	
	this.Index = 0;//当前索引
	
	this.SetOptions(options);
	
	this.Auto = !!this.options.Auto;
	this.Duration = Math.abs(this.options.Duration);
	this.Time = Math.abs(this.options.Time);
	this.Pause = Math.abs(this.options.Pause);
	this.Tween = this.options.Tween;
	this.onStart = this.options.onStart;
	this.onFinish = this.options.onFinish;
	
	var bVertical = !!this.options.Vertical;
	this._css = bVertical ? "top" : "left";//方向
	
	//样式设置
	var p = CurrentStyle(this._container).position;
	p == "relative" || p == "absolute" || (this._container.style.position = "relative");
	this._container.style.overflow = "hidden";
	this._slider.style.position = "absolute";
	
	this.Change = this.options.Change ? this.options.Change :
		this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;
};
SlideTrans.prototype = {
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Vertical:	true,//是否垂直方向（方向不能改）
		Auto:		true,//是否自动
		Change:		0,//改变量
		Duration:	30,//滑动持续时间
		Time:		10,//滑动延时
		Pause:		3000,//停顿时间(Auto为true时有效)
		onStart:	function(){},//开始转换时执行
		onFinish:	function(){},//完成转换时执行
		Tween:		Tween.Quart.easeOut//tween算子
	};
	Extend(this.options, options || {});
  },
  //开始切换
  Run: function(index) {
	//修正index
	index == undefined && (index = this.Index);
	index < 0 && (index = this._count - 1) || index >= this._count && (index = 0);
	//设置参数
	this._target = -Math.abs(this.Change) * (this.Index = index);
	this._t = 0;
	this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]);
	this._c = this._target - this._b;
	
	this.onStart();
	this.Move();
  },
  //移动
  Move: function() {
	clearTimeout(this._timer);
	//未到达目标继续移动否则进行下一次滑动
	if (this._c && this._t < this.Duration) {
		this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));
		this._timer = setTimeout(Bind(this, this.Move), this.Time);
	}else{
		this.MoveTo(this._target);
		this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause));
	}
  },
  //移动到
  MoveTo: function(i) {
	this._slider.style[this._css] = i + "px";
  },
  //下一个
  Next: function() {
	this.Run(++this.Index);
  },
  //上一个
  Previous: function() {
	this.Run(--this.Index);
  },
  //停止
  Stop: function() {
	clearTimeout(this._timer); this.MoveTo(this._target);
  }
};


