//THIS FILE CONTAINS SHOPS OWN PLUGINS AND FUNCTIONS. INITPLUGINS FUNCTION IS CALLED ON SOURCE LOADED

function initPlugins()
{

	if($('productsIndex')){
		var V2 = new viewer($$('#productsIndexBox div.productIndex)'),{
			mode: 'alpha',
			interval: 4000
		});
		V2.play(true);
		V2.play.bind(V2,[false]);
	}

}

var interval_ID;
var maxWidth;
var maxWidthMenuTabs;

var interval_IDVertical;
var maxHeight;
var maxHeightMenuTabs;

var intervals_IDVertical = new Array();
var arrMaxHeight = new Array();
var arrMaxHeightMenuTabs = new Array();

var intervals_ID = new Array();
var arrMaxWidth = new Array();
var arrMaxWidthMenuTabs = new Array();


function getWidth(id){
	if(id){
		if(document.getElementById("menuTabsTable"+id)){ arrMaxWidth[id] = document.getElementById("menuTabsTable"+id).offsetWidth;}
		if(document.getElementById("menuTabs"+id)) { arrMaxWidthMenuTabs[id] = document.getElementById("menuTabs"+id).style.width; arrMaxWidthMenuTabs[id] = parseInt(arrMaxWidthMenuTabs[id].replace("px", ""));	}
	}
	else{
		if(document.getElementById("menuTabsTable")){ maxWidth = document.getElementById("menuTabsTable").offsetWidth;}
		if(document.getElementById("menuTabs")) { maxWidthMenuTabs = document.getElementById("menuTabs").style.width;	maxWidthMenuTabs = parseInt(maxWidthMenuTabs.replace("px", ""));}
	}
}

function getHeight(id){
	if(id){
		if(document.getElementById("menuTabsTableVertical"+id)){ arrMaxHeight[id] = document.getElementById("menuTabsTableVertical"+id).offsetHeight;}
		if(document.getElementById("menuTabsVertical"+id)) { arrMaxHeightMenuTabs[id] = document.getElementById("menuTabsVertical"+id).style.height; arrMaxHeightMenuTabs[id] = parseInt(arrMaxHeightMenuTabs[id].replace("px", ""));}
	}
	else{
		if(document.getElementById("menuTabsTableVertical")){ maxHeight = document.getElementById("menuTabsTableVertical").offsetHeight;}
		if(document.getElementById("menuTabsVertical")) { maxHeightMenuTabs = document.getElementById("menuTabsVertical").style.height; maxHeightMenuTabs = parseInt(maxHeightMenuTabs.replace("px", ""));}
	}
}


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject



function startMenu(step, id)
{
	var divId = "menuTabs";
	if(id){
		divId = divId +id;
		intervals_ID[id] = setInterval('moveDiv("'+divId+'",'+step+',\''+id+'\');',15);
	}
	else{
		interval_ID = setInterval('moveDiv("'+divId+'",'+step+');',15);
	}
}

function startMenuVertical(step, id)
{
	var divId = "menuTabsVertical";
	if(id){
		divId = divId +id; 
		intervals_IDVertical[id] = setInterval('moveDivVertical("'+divId+'",'+step+',\''+id+'\');',15);
	}
	else{
		interval_IDVertical = setInterval('moveDivVertical("'+divId+'",'+step+');',15);
	}
}

function moveDiv(divID,step, id)
{
  // get the stylesheet
  //
	if(id){ getWidth(id);}
	else getWidth();
  var the_style = getStyleObject(divID);

  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
		var new_left = current_left + step;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
		if(step > 0 && current_left < 0 ){
			
			if (document.layers)  
			{
				the_style.left = new_left;
			}
			else 
			{  
				the_style.left = new_left + "px";
			}
		}
		if(id){
			if(step < 0 && current_left >= (-arrMaxWidth[id] + arrMaxWidthMenuTabs[id])){
				if (document.layers) 
				{
					the_style.left = new_left;
				}
				else 
				{  
					the_style.left = new_left + "px";
				}
			}
		}
		else{
			 if(step < 0 && current_left >= (-maxWidth + maxWidthMenuTabs)){
				if (document.layers) 
				{
					the_style.left = new_left;
				}
				else 
				{  
					the_style.left = new_left + "px";
				}
			}
		}
		
  }
}

function moveDivVertical(divID,step, id)
{
  // get the stylesheet
  //
 	if(id){ getHeight(id);}
	else getHeight();
  var the_style = getStyleObject(divID);
	if (the_style)
  {
    // get the current coordinate and add 5
    //
		if(the_style.top != "")
	    var current_top = parseInt(the_style.top);
		else
			var current_top = 0;
		
	var new_top = current_top + step;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
		if(step > 0 && current_top < 0 ){ 
			if (document.layers) 
			{
				the_style.top = new_top;
			}
			else 
			{  
				the_style.top = new_top + "px";
			}
		} 
		if(id){
			if(step < 0 && current_top >= (-arrMaxHeight[id] + (arrMaxHeightMenuTabs[id]))){
				if (document.layers) 
				{
					the_style.top = new_top;
				}
				else 
				{  
					the_style.top = new_top + "px";
				}
			}
		}
		else{
			if(step < 0 && current_top >= (-maxHeight + (maxHeightMenuTabs))){
				if (document.layers) 
				{
					the_style.top = new_top;
				}
				else 
				{  
					the_style.top = new_top + "px";
				}
			}
		}
  }
}

function stopMenu(id){
	if(id) clearInterval(intervals_ID[id]);	
	else clearInterval(interval_ID);
}

function stopMenuVertical(id)
{
	if(id) clearInterval(intervals_IDVertical[id]);
	else clearInterval(interval_IDVertical);
}