var current_index_main_img = 0;
var do_rotate_index_main_img = 1;

window.onload = set_index_img_rotate;

function set_index_img_rotate()
{
	document.getElementById("index_main_img").onmousemove = function()
	{
	  do_rotate_index_main_img = 0;
	}
	
	document.getElementById("index_main_img").onmouseout = function()
	{
	  do_rotate_index_main_img = 1;
	}
	
	set_thumb_index();
	set_index_main_img(0);
	
	setInterval(rotate_index_main_img,3000);
	setTimeout(preload_main_img, 1000);	

   
   	scroll_id = document.getElementById("scrollnews");
	//init_scroll_news();

}


function preload_main_img()
{
   
    for(var i = 1;i<index_main_img_list.length;i++)
    {
      var index_main_images_pre = new Array();
      
      index_main_images_pre[i-1] = new Image();
      index_main_images_pre[i-1].src = index_main_img_list[i];
      
    }
    
}


function set_thumb_index()
{
  var new_thumb_index;
  var the_ul_node = document.getElementById("index_main_img").getElementsByTagName("UL")[0];
  
  while(the_ul_node.lastChild != undefined && the_ul_node.lastChild.nodeType == 1)
  {
   the_ul_node.removeChild(the_ul_node.lastChild);
  }
  
  for(var i = 0;i<index_main_img_list.length;i++)
  {
    new_thumb_index = document.createElement("LI");
    new_thumb_index.innerHTML = i+1;
    
    new_thumb_index.style.cursor = "pointer";
    
    new_thumb_index.onmousemove = new_thumb_index.onclick = function()
    {
         set_index_main_img(this.innerHTML-1);
    }
    
    document.getElementById("index_main_img").getElementsByTagName("UL")[0].appendChild(new_thumb_index);
  }

}


function rotate_index_main_img()
{
  if(do_rotate_index_main_img == 0) return;
  
  if(current_index_main_img >= index_main_img_list.length) current_index_main_img = 0;
  
  set_index_main_img(current_index_main_img);
  
  current_index_main_img ++;
}

function set_index_main_img(new_img_num)
{
  current_index_main_img = new_img_num;
  
  document.getElementById("index_main_img").getElementsByTagName("IMG")[0].src=index_main_img_list[current_index_main_img]; 
  document.getElementById("index_main_img").getElementsByTagName("A")[0].href=index_main_img_link[current_index_main_img]; 
  document.getElementById("index_main_img").getElementsByTagName("A")[0].target='_blank';
  
  for(var i = 0;i<index_main_img_list.length;i++)
  {
	if(i == current_index_main_img)
		document.getElementById("index_main_img").getElementsByTagName("UL")[0].getElementsByTagName("LI")[i].style.backgroundColor = "#F89A32";
	else
		document.getElementById("index_main_img").getElementsByTagName("UL")[0].getElementsByTagName("LI")[i].style.backgroundColor = "#D4D4D4";
  }
  
}