function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function TesteBox() {
	
	this.curent = 1;
	
	this.active = "";
	this.defImg = "";
	
	this.isSetDefImg = false;
	
	this.previousProduct = function() {
		if(document.getElementById("product_" + (this.curent-2))) {
			this.curent --;
			
			document.getElementById("product_" + (this.curent-1)).className = "item_visible";
			document.getElementById("product_" + (this.curent+2)).className = "item_hidden";
		};
		
		this.clearProductInfo();
	};
	
	this.nextProduct = function() {
		if(document.getElementById("product_" + (this.curent+2))) {
			this.curent ++;
			
			document.getElementById("product_" + (this.curent-2)).className = "item_hidden";
			document.getElementById("product_" + (this.curent+1)).className = "item_visible";
		};
		
		this.clearProductInfo();
	};
	
	this.activeProduct = function(ref) {
		//this.active = ref;
		
		if (document.getElementById("image"))
		{
			
			if(!this.isSetDefImg) {
				this.defImg = document.getElementById("image").innerHTML;
			}
			
			var sImg = ref.getElementsByTagName("img")[0];
			var bImg = ref.getElementsByTagName("img")[1];
			var moreInfo = ref.getElementsByTagName("div")[0];
			
			var image = moreInfo.getElementsByTagName("div")[3];
			
			document.getElementById("image").innerHTML = image.innerHTML;
			
			sImg.className = "img_hidden";
			bImg.className = "img_visible";
			moreInfo.className = "more_info_visible";
			
			ref.style.zIndex = 9999;
		}
	};
	
	this.inactiveProduct = function(ref) {
		//this.active = ref;
		if (document.getElementById("image"))
		{
			var sImg = ref.getElementsByTagName("img")[0];
			var bImg = ref.getElementsByTagName("img")[1];
			var moreInfo = ref.getElementsByTagName("div")[0];
			
			document.getElementById("image").innerHTML = this.defImg;
			
			sImg.className = "img_visible";
			bImg.className = "img_hidden";
			moreInfo.className = "more_info_hidden";
			
			ref.style.zIndex = 99;
		}
	};
	
	this.showProductInfo = function(ref) {
		this.active = ref;
		
		if( window.innerHeight && window.scrollMaxY ) { // Firefox
			pageWidth = window.innerWidth + window.scrollMaxX;
			pageHeight = window.innerHeight + window.scrollMaxY;
		} else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
			pageWidth = document.body.scrollWidth;
			pageHeight = document.body.scrollHeight;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
			pageHeight = document.body.offsetHeight + document.body.offsetTop; 
		}
		
		if(pageWidth <= 1045) {
			self.scrollTo(0, 125+document.getElementById("testebox").offsetTop);
		}
		
		document.getElementById("image").className = "image";
		
		this.defImg = document.getElementById("image").innerHTML;
		
		var moreInfo = ref.getElementsByTagName("div")[0];
		var informations = moreInfo.getElementsByTagName("div")[2];
		
		document.getElementById("more_information").innerHTML = informations.innerHTML;
	};
	
	this.clearProductInfo = function() {		
		document.getElementById("more_information").innerHTML = "";
		document.getElementById("image").innerHTML = this.defImg;
	};
	
	this.showHowToPrepare = function() {
		if(this.active!="") {
			var how_to_prepare_dark = document.getElementById("how_to_prepare_dark");
			var how_to_prepare_box = document.getElementById("how_to_prepare_box");
			var how_to_prepare_content = document.getElementById("how_to_prepare_content");
			
			var moreInfo = this.active.getElementsByTagName("div")[0];
			var content = moreInfo.getElementsByTagName("div")[4];
			
			if( window.innerHeight && window.scrollMaxY ) { // Firefox
				pageWidth = window.innerWidth + window.scrollMaxX;
				pageHeight = window.innerHeight + window.scrollMaxY;
			} else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
				pageWidth = document.body.scrollWidth;
				pageHeight = document.body.scrollHeight;
			} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
				pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
				pageHeight = document.body.offsetHeight + document.body.offsetTop; 
			}
			
			how_to_prepare_dark.style.display = "block";
			how_to_prepare_dark.style.width  = pageWidth + "px";
			how_to_prepare_dark.style.height = pageHeight + "px";
			
			how_to_prepare_content.innerHTML = content.innerHTML;
			
			how_to_prepare_box.style.display = "block";
			
			how_to_prepare_box.style.top = 470 + "px";
			how_to_prepare_box.style.left = (((pageWidth - how_to_prepare_box.offsetWidth)/2)-25) + "px";
		};
	};
	
	this.hideHowToPrepare = function() {
		var how_to_prepare_dark = document.getElementById("how_to_prepare_dark");
		var how_to_prepare_box = document.getElementById("how_to_prepare_box");
		
		how_to_prepare_dark.style.display = "none";
		how_to_prepare_box.style.display = "none";
	};
	
};

var testebox = new TesteBox();

function displayFirstProductImage()
{
	if (document.getElementById("image"))
	{
		var ref = document.getElementById("product_0");
		if (ref)
		{
			var moreInfo = ref.getElementsByTagName("div")[0];
			
			var image = moreInfo.getElementsByTagName("div")[3];
			
			document.getElementById("image").className = "image_noactive";
			document.getElementById("image").innerHTML = image.innerHTML;
		}
		else
		{
			document.getElementById("image").innerHTML = "";
		}

	}

}

addEvent(window, 'load', displayFirstProductImage);