
var idsofsboxs = new Array();
var at_point = 0; // NEW
var at_v_point;
var at_h_point;
var top_end_at;
var left_end_at;
var v_scroll_amount
var h_scroll_amount 
var incroment =  18;
var stepping;
var clock_handel;
var trig_handel;
var pause_lenght = 3000;
var work;
var img_to_parent_offset = 375;
var stop_inx = 1;
var run = 1;
var rev_stop_inx;
var rev_dir =1;
var other_way = 1;

function init(){//document.getElementById("display").value="mark";
document.getElementById('loader').style.visibility='hidden';
idsofsboxs.push('$itemnum');
for (i=0;i<idsofsboxs.length;i++) {
what = idsofsboxs[i];
//document.getElementById("display").value=i;
define_what(what);
buttens_to_display(what);
detect_img_positions(what);

document.getElementById(what).scrollLeft = item_stop_points[0];




//scroll_back('$itemnum');


}; //for (i=0;idsofsboxs.length;i++) 
set_trig(what);
};


function set_trig(what){

trig_handel= setTimeout("next_item_please_v1('"+what+"')",pause_lenght);

};

function next_item_please_v1(what){
rev_dir =1; 
define_what(what);

document.getElementById(what).at_h_point = item_stop_points[stop_inx];

if (stop_inx <= 1){other_way = -1};

stop_inx++;
if (stop_inx == item_stop_points.length){stop_inx =1;}; 

start_h_scroll(what);


//scroll_forward(what);
};


function preveus_item_please_v1(what){
rev_dir =1; other_way = 1;
define_what(what);

stop_inx--;
rev_stop_inx = stop_inx;
if (stop_inx < 0 ){rev_stop_inx =item_stop_points.length -1;rev_dir = -1}; 

rev_stop_inx --;
if (rev_stop_inx < 0 ){rev_stop_inx =item_stop_points.length -2;stop_inx =item_stop_points.length -1;rev_dir = -1}; 

document.getElementById(what).at_h_point = item_stop_points[rev_stop_inx];
//document.getElementById("display").value= item_stop_points[rev_stop_inx]+' '+rev_stop_inx;



start_h_scroll(what);


//scroll_forward(what);
};




function detect_img_positions(what){

for (i=0;i<item_stop_points.length;i++) {

// document.getElementById("display").value= document.getElementById("display").value+ document.getElementById("$item_img_"+i).offsetParent.offsetLeft + ':'+document.getElementById("$item_img_"+i).width +', ';

if (document.getElementById("$item_img_"+i).width > 0) {work= document.getElementById("$item_img_"+i).width / 2} else {work= 0};



work= (document.getElementById("$item_img_"+i).offsetParent.offsetLeft + work) - img_to_parent_offset;

if (work < 0 ){work=0};

item_stop_points[i] = Math.round(work);
//document.getElementById("display").value = document.getElementById("display").value+work+', ';


}; // (i=0;i<item_stop_points.length;i++)



};


function stop_start(what){

if (run > 0){
run = 0;
document.getElementById('ps').src='images/pic-butt_ps_on.png';
clearTimeout(trig_handel);
} else {
run =1;
document.getElementById('ps').src='images/pic-butt_ps_off.png';
next_item_please_v1(what);

}; //if (run > 0)

};

function scroll_down(what){
define_what(what);



document.getElementById(what).at_v_point = document.getElementById(what).at_v_point + v_scroll_amount;
if (document.getElementById(what).at_v_point > (top_end_at - v_scroll_amount)){document.getElementById(what).at_v_point = top_end_at - v_scroll_amount};

start_v_scroll(what);

}; 

function scroll_up(what){

define_what(what);



document.getElementById(what).at_v_point = document.getElementById(what).at_v_point - v_scroll_amount;
if (document.getElementById(what).at_v_point < 0){document.getElementById(what).at_v_point = 0};

start_v_scroll(what);

}; 

