var arSlideImageUrl = new Array();
var arSlideTitle = new Array();
var arSlideLinkUrl = new Array();

var g_nSlideImageIndex = 0;
var g_nShowImageCount = 3;
var g_nSlideIntervalSecond = 4;
var auto_roll = 0;
var Stime;
var Stime2;

arSlideImageUrl.push('');
arSlideTitle.push('');
arSlideLinkUrl.push('');

function resize_img(obj,maxWidth,maxHeight)
{

    var imgWidth = obj.width;
    var imgHeight = obj.height;

    var widthDiffer = imgWidth - maxWidth;
    var heightDiffer = imgHeight - maxHeight;

    var diffPer = 0;

    if(widthDiffer > heightDiffer) diffPer = maxWidth / imgWidth;
    else diffPer = maxHeight / imgHeight;

    obj.width  = parseInt(imgWidth * diffPer);
    obj.height = parseInt(imgHeight * diffPer);
}


function ShowCutPhoto(nShowIndex, nSlideIndex)
{

	if(nShowIndex == arSlideImageUrl.length) nShowIndex = 1;
	if (nShowIndex >= arSlideImageUrl.length || arSlideImageUrl[nShowIndex] == '')
	{
		image_url = './images/main/x.gif';
		title = '';
		link_url = '';
	}
	else
	{
		image_url = document.getElementById('tmpimgAA'+nShowIndex).src
		image_w   = document.getElementById('tmpimgAA'+nShowIndex).width
		image_h   = document.getElementById('tmpimgAA'+nShowIndex).height

		title = arSlideTitle[nShowIndex];
		link_url = arSlideLinkUrl[nShowIndex];
	}

	document.getElementById('imageSlidePhoto'+nSlideIndex).src     = image_url;
	document.getElementById('imageSlidePhoto'+nSlideIndex).width   = image_w;
	document.getElementById('imageSlidePhoto'+nSlideIndex).height  = image_h;

	document.getElementById('linkSlidePhoto'+nSlideIndex).href     = link_url;
	document.getElementById('linkSlideText'+nSlideIndex).href      = link_url;
	document.getElementById('linkSlideText'+nSlideIndex).innerHTML = title;
}

function ShowSlidePhoto()
{
  var nShowIndex = g_nSlideImageIndex;
  
  for (i=1; i<=g_nShowImageCount; i++)
  {
	if(nShowIndex == arSlideImageUrl.length) nShowIndex = 1;
	nShowIndex = (nShowIndex+arSlideImageUrl.length)%arSlideImageUrl.length; 
  	++nShowIndex;
  	ShowCutPhoto(nShowIndex, i);
  }
}

function NextSlidePhoto(click)
{

  if(click == '1') StopSliding();
  if (g_nSlideImageIndex+g_nShowImageCount+1 >= (arSlideImageUrl.length+(g_nShowImageCount2-1)))
  {
    g_nSlideImageIndex = -1;
  }

  ++g_nSlideImageIndex;
  
  ShowSlidePhoto();
  if(click == '1') {
	  clearTimeout(Stime);
	  Stime = setTimeout("StartSliding();",3000);
  }
}

function PrevSlidePhoto(click)
{
  if(click == '1') StopSliding();

  if (g_nSlideImageIndex == 0){
    g_nSlideImageIndex = -1;
  }	

  --g_nSlideImageIndex;

  ShowSlidePhoto();

  if(click == '1'){
	  clearTimeout(Stime);
	  Stime = setTimeout("StartSliding()",3000);
  }
}
function StartSliding()
{
	auto_roll = setInterval('NextSlidePhoto()', g_nSlideIntervalSecond*1000);
}

function StopSliding(){
	clearInterval(auto_roll);
}


/*Issue!Item Rolling*/
var arSlideImageUrl2 = new Array();
var arSlideTitle2 = new Array();
var arSlideLinkUrl2 = new Array();

var g_nSlideImageIndex2 = 0;
var g_nShowImageCount2 = 4;
var g_nSlideIntervalSecond2 = 4;

