/* JavaScript Document */
/*

	Copyright 2009 Hpito design
      
*/
var works = new Spry.Data.XMLDataSet("xml/projects.xml", "afttf/work", {useCache: false, subPaths: "imagens" });
works.setColumnType("titulo", "html"); works.setColumnType("texto", "html");

var sale01 = new Spry.Data.XMLDataSet("xml/sale.xml", "afttf/art");
sale01.setColumnType("nome", "html"); sale01.setColumnType("text", "html");

var sale02 = new Spry.Data.XMLDataSet("xml/sale.xml", "afttf/screenprint");
sale02.setColumnType("nome", "html"); sale02.setColumnType("text", "html");

var sale03 = new Spry.Data.XMLDataSet("xml/sale.xml", "afttf/tee");
sale03.setColumnType("nome", "html"); sale03.setColumnType("text", "html");

var sale04 = new Spry.Data.XMLDataSet("xml/sale.xml", "afttf/print");
sale04.setColumnType("nome", "html"); sale04.setColumnType("text", "html");


<!--Apanhar o url!-->
var params = Spry.Utils.getURLHashParamsAsObject(window.location.hash);
if (params.work){
	works.addObserver({ onDataChanged: function(ds, type)
{
	var row = works.findRowsWithColumnValues({"titulo": ""+params.work+""}, true);
	if (row)
		works.setCurrentRow(row.ds_RowID);
		document.getElementById("intro").style.display='none';
		document.getElementById("work").style.display='block';
} });
works.loadData(); 
}


<!--PayPal!-->
function addItem(number){
			
			var  nome = document.getElementById(number+"_nome");
			var  preco = document.getElementById(number+"_preco");
			var  tamanho = document.getElementById(number+"_tamanho");
		
			var produto = ' Name: '+ nome.value + tamanho.value
		
			var url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=d%40addfueltothefire%2ecom&undefined_quantity=1&item_name='+produto+'&amount='+preco.value+'&no_shipping=2&no_note=1&currency_code=EUR&bn=PP%2dBuyNowBF&charset=UTF%2d8';
window.open(url, '', '');
}


// menu load 
if (document.getElementById) { window.onload = swap };
function swap() {
var numimages=2;
rndimg = new Array("media/menu01.gif", "media/menu03.gif"); 
x=(Math.floor(Math.random()*numimages));
randomimage=(rndimg[x]);
document.getElementById("nu01").style.backgroundImage = "url("+ randomimage +")"; 
document.getElementById("nu02").style.backgroundImage = "url("+ randomimage +")"; 
document.getElementById("nu03").style.backgroundImage = "url("+ randomimage +")"; 
document.getElementById("nu04").style.backgroundImage = "url("+ randomimage +")"; 
document.getElementById("nu05").style.backgroundImage = "url("+ randomimage +")";
/*document.getElementById("blog").style.backgroundImage = "url("+ randomimage +")";*/
}

function tasluci(elementid){
fad01 = new OpacityTween(document.getElementById(elementid),Tween.strongEaseOut, 100, 0, 0.5);
fad02 = new OpacityTween(document.getElementById(elementid),Tween.strongEaseIn, 0, 100, 0.8);
fad01.start();fad01.onMotionFinished = function(){fad02.start()};
}

function opensale(){
	if ( document.getElementById('menusale').style.height == '70px' ){ 
	} else {
	abrir = new Tween(document.getElementById('menusale').style,'height',Tween.strongEaseOut,0,70,1,'px');abrir.start();}
}

function closale(){
	if ( document.getElementById('menusale').style.height == '70px' ){
	fexar = new Tween(document.getElementById('menusale').style,'height',Tween.strongEaseOut,70,0,1,'px');fexar.start();}
}


// Fazer aparecer uma div e desaparecer as outras todas
function hideAll(Id){
var theArray= new Array('intro','work','allwork','about','contact','sale01','sale02','sale03','sale04');
w=document.getElementById(Id)
       for(i=0; i<theArray.length; i++){
            if(theArray[i] == Id){
               window.setTimeout("w.style.display='block'" , 500);
            }else{
                document.getElementById(theArray[i]).style.display='none';	
            }
      } 
}

function openwork(){
move01 = new Tween(document.getElementById('work_th').style,'width',Tween.regularEaseInOut, 0, 800, 1.5,'px');
move02 = new Tween(document.getElementById('tapawork').style,'width',Tween.regularEaseInOut, 0, 800, 1.5,'px');
fad01 = new OpacityTween(document.getElementById('work_th'),Tween.regularEaseIn, 10, 100, 1);
fad02 = new OpacityTween(document.getElementById('tapamenu'),Tween.regularEaseIn, 0, 40, 1);
fad03 = new OpacityTween(document.getElementById('tapawork'),Tween.regularEaseIn, 0, 100, 1);
fad04 = new OpacityTween(document.getElementById('fechar'),Tween.strongEaseIn, 0, 100, 0.8);
document.getElementById('tapamenu').style.display='block';
document.getElementById('fechar').style.display='block';
move01.start();move02.start();fad01.start();fad02.start();fad03.start();fad04.start()
}

function closework(){
move01 = new Tween(document.getElementById('work_th').style,'width',Tween.strongEaseOut, 800, 0, 2,'px');
move02 = new Tween(document.getElementById('tapawork').style,'width',Tween.strongEaseOut, 800, 0, 2,'px');
fad01 = new OpacityTween(document.getElementById('work_th'),Tween.regularEaseIn, 100, 10, 1);
fad02 = new OpacityTween(document.getElementById('tapamenu'),Tween.regularEaseIn, 40, 0, 1);
fad03 = new OpacityTween(document.getElementById('tapawork'),Tween.regularEaseIn, 100, 0, 1);
fad04 = new OpacityTween(document.getElementById('fechar'),Tween.strongEaseIn, 100, 0, 0.8);
window.setTimeout("document.getElementById('tapamenu').style.display='none'" , 1000);
window.setTimeout("document.getElementById('fechar').style.display='none'" , 1000);
move01.start();move02.start();fad01.start();fad02.start();fad03.start();fad04.start()
}


//Scroll to the top
function currentYPosition() {
    // Firefox, Chrome, Opera, Safari
    if (self.pageYOffset) return self.pageYOffset;
    // Internet Explorer 6 - standards mode
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    // Internet Explorer 6, 7 and 8
    if (document.body.scrollTop) return document.body.scrollTop;
    return 0;
}

function elmYPosition(eID) {
    var elm = document.getElementById(eID);
    var y = elm.offsetTop;
    var node = elm;
    while (node.offsetParent && node.offsetParent != document.body) {
        node = node.offsetParent;
        y += node.offsetTop;
    } return y;
}

function smoothScroll(eID) {
    var startY = currentYPosition();
    var stopY = elmYPosition(eID);
    var distance = stopY > startY ? stopY - startY : startY - stopY;
    if (distance < 100) {
        scrollTo(0, stopY); return;
    }
    var speed = Math.round(distance / 50);
    var step = Math.round(distance / 10);
    var leapY = stopY > startY ? startY + step : startY - step;
    var timer = 0;
    if (stopY > startY) {
        for ( var i=startY; i<stopY; i+=step ) {
            setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
            leapY += step; if (leapY > stopY) leapY = stopY; timer++;
        } return;
    }
    for ( var i=startY; i>stopY; i-=step ) {
        setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
        leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
    }
}