function define_what(what){
//document.getElementById("display").value='--'+what;
if (document.getElementById(what).in_uses != 1){
document.getElementById(what).in_uses = 1;
document.getElementById(what).at_v_point =0;
document.getElementById(what).at_h_point =0;


}; // in_uses != 1



top_end_at = document.getElementById(what +"_end").offsetTop;

left_end_at = document.getElementById(what +"_end").offsetParent.offsetLeft;


v_scroll_amount = parseInt(document.getElementById(what).style.height);
h_scroll_amount = parseInt(document.getElementById(what).style.width);

};

function start_v_scroll(what){

if (document.getElementById(what).scrollTop != document.getElementById(what).at_v_point){
clock_handel = setInterval('v_scrolling("'+what+'")', 10);

};

};

function v_scrolling(what){

if (document.getElementById(what).scrollTop < document.getElementById(what).at_v_point){stepping = incroment;
if (document.getElementById(what).scrollTop + stepping  > document.getElementById(what).at_v_point){stepping = document.getElementById(what).at_v_point - document.getElementById(what).scrollTop};
}else if (document.getElementById(what).scrollTop > document.getElementById(what).at_v_point){stepping = incroment * -1;
if (document.getElementById(what).scrollTop + stepping  < document.getElementById(what).at_v_point){stepping = document.getElementById(what).at_v_point - document.getElementById(what).scrollTop};
} else {clearInterval(clock_handel);
stepping =0;

};

document.getElementById(what).scrollTop = document.getElementById(what).scrollTop + stepping;


//document.getElementById("display").value="top="+document.getElementById(what).scrollTop+" point="+document.getElementById(what).at_v_point+" end="+(top_end_at - v_scroll_amount) +" ScrollTop = "+document.getElementById(what).scrollTop;

};


function scroll_forward(what){
define_what(what);


document.getElementById(what).at_h_point = document.getElementById(what).at_h_point + h_scroll_amount;
if (document.getElementById(what).at_h_point > (left_end_at - h_scroll_amount)){document.getElementById(what).at_h_point = left_end_at - h_scroll_amount};

start_h_scroll(what);
buttens_to_display(what);

}; 

function scroll_back(what){

define_what(what);

document.getElementById(what).at_h_point = document.getElementById(what).at_h_point - h_scroll_amount;
if (document.getElementById(what).at_h_point < 0){document.getElementById(what).at_h_point = 0};

start_h_scroll(what);
buttens_to_display(what);
}; 

function start_h_scroll(what){

if (document.getElementById(what).scrollLeft != document.getElementById(what).at_h_point){
clock_handel = setInterval('h_scrolling("'+what+'")', 10);

};

};

function h_scrolling(what){

if (document.getElementById(what).scrollLeft < document.getElementById(what).at_h_point){stepping = incroment;
if (document.getElementById(what).scrollLeft + stepping  > document.getElementById(what).at_h_point){stepping = document.getElementById(what).at_h_point - document.getElementById(what).scrollLeft }; // 
}else if (document.getElementById(what).scrollLeft > document.getElementById(what).at_h_point){stepping = incroment * -1;
if (document.getElementById(what).scrollLeft + stepping  < document.getElementById(what).at_h_point){stepping = document.getElementById(what).at_h_point - document.getElementById(what).scrollLeft};
} else {clearInterval(clock_handel);
stepping =0;other_way = 1;
if (stop_inx ==0){
document.getElementById(what).scrollLeft = item_stop_points[stop_inx];
stop_inx++;} ; //if (stop_inx ==0)
if (run == 1){set_trig(what)};
};

if (stepping > 0){stepping = stepping * rev_dir};
if (stepping < 0){stepping = stepping * other_way};

if (document.getElementById(what).scrollLeft >= item_stop_points[item_stop_points.length -1] && stepping > 0) {document.getElementById(what).scrollLeft = item_stop_points[0]};

if (document.getElementById(what).scrollLeft + stepping < item_stop_points[0]){document.getElementById(what).scrollLeft = item_stop_points[item_stop_points.length -1]};

document.getElementById(what).scrollLeft = document.getElementById(what).scrollLeft + stepping;

//document.getElementById("display").value="L="+document.getElementById(what).scrollLeft+"st="+stepping+"rev_"+rev_dir+" p="+document.getElementById(what).at_h_point;


//document.getElementById("display").value="L="+document.getElementById(what).scrollLeft+"st="+stepping+"wv_"+other_way+" p="+document.getElementById(what).at_h_point;

//document.getElementById("display").value="Left="+document.getElementById(what).scrollLeft+" point="+document.getElementById(what).at_h_point+" end="+(left_end_at - h_scroll_amount);

};


