// 8a functions.js

function showtitle(page) {
	// Hide actual title
	new Effect.Fade('titulo-span');
	// Move to start
	new Effect.MoveBy ('titulo-span', 300, 0, {duration: 0.1});
	// Change image
	var image = page + '.jpg';
	$('titulo-img').src = image;
	//Move & appear
	new Effect.MoveBy( this.parentNode, 300, 0, {duration: 0.5,  transition: Effect.Transitions.reverse});
}

function toggleBoxONOFF(ID) {
	if(document.getElementById(ID).style.display == 'block') {
		toggleBox(ID, 0);
	} else {
		toggleBox(ID, 1);
	}
}
function displayCheckStatus(ID) {
    if(document.layers)	{   //NN4+
       return document.layers[ID].display;
    } else if(document.getElementById)	{  //gecko(NN6) + IE 5+
        var obj = document.getElementById(ID);
		return obj.style.display;
    } else if(document.all) {	// IE 4
        return document.all[ID].style.display;
    }
}
function displayIsOn(ID) {
	return displayCheckStatus(ID)== "block";
}
function displayIsOff(ID) {
	return (displayCheckStatus(ID)== "none" || displayCheckStatus(ID)== "");
}
function toggleBox(ID, iState) // 1 visible, 0 hidden
{
	if(document.layers)	   //NN4+
    {
       document.layers[ID].display = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(ID);
		obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[ID].style.display = iState ? "block" : "none";
    }
}

function turnOff(ID) {
	$(ID).style.opacity = 0;
}

function getMP3(mp3id) {
	// chequeo si esta logueado
	gmp3id = mp3id;
	var url = '/get.php';
	var getData = 'mp3id=' + mp3id;
	// ventana de wait
	toggleBox('showdownload',0);
	toggleBox('waiting',1);
	toggleBox('code-box',0);
	toggleBox('code',1);
	// llamo a get
	new Ajax.Request(url, {
	  method: 'get',
	  parameters: getData,
	  onSuccess: function(transport) {
		// si no esta logueado devuelve nologin y muestra login
		if (transport.responseText.match(/nologin/)) {
			toggleBox('showdownload',0);
			toggleBox('waiting',0);
			toggleBox('code-box',1);
		} else {
		// si esta logueado devuelve la info, updateo div y muestro
			$('mp3link').update(transport.responseText); 
			toggleBox('showdownload',1);
			toggleBox('waiting',0);
			toggleBox('code-box',0); 
		  //notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' });
		}
	  }
	});

}

function sendCode(code) {
	var getData = $('formcode').serialize();
	getData = getData + '&mp3id=' + gmp3id;
	url = 'get.php';
	
	toggleBox('showdownload',0);
	toggleBox('waiting',1);
	toggleBox('code-box',0);
	
	new Ajax.Request(url, {
	  method: 'get',
	  parameters: getData,
	  onSuccess: function(transport) {
		// si no esta logueado devuelve nologin y muestra login
		if (transport.responseText.match(/nologin/)) {
			toggleBox('showdownload',0);
			toggleBox('waiting',0);
			toggleBox('code-box',1);
		} else if (transport.responseText.match(/badlogin/)) {
			
			toggleBox('showdownload',0);
			toggleBox('waiting',0);
			toggleBox('code-box',1);
			$('code-error').update('El codigo ingresado es incorrecto.');
		} else {
		// si esta logueado devuelve la info, updateo div y muestro
			$('mp3link').update(transport.responseText); 
			toggleBox('showdownload',1);
			toggleBox('waiting',0);
			toggleBox('code-box',0); 
		  //notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' });
		}
	  }
	});

}

function changeBackground(id) {
	if(id == 1) {
		$('container').style.backgroundImage = 'url(/img/background-azul.jpg)';
	} else {
		$('container').style.backgroundImage = 'url(/img/background-purpura.jpg)';
	}
}

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function goDown(ID) {
	
	document.getElementById('caracteristicas').style.display = 'block';

	//new Effect.Appear( $(ID), {queue: 'end', scope: 'specs', limit:4} );
}

function goUp(ID) {
	document.getElementById('caracteristicas').style.display = 'none';
	//new Effect.Fade($(ID),{queue: 'front', scope: 'specs', limit:4});
}



// Scroller

//scroller width
var swidth=130;
//scroller height
var sheight=1;
//background color
var sbcolor='#1c82b6';
//scroller's speed
var sspeed=1;

