var referUrl = '';


/*****************************************************
 *   以下是原 function.marquee.js 当中的内容.   *   
 *****************************************************/

   var marqueeInterval=new Array();  
   var marqueeId=0;
   var marqueeDelay=6000;
   var marqueeHeight=30;


//接下來的是定義一些要使用到的函數
Array.prototype.random = function(){
  var a = this;
  var l = a.length;
  for(var i = 0; i < l; i++){
    var r = Math.floor(Math.random() * (l - i));
    a = a.slice(0, r).concat(a.slice(r + 1)).concat(a[r]);
  }
  return a;
}

function initMarquee(){
  var str = '';
  str = makeMarqueeContent(0);
  $('#mymarqueebox').html('<div id="marqueeBox" style="overflow:hidden;height:' + marqueeHeight + 'px"><div align="left">' + str + '</div></div>');
  marqueeId += 1;
  if(marqueeContent.length > 2){
    marqueeInterval[0] = setTimeout(function(){startMarquee();}, marqueeDelay);
  }
}

function startMarquee(){
  var str = '';
  str = makeMarqueeContent(marqueeId);
  marqueeId += 1;
  if(marqueeId >= Math.floor(marqueeContent.length / 2)){
    marqueeId = 0;
  }
  if(document.getElementById('marqueeBox').childNodes.length == 1){
    var nextLine = document.createElement('div');
    nextLine.innerHTML = str;
    document.getElementById('marqueeBox').appendChild(nextLine);
  } else {
    document.getElementById('marqueeBox').childNodes[0].innerHTML = document.getElementById('marqueeBox').childNodes[1].innerHTML;
    document.getElementById('marqueeBox').childNodes[1].innerHTML = str;
    //document.getElementById('marqueeBox').appendChild(document.getElementById('marqueeBox').childNodes[0]);
    document.getElementById('marqueeBox').scrollTop = 0;
  }
  clearInterval(marqueeInterval[1]);
  marqueeInterval[1]=setInterval(function(){scrollMarquee();}, 30);
}

function scrollMarquee(){
  document.getElementById('marqueeBox').scrollTop++;
  if(document.getElementById('marqueeBox').scrollTop%marqueeHeight == (marqueeHeight-1)){
    clearInterval(marqueeInterval[1]);
    marqueeInterval[0] = setTimeout(function(){startMarquee();}, marqueeDelay);
  }
}

function makeMarqueeContent(mid){
  return '<span class="W" style="word-break : keep-all; white-space:nowrap;" onmouseover="javascript:clearTimeout(marqueeInterval[0]);" onmouseout="javascript:marqueeInterval[0] = setTimeout(function(){startMarquee();}, marqueeDelay);"><a onclick="clickURL(this)"  href="' + marqueeContent[mid * 2].link + '" class=menu>' + marqueeContent[mid * 2].text + '</a></span><span style="color: #000000;">、</span><span style="word-break : keep-all; white-space:nowrap;" class="W" onmouseover="javascript:clearTimeout(marqueeInterval[0]);" onmouseout="javascript:marqueeInterval[0] = setTimeout(function(){startMarquee();}, marqueeDelay);"><a  onclick="clickURL(this)" href="' + marqueeContent[mid * 2 + 1].link + '" class=menu>' + marqueeContent[mid * 2 + 1].text + '</a></span>';
}

function clickURL(othis){
	 var _href = othis.href;
   if (/^http:\/\/refer\.click108\.com\.tw/.test(_href)){
     _href = '/clickCount.php?clickHref=' + encodeURIComponent(_href);
     othis.href = _href;
   }	 
}

/*****************************************************
 *   以下是原 function.general.js 当中的内容.   *   
 *****************************************************/

function gotoSelectedItem(){
  window.location.href = $('#itemSelector').val();
}

function setGoOtherDayOnSubmit(){
  if($('#goOtherDay').length > 0){
    $('#goOtherDay').get(0).onsubmit = function(){
      var dateSel = $('#_select_iAcDay').val();
      dateSel = dateSel.replace(/\//g, '');
      iAstro = document.getElementsByName('iAstro')[0].value;
      this.action = 'daily_' + iAstro + '_' + dateSel + '.php#main';
      return true;
    }
  }
}

function getos(){ 
   var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { return "MSIE"; } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ return "Firefox"; } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { return "Safari"; } 
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ return "Camino"; } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko")>0){ return "Gecko"; }   
} 

function DreamLoadto(select){// 
	var currSel=select.selectedIndex;
	if(currSel<0)
	return;
	var code =select.options[currSel].value;
	parent.location.href = "dream01.php?word_type=" + code + "#main";
	select.selectedIndex=0;
}

function MM_swapImgRestore(){
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages(){
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d){
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function referUrlClickCount(_Url){
	 ///alert(
	 $.ajax({
	 	     "type"   : "GET",
	 	     "url"    : "/clickCount.php",
	 	     "data"   : "isAjax=1&clickHref=" + encodeURIComponent(_Url), 
	 	     "async"  : false ,
	 	     "success": function(){}
	 });
	 ///.responseText);
	 return true;    	
}

/*****************************************************
 *  
 *****************************************************/

function getCookieByName(objName){
	var _cookies = document.cookie.split("; ");   
	for(var i = 0;i < _cookies.length;i ++){    
		var temp = _cookies[i].split("=");    
		if(temp[0] == objName) return unescape(temp[1]);   
	}
}

function addEvent(obj ,_type ,_fn){ if(obj.addEventListener){ obj.addEventListener(_type,_fn,false);}else if(obj.attachEvent){  obj.attachEvent("on"+_type,_fn); } }
function $id(s){ if(document.getElementById){return eval('document.getElementById("' + s + '")');} else{return eval('document.all.' + s);}} 


var refererHost     = 'fate.click108.com.tw';
var FRIST_HTTP_HOST = getCookieByName('FRIST_HTTP_HOST');

$.each(['www.click108.com','www.click108.com.tw','kids.click108.com.tw','hr.click108.com.tw','astro.click108.com.tw'],function(i,n){
	 (FRIST_HTTP_HOST == n) && (refererHost = 'www.click108.com.tw');
});