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

var interval_ID;
var maxHeight = 0;
var maxHeightMenuTabs = 0;

var actualTop = 0;

function getHeight(id){
	if($(id+'Table')){ 
		maxHeightTable = $(id+'Table').offsetHeight;
	}
	if($(id)) { 
		maxHeightContent = $(id).style.height; 
		maxHeightContent = parseInt(maxHeightContent.replace("px", ""));
	}
}

function initScrollPages(step,id){
	var divId = id;
	getHeight(divId);
	interval_ID = setInterval('startScrollPages("'+divId+'",'+step+');',15);
}

function startScrollPages(divID, step){
	var the_style = getStyleObject(divID);
	if (the_style)
  {
 		if(the_style.top != "")var current_top = parseInt(the_style.top);
		else var current_top = 0;
		
		var new_top = current_top + step;
		if(step > 0 && current_top < 0 ){ 
			if (document.layers) the_style.top = new_top;
			else the_style.top = new_top + "px";
		} 
		if(step < 0 && current_top >= (-maxHeightTable + (maxHeightContent))){
			if (document.layers) the_style.top = new_top;
			else the_style.top = new_top + "px";
		}
  }
}

function stopScrollPages(){
	clearInterval(interval_ID);
}

function getHeightMenu(table){
	if($(table)){ 
		maxHeightTable = $(table).offsetHeight;
		return maxHeightTable;
	}
	if($(table)) { 
		maxHeightContent = $(table).style.height; 
		maxHeightContent = parseInt(maxHeightContent.replace("px", ""));
	}
}

function menuSlider (id) {	
	// The same as before: adding events
	var alt = getHeightMenu ('subCategoryShoppingTable'+id);
	var alt2 = getHeightMenu ('Prova'+id);
	var alt = alt+alt2;
	$('subcategoriesProva'+id).addEvents({
		'click': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.set('tween', {
				duration: 500,
				transition: Fx.Transitions.linear.easeOut // This could have been also 'bounce:out'
			}).tween('height', alt+'px');
		},
		'dblclick': function(){
			
			this.set('tween', {}).tween('height', alt2+'px');
		}
	});
}

function menuSlider1 (id) {	
	// The same as before: adding events
	var alt = getHeightMenu ('subCategoryShoppingTable'+id);
	var alt2 = getHeightMenu ('Prova'+id);
	var alt = alt+alt2;
	$('subcategoriesProva'+id).set('tween', {
		duration: 500,
		transition: Fx.Transitions.linear.easeOut // This could have been also 'bounce:out'
	}).tween('height', alt+'px');
}


//Balloon Top Menu

function initPlugins() { }

var headerTimeout;

function hideMenus(){	
	$('ballon1').style.display = 'none';
	$('ballon2').style.display = 'none';
	$('ballon3').style.display = 'none';
	$('ballon4').style.display = 'none';
	$('ballon5').style.display = 'none';
}

function showMenu(menuId){
	stopMenuDelayClosing();
	hideMenus();
	$(menuId).style.display = 'block';
}

function stopMenuDelayClosing(){
	clearTimeout(headerTimeout);
}

function startMenuDelayClosing(timing){
	if(!timing) timing = 600;
	clearTimeout(headerTimeout);
	headerTimeout = setTimeout('hideMenus();',timing);
}

/*Scrollbar*/

			
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}