var resumesspeed = 1;

var speedArray = new Array();
speedArray["ticker"]=1;
speedArray["ticker2"]=1;
speedArray["ticker3"]=1;
speedArray["ticker4"]=1;
speedArray["ticker5"]=1;
speedArray["ticker6"]=1;
speedArray["ticker7"]=1;
speedArray["ticker8"]=1;
speedArray["ticker9"]=1;
speedArray["ticker10"]=1;

var sheightArray = new Array();
sheightArray["ticker"]=1;
sheightArray["ticker2"]=1;
sheightArray["ticker3"]=1;
sheightArray["ticker4"]=1;
sheightArray["ticker5"]=1;
sheightArray["ticker6"]=1;
sheightArray["ticker7"]=1;
sheightArray["ticker8"]=1;
sheightArray["ticker9"]=1;
sheightArray["ticker10"]=1;

var resumespeedArray = new Array();
resumespeedArray["ticker"]=1;
resumespeedArray["ticker2"]=1;
resumespeedArray["ticker3"]=1;
resumespeedArray["ticker4"]=1;
resumespeedArray["ticker5"]=1;
resumespeedArray["ticker6"]=1;
resumespeedArray["ticker7"]=1;
resumespeedArray["ticker8"]=1;
resumespeedArray["ticker9"]=1;
resumespeedArray["ticker10"]=1;

var sizeupArray = new Array();
sizeupArray["ticker"]=1;
sizeupArray["ticker2"]=1;
sizeupArray["ticker3"]=1;
sizeupArray["ticker4"]=1;
sizeupArray["ticker5"]=1;
sizeupArray["ticker6"]=1;
sizeupArray["ticker7"]=1;
sizeupArray["ticker8"]=1;
sizeupArray["ticker9"]=1;
sizeupArray["ticker10"]=1;

var thetopArray = new Array();
thetopArray["ticker"]=0;
thetopArray["ticker2"]=0;
thetopArray["ticker3"]=0;
thetopArray["ticker4"]=0;
thetopArray["ticker5"]=0;
thetopArray["ticker6"]=0;
thetopArray["ticker7"]=0;
thetopArray["ticker8"]=0;
thetopArray["ticker9"]=0;
thetopArray["ticker10"]=0;

// Begin the ticker code

function startTicker(tickerId) {
		if (document.all) iemarquee(tickerId);
		else if (document.getElementById)
				ns6marquee(document.getElementById(tickerId));
}

function iemarquee(whichdiv){
		var iediv=eval(whichdiv)
		sheightArray[whichdiv] += 1;
		iediv.style.pixelTop=sheightArray[whichdiv];
		//iediv.innerHTML=msg 
		sizeupArray[whichdiv]=iediv.offsetHeight
		ieslide(whichdiv, iediv)
}

function ieslide(whichdiv, iediv){
		if (iediv.style.pixelTop>=sizeupArray[whichdiv]*(-1)){
				iediv.style.pixelTop-=speedArray[whichdiv]
				setTimeout("ieslide()",200)
		}
		else{
				iediv.style.pixelTop=sheightArray[whichdiv];
				ieslide(whichdiv, iediv)
		}
}

function ns6marquee(whichdiv){
		var ns6div=eval(whichdiv)
		sheightArray[whichdiv] += 1;
		ns6div.style.top=sheightArray[whichdiv] + "px";
		//ns6div.innerHTML=msg
		sizeupArray[whichdiv]=ns6div.offsetHeight
		ns6slide(whichdiv, ns6div)
}
function ns6slide(whichdiv, ns6div){
		if (parseInt(ns6div.style.top)>=sizeupArray[whichdiv]*(-1)){
				thetopArray[whichdiv] = parseInt(ns6div.style.top)-speedArray[whichdiv]
				ns6div.style.top = thetopArray[whichdiv] + "px";
				setTimeout("ns6slide()",200)
		}
		else {
				ns6div.style.top = sheightArray[whichdiv] + "px";
				ns6slide(whichdiv, ns6div)
				alert(whichdiv);
		}
}

/*
function myCallBackOnFinish(obj){
  alert("the Element's id the effect was applied to is :" + obj.element.id);
}
function myCallBackOnStart(obj){
  alert("the Element object the effect will be applied to is :" + obj.element);
}
*/