function buttens_to_display(what){

//document.getElementById("display").value= document.getElementById(what).at_h_point +'>= ('+left_end_at+' - '+h_scroll_amount + ' --- '+document.getElementById(what +"_end").offsetParent.offsetLeft;


/*

// Up Down


if (document.getElementById(what).at_h_point >= (left_end_at - h_scroll_amount)){

document.getElementById(what+"_arrow_up").src="images/arrow_none.gif";

} else {

document.getElementById(what+"_arrow_up").src="images/arrow_up.gif";

};




if (document.getElementById(what).at_v_point > 0) {

document.getElementById(what+"_arrow_down").src="images/arrow_down.gif";

} else {

document.getElementById(what+"_arrow_down").src="images/arrow_none.gif";

};

*/


/*

// side to side


if (document.getElementById(what).at_h_point >= (left_end_at - h_scroll_amount)){

document.getElementById(what+"_arrow_right").src="images/arrow_none.gif";

} else {

document.getElementById(what+"_arrow_right").src="images/arrow_right.gif";

};




if (document.getElementById(what).at_h_point > 0) {

document.getElementById(what+"_arrow_left").src="images/arrow_left.gif";

} else {

document.getElementById(what+"_arrow_left").src="images/arrow_none.gif";

};


*/

};

function add_box_id(what){

idsofsboxs.push(what);

};



/*    ------- All Notes and Refeces ---------

//Notes 
//at_v_point="" at_h_point="" in_uses=""

from function init()

//what = idsofsboxs[i].substring(0,idsofsboxs[i].length);

//scroll_amount = document.getElementById("itemscatalog").style.posHeight;
//end_at = document.getElementById("end").offsetTop;

//document.display.value="yes";//not working


//document.getElementById("display").value=document.getElementById("$itemnum").scrollTop
//document.getElementById("display").value=document.getElementById("$itemnum_end").offsetTop;
//document.getElementById("$itemnum").at_v_point="1";
//document.getElementById("display").value=document.getElementById("$itemnum").at_v_point;

//document.getElementById("$itemnum").at_v_point = 0;

from function scroll_down(what)
//document.getElementById(what).scrollTop = top_end_at - v_scroll_amount ;

from function scroll_up(what)
//document.getElementById("itemscatalog").scrollTop = 0 ;

from function define_what(what)
//-//if (document.getElementById(what).at_h_point == "NaN"){};

//at_v_point=document.getElementById(what).at_v_point;
//at_h_point=document.getElementById(what).at_h_point;

//-//document.getElementById("display").value = left_end_at;

//-//document.getElementById(what).style.width;
//-//  offsetLeft offsetWidth  

//-//document.getElementById("display").value = h_scroll_amount


//-//document.getElementById("display").value = document.getElementById(what).scrollTop;
//-//document.getElementById("display").value = document.getElementById(what).scrollLeft;

from function start_v_scroll(what)

from function v_scrolling(what)
//document.getElementById("display").value =what;

//document.getElementById(what).at_v_point= at_v_point;

from function scroll_forward(what)

from function scroll_back(what)

from function start_h_scroll(what)


from function h_scrolling(what)
//document.getElementById("display").value =what;

//document.getElementById(what).at_v_point= at_v_point;

from function buttens_to_display(what)
 Up Down
//-// if (end_at >= (frame_hight + at_point)) 
//-//if (top_end_at >= (v_scroll_amount + document.getElementById(what).at_v_point)) {

 side to side
//if (left_end_at >= (h_scroll_amount + document.getElementById(what).at_h_point)) 







*/





