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 loadContent(nameFile, nameDiv, callBack, ajaxLoading) {
	if(ajaxLoading != "")
		ajaxLoading = "<img src='" + shop.url + "/ecommerce/images/icons/"+ajaxLoading+"'>";
	if($(nameDiv+'Floater'))$(nameDiv+'Floater').style.top = 30+ (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 'px';
	loadAjaxFile(nameFile, nameDiv, callBack, ajaxLoading);
}

function closeContent(){
	$('informationBox').innerHTML = '';
	$('informationBox').style.visibility = 'hidden';
}

function submitForm(form, divId, callBack, imageLoading){
	if(imageLoading)
			document.getElementById(divId).innerHTML = "<img src='" + shop.url + "/ecommerce/images/icons/"+imageLoading+"'>";
	Spry.Utils.submitForm(form, function(req){document.getElementById(divId).innerHTML = req.xhRequest.responseText; eval(callBack);} );
}


function changeClass(obj, nameClass, nameClass2){
	if(obj.className == nameClass){obj.className = nameClass2;}
	else {obj.className = nameClass;}
}

function restartShadowbox(){
	Shadowbox.clearCache(); Shadowbox.setup(); 
}

function playMusic(file){
	ajaxLoadSync(shop.url + '/ajaxTemplates/common/checkoutActions.cfm?action=sound_open')
	$('audioDiv').innerHTML = '<embed src="'+file+'" hidden="true" autostart="true" loop="true" type="audio/wav">';
}
function stopMusic(){
	ajaxLoadSync(shop.url + '/ajaxTemplates/common/checkoutActions.cfm?action=sound_close')	
	$('audioDiv').innerHTML = '';
}

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 getWidthScroll(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 getHeightScroll(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){ getWidthScroll(id);}
	else getWidthScroll();
  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
    //
		//alert(step);
		//alert(current_left);
		
		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
  //
 //alert(-maxHeight + maxHeightMenuTabs);
	if(id){ getHeightScroll(id);}
	else getHeightScroll();
  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()
{
clearInterval(interval_ID);
}

function stopMenu(id){
	clearInterval(intervals_ID[id]);
}

function stopMenuVertical(id)
{
clearInterval(intervals_IDVertical[id]);
}