// VARS
var z1img_size = '524x524';
var z1img_win = 'http://www.cadeogame.com.br/MostraImagem/';
var z1img_siz_w = 1000;
var z1img_siz_h = 600;

// NAVIGATION FUNCTIONS
function AbreImg(uri)
	{
		var siz_w = z1img_siz_w;
		var siz_h = z1img_siz_h;
		
		var win = abreJanela(z1img_win+escape(ByDeaDz1(uri)), 'Z1IMGZOOM', siz_w, siz_h);
		win.moveTo(screen.width/2 - siz_w/2, screen.height/2 - siz_h/2 - 50);
		win.focus();
	}
function ByDeaDz1(n)
	{
		n = n.substr(0, n.lastIndexOf('_')) + '_' + z1img_size + n.substr(n.lastIndexOf('.'));
		n = n.split('/');
		return n.pop();
	}

// DHTML TITLES
var windowOnMouseDown_last = false;
function windowOnMouseDown(ev, html) {
	
	if(windowOnMouseDown_last) {
		try {
			document.getElementsByTagName("body").item(0).removeChild(windowOnMouseDown_last);
		} catch(err) { ; }
	}
	
	var div = document.createElement("DIV");
	div.className = 'windowOnMouseDown';
	div.innerHTML = html;
	document.getElementsByTagName("body").item(0).appendChild(div);

	var w = getElWidth(div);
	var h = getElHeight(div);
	var coord = getMouseXY(ev);
	var wins = getWinSize(window);
	var scrl = getWinScroll(window);
	var newX = (coord.x - w/2);
	var newY = (coord.y - h/2);

	//alert('Win:'+wins.w+'x'+wins.h+'\nObj Pos:'+newX+'x'+newY+'\nObj Dim:'+w+'x'+h);
	
	if(newX+w > (wins.w+scrl.x) ) // right
		newX = (wins.w+scrl.x)-(w+5);
	if(newY+h > (wins.h+scrl.y) ) // bottom
		newY = (wins.h+scrl.y)-(h+5);

	if(newX < scrl.x) // left
		newX = scrl.x+5;
	if(newY < scrl.y) // top
		newY = scrl.y+5;
	
	//alert('Win:'+wins.w+'x'+wins.h+'\nObj Pos:'+newX+'x'+newY+'\nObj Dim:'+w+'x'+h);
	
	div.style.left = newX + 'px';
	div.style.top = newY + 'px';
	
	div.onmousedown = function () { document.onclick = null; }
	div.onmouseout = function () { 
			try {
					document.onclick = function () {
										try { 
											document.getElementsByTagName("body").item(0).removeChild(div);
											document.onclick=null;
										} catch(err) { };
									};
				} catch(err) { };
		}

	
	//div.onclick = function () { document.onclick=null; try { document.getElementsByTagName("body").item(0).removeChild(div); } catch(err) { ; } } ;
	setTimeout( function () {
		div.onmouseout();
	}, 100);
	windowOnMouseDown_last = div;
	
	return true;
}

// MULTIPLE FILES
function MultipleFiles (el) {
	var input = document.createElement("INPUT");
	input.type = 'file';
	input.name = 'upl[]';
	input.style.margin = '3px';
	
	el.appendChild(input);
}

// SPOILER
function spoiler(obj) {
	var holder = obj.parentNode.getElementsByTagName('DIV').item(1);
	holder.style.display = '';
	obj.style.display = 'none';
	fixCssLayout();
}
function unspoiler(obj) {
	var holder = obj.parentNode;
	var expander = holder.parentNode.getElementsByTagName('DIV').item(0)
	expander.style.display = '';
	holder.style.display = 'none';
	fixCssLayout();
}

// OUTDOOR
var currentOutdoor = 1;
var outdoorAutoPlay = true;
var outdoorList = [];
function saveOutdoor(num, uri, img, texto, label, titulo) {
	outdoorList[num] = new Array(num, uri, img, texto, label, titulo);
}
function updateOutdoor() {
	getE('Outdoor_'+currentOutdoor).className = 'outdoor_current';
}
function playOutdoor() {
	if(outdoorAutoPlay) {
		var next = currentOutdoor+1;
		if(next == 6) {
			next = 1;
		}
		changeOutdoor(next);
	}
}
function changeOutdoor(num) {
	try {
		var uri = outdoorList[num][1];
		var img = outdoorList[num][2];
		var texto = outdoorList[num][3];
		var label = outdoorList[num][4];
		var titulo = outdoorList[num][5];
	
		ps = getE('HomeOutdoor').getElementsByTagName('P');
		resumo = getE('outdoor_titulo').getElementsByTagName('A').item(0);
		
		ps.item(0).firstChild.href = uri;
		ps.item(0).firstChild.innerHTML = label;
		
		ps.item(1).firstChild.href = uri;
		ps.item(1).firstChild.innerHTML = label;
		
		ps.item(2).firstChild.href = uri;
		ps.item(2).firstChild.innerHTML = label;
		
		resumo.innerHTML = ' <strong>'+label+'</strong> - '+texto+' ...';
			
		for(i=0;i<=5;i++) {
			try {
				getE('Outdoor_'+i).className = 'outdoor';
				getE('outdoor_img_'+i).style.display = 'none';
			} catch(err) { }
		}
		
		getE('outdoor_img_'+num).style.display = '';
		
		currentOutdoor = num;
		
		updateOutdoor();
	} catch (err) { return; }
}