﻿// JScript File

var clipRight = 615;
var clipLeft = 0;

var topper = 0;
var lyrwidth = 0;
var time,amount,theTime,theHeight,DHTML;

var prev_model = null;
var curr_model = null;

window.onload = function()
{
    init();
    var td = document.getElementById("tmodels");
    if(td)
    {
        var arr = td.getElementsByTagName("div");
        for(var i = 0; i < arr.length; i++)
        {
            if(arr[i].className == "gitem_mid_act")
            {
                prev_model = arr[i];
                break;
            }
        }
    }
}

//-------------- AJAX --------------
function DoPostBack(url, a)
{
    document.body.style.cursor = "wait";
    a.style.cursor = "wait";
    curr_model = a.parentNode.parentNode.parentNode;
    
    request_page = getRequest();
    request_page.onreadystatechange = stateChange_request_page;
    request_page.open("GET", url, true);
    request_page.setRequestHeader("Content-Type", "text/html");
    request_page.send("");
}
function getRequest()
{
    var xreq = null;
    if(window.XMLHttpRequest)
    {
        xreq = new XMLHttpRequest;
    }
    else if(typeof ActiveXObject != "undefined")
    {
        xreq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xreq;
}
function stateChange_request_page()
{
    if(request_page.readyState == 4)
    {
        LoadContent(request_page.responseText);
    }
}
function LoadContent(resp_text)
{
    var div = document.createElement("div");
    div.innerHTML = resp_text;
    var arr = div.getElementsByTagName("div");
    var d = null;
    for(var i=0; i<arr.length; i++)
    {
        if(arr[i].id == "div_model_detail") d = arr[i];
    }
    if(d != null)
    {
        var div_model = document.getElementById("div_model_detail");
        div_model.innerHTML = d.innerHTML;
    }
    prev_model.className = "gitem_mid";
    curr_model.className = "gitem_mid_act";
    curr_model.firstChild.firstChild.firstChild.style.cursor = "default";
    document.body.style.cursor = "default";
    prev_model = curr_model;
}
//----------------------------------

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('div_flash');
	if(x.obj!=null)
	{
	    if (document.getElementById || document.all)
	    {
	        var img_flash= document.getElementById("tmodels");
	        if(img_flash)
	        {
		        lyrwidth = img_flash.offsetWidth;
	            if(lyrwidth<=clipRight)
	            {
	                document.getElementById('to_left').style.visibility='hidden';
	                document.getElementById('to_right').style.visibility='hidden';
	                x.style.clip = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
	                //scrollToCenter();
	                x.style.width = clipRight - topper + "px";
	            }
	            else
	            {
	                document.getElementById('to_left').style.visibility='visible';
	                document.getElementById('to_right').style.visibility='visible';
    	            
		            x.style.clip = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		            x.style.width = clipRight + "px";
		            //srollToRight();
		        }
		        var td = document.getElementById("gcenter");
		        td.style.height = img_flash.offsetHeight + "px";
		        x.style.visibility = "visible";
		    }
		    else
		    {
		        document.getElementById('to_left').style.visibility='hidden';
	            document.getElementById('to_right').style.visibility='hidden';
		    }
	    }
	}
}

function scrollayer(amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj('div_flash');
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipLeft += amount;
	clipRight += amount;
	topper -= amount;
	if (clipLeft < 0 || clipRight > lyrwidth)
	{
		clipLeft -= amount;
		clipRight -= amount;
		topper += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
	    thelayer = new getObj('div_flash');
		clipstring = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.marginLeft = topper + 'px';
		thelayer.style.width = parseInt(amount) + parseInt(thelayer.style.width) + "px";
	}
	time = setTimeout('realscroll()',theTime);
}

function scrollToCenter()
{
    if (!DHTML) return;
    thelayer = new getObj('div_flash');
    while(true)
    {
	    topper += 1;
	
        if (topper > ((clipRight - lyrwidth)/2))
	    {   
		    topper += 1;
		    thelayer.style.marginLeft = topper + 'px';
		    return;
	    }
	}
}

function srollToRight()
{
 if (!DHTML) return;
 thelayer = new getObj('div_flash');
    while(true)
    {
	clipLeft += 1; 
	clipRight += 1;
	topper -= 1;
	
        if (clipRight > (lyrwidth/2 + 307))
	    {
		    clipLeft -= 1;
		    clipRight -= 1;
		    topper += 1;
		    clipstring = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		    thelayer.style.clip = clipstring;
		    thelayer.style.marginLeft = topper + 'px';
		    thelayer.style.width = parseInt(clipLeft) + parseInt(thelayer.style.width) + "px";
		    return;
	    }
	    
	}
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  	if(document.getElementById(name) !=null)
  	{
	    this.style = document.getElementById(name).style;
	}
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}
