var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");        
var isIE=navigator.userAgent.indexOf("IE")>0;
var isIE5=navigator.userAgent.indexOf("IE 5.0")>0;
var isIE6=navigator.userAgent.indexOf("IE 6.0")>0;
var isNav=(navigator.appName.indexOf("Netscape")!=-1);
var element;
function $$(obj){
	return typeof(obj) == "string" ? document.getElementById(obj) : obj;
}
String.prototype.trim=function(){
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};
function hide(el) {
	element = $$(el);
	element.style.display = 'none';
}
function show(el) {
	element = $$(el);
	element.style.display = '';
}
function remove(el){
	element = $$(el);
	element.parentNode.removeChild(element);
}
function toggle(el) {
    el = $$(el);
	if(el.style.display=="none"){
		el.style.display='block';
	}else{
		el.style.display='none';
	}
}

/*==================================================*/

function scrollup(o,h,d){	
	timer_flg = false;
	if(d==h){
	   var t = o.firstChild;
	   o.appendChild(t);
	   t.style.marginTop=o.firstChild.style.marginTop='0px';
	   d=0;
	   timer_flg = true;
	}
	else{
	   var s=3,d=d+s,l=(d>=h?d-h:0);
	   o.firstChild.style.marginTop=-d+l+'px';
	   window.setTimeout(function(){scrollup(o,h,d-l)},20);
	}
}


function scrollup_online(o,h,d){
	online_timer_flg = false;
	if(d==h){
	   var t = o.firstChild;
	   o.appendChild(t);
	   t.style.marginTop=o.firstChild.style.marginTop='0px';
	   d=0;
	   online_timer_flg = true;
	}
	else{
	   var s=3,d=d+s,l=(d>=h?d-h:0);
	   o.firstChild.style.marginTop=-d+l+'px';
	   window.setTimeout(function(){scrollup_online(o,h,d-l)},20);
	}
}

///////////////
function addListener(element, type, expression, bubbling)
{
  bubbling = bubbling || false;
  if(window.addEventListener)	{ // Standard
    element.addEventListener(type, expression, bubbling);
    return true;
  } else if(window.attachEvent) { // IE
    element.attachEvent('on' + type, expression);
    return true;
  } else return false;
}

var ImageLoader = function(url){
  this.url = url;
  this.image = null;
  this.loadEvent = null;
};

ImageLoader.prototype = {
  load:function(){
    this.image = document.createElement('img');
    var url = this.url;
    var image = this.image;
    var loadEvent = this.loadEvent;
    addListener(this.image, 'load', function(e){
      if(loadEvent != null){
        loadEvent(url, image);
      }
    }, false);
    this.image.src = this.url;
  },
  getImage:function(){
    return this.image;
  }
};

function loadImage(objId,urls){
var loader = new ImageLoader(urls);
loader.loadEvent = function(url){
 obj = $$(objId);
 obj.src = url;
}
loader.load();
}

function rewrite_url(pname , pid){
	if(pid == null || pid == "undefined" ) {return ""};
	var re = /[^a-zA-Z0-9]/ig;
	var url = "";
	if(FRIENDLY_URLS != null && FRIENDLY_URLS == 'true'){
		url = baseURL + pname.replace(re,"-") + "_p" + pid + ".html";
	}
	else{
		url = linkURL+pid;
	}
	return url;
}
/////////////////
/*the li scroll*/
function page_go(id, num, c, t, cid){
	var Prev = id + "Prev";
	var Next = id + "Next";	
	var pageId = id + "Page";
	var Page = 0;
	var currentPage = 1;
	var PageNumber = Math.ceil(t/num);
	var activeClick = true;
	var gopage = 0;

	if(num>t){activeClick = false;}
	if(c >= num){
		if(t!=null){
			gopage = Math.ceil(c/num);
			if(c % num == 0) gopage++; 		
		}
		updateProduct('goto', gopage);
	}else{
		updateProduct('goto', 1);
	}
	
	function updateProduct(type, gopage) {
		if(type=='pre') {Page -= parseInt(num);currentPage--};
		if(type=='next') {Page += parseInt(num);currentPage++};
		if(type=='goto' && gopage != null) {Page = (gopage-1) * num ; currentPage = gopage;}
		if(Page<0) {
			Page=num*(PageNumber-1);
			currentPage=PageNumber;
		}
		if(Page>=t) {
			Page=0;
			currentPage=1;
		}
		
		$$(pageId).innerHTML = currentPage +'/'+PageNumber;
		
		for(i=0;i<num;i++){
			if(i >= productID.length){
				break;
			}
			n_page = i + Page;
			$$('cell_link'+i).href = productLink[n_page];
			
			$$('li'+i).style.display='block';
			if(productID[n_page] == null){
				$$('li'+i).style.display='none';
				continue;
			}
			
			$$('cell_link'+i).innerHTML = productIMG[n_page];
			
			if(cid != null){
				if(cid == productID[n_page]){
					$$('cell_link'+i).className = 'selected';
				}
				else{
					$$('cell_link'+i).className = '';
				}
			}		
		}
	}

	$$(pageId).innerHTML = currentPage +'/'+PageNumber;
	$$(Prev).onclick = function () {
		if(!activeClick) return false;
		updateProduct('pre');
	}
	$$(Next).onclick = function () {
		if(!activeClick) return false;
		updateProduct('next');
	}	
}