arSlideImageUrl2.push('');
arSlideTitle2.push('');
arSlideLinkUrl2.push('');

function ShowCutPhoto2(nShowIndex, nSlideIndex)
{
	if(nShowIndex == arSlideImageUrl2.length) nShowIndex = 1;
	if (nShowIndex >= arSlideImageUrl2.length || arSlideImageUrl2[nShowIndex] == '')
	{
		image_url = './images/main/x.gif';
		title = '&nbsp;<br><font color="#086ADE" size="2px">&nbsp;</font>';
		link_url = '';
	}
	else
	{
		image_url = document.getElementById('tmpimgBB'+nShowIndex).src
		image_w   = document.getElementById('tmpimgBB'+nShowIndex).width
		image_h   = document.getElementById('tmpimgBB'+nShowIndex).height

		title = arSlideTitle2[nShowIndex];
		link_url = arSlideLinkUrl2[nShowIndex];
	}

	document.getElementById('imageSlidePhoto2'+nSlideIndex).src     = image_url;
	document.getElementById('imageSlidePhoto2'+nSlideIndex).width   = image_w;
	document.getElementById('imageSlidePhoto2'+nSlideIndex).height  = image_h;

	document.getElementById('linkSlidePhoto2'+nSlideIndex).href = link_url;
	document.getElementById('linkSlideText2'+nSlideIndex).href = link_url;
	document.getElementById('linkSlideText2'+nSlideIndex).innerHTML = title;
}

function ShowSlidePhoto2()
{
  var nShowIndex = g_nSlideImageIndex2;
   
  for (i=1; i<=g_nShowImageCount2; i++)
  {
	if(nShowIndex == arSlideImageUrl2.length) nShowIndex = 1;
	nShowIndex = (nShowIndex+arSlideImageUrl2.length)%arSlideImageUrl2.length; 
	++nShowIndex;
	ShowCutPhoto2(nShowIndex, i);
  }
}
function NextSlidePhoto2(click)
{
  if(click == '1') StopSliding2();
  if (g_nSlideImageIndex2+g_nShowImageCount2+1 >= (arSlideImageUrl2.length+(g_nShowImageCount2-1)))
  {
    g_nSlideImageIndex2 = -1;
  }

  ++g_nSlideImageIndex2;
  ShowSlidePhoto2();
  if(click == '1'){
	  clearTimeout(Stime2);
	  Stime2 = setTimeout("StartSliding2()",3000);
  }
}

function PrevSlidePhoto2(click)
{
  if(click == '1') StopSliding2();
  if (g_nSlideImageIndex2 == 0){
	g_nSlideImageIndex2 = -1;
  }

  --g_nSlideImageIndex2;

  ShowSlidePhoto2();
  if(click == '1'){
	  clearTimeout(Stime2);
	  Stime2 = setTimeout("StartSliding2()",3000);
  }
}
function StartSliding2()
{
	auto_roll2 = setInterval('NextSlidePhoto2()', g_nSlideIntervalSecond2*1000);
}

function StopSliding2(){
	clearInterval(auto_roll2);
}

function plusComma(num){ 
	if (!num)
	{
		return '';
	}
	if (num < 0) { num *= -1; var minus = true}
	else var minus = false

	var dotPos = (num+"").split(".")
	var dotU = dotPos[0]
	var dotD = dotPos[1]
	var commaFlag = dotU.length%3

	if(commaFlag) {
	var out = dotU.substring(0, commaFlag) 
	if (dotU.length > 3) out += ","
	}
	else var out = ""

	for (var i=commaFlag; i < dotU.length; i+=3) {
	out += dotU.substring(i, i+3) 
	if( i < dotU.length-3) out += ","
	}

	if(minus) out = "-" + out
	if(dotD) return out + "." + dotD
	else return out 
}


function jsonload(){ 
	ShowSlidePhoto();
	StartSliding();
	ShowSlidePhoto2();
	StartSliding2();
}