var page_width = 0;
var activePage = 0;

function sma_showMagazine()
	{
	//$('sma_magazine').style.display = 'block';
	Effect.BlindDown('sma_magazine');
	}

function sma_hideMagazine()
	{
	Effect.BlindUp('sma_magazine');
	}

function sma_loadMagazine(vIMG)
	{
	// Carreguem el Magazine
	$('sma_magazine').style.display = 'block';
	var oWidth = $('sma_magazine').offsetWidth;
	page_width = ((oWidth-6)/2);
	$('sma_magazine').style.display = 'none';
	$('sma_magazine').style.backgroundColor = "#000";

	//[ Creating DOM ]//
	for(var i=(vIMG.length-1);i>=0;i--)
		{
		var obj = document.createElement("div");
		obj.style.position = "absolute";
		obj.style.width = page_width+"px";
		obj.style.height = "590px";
		obj.style.backgroundColor = "#FFF";
		obj.style.top = "2px";
		obj.style.overflow = 'hidden';
		obj.style.border = "1px solid black";
		obj.style.cursor = "pointer";
		
		if((i%2) == 0)
			{// Esquerra
			obj.id = (i/2)+'_l';
			obj.style.left = "2px";
			}
		else
			{// Dreta
			obj.id = (((i/2)+0.5)-1)+'_r';
			obj.style.left = (page_width+2)+"px";
			}

		//obj.innerHTML = "<img src='"+vIMG[i]+"' width='"+page_width+"' />";
		obj.style.backgroundImage = "url('http://shared.smawebsite.net/aspectratio.php?p="+vIMG[i]+"&w="+page_width+"&h=590')";
		$('sma_magazine').appendChild(obj);
		}


	var ampli = document.createElement("div");
	ampli.style.position = "absolute";
	ampli.style.top = "0px";
	ampli.style.left = "0px";
	ampli.style.width = "35px";
	ampli.style.height = "100%";
	$('sma_magazine').appendChild(ampli);
		
	var obj = document.createElement("div");
	obj.id = 'sma_ampliar_l';
	obj.style.position = 'absolute';
	obj.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_l.png')";
	obj.style.width = "50px";
	obj.style.height = "50px";
	obj.style.top = "546px";
	obj.style.left = "-50px";
	obj.style.cursor = "pointer";
	obj.onclick = function()
		{
		if($('sma_bigImg').style.display == 'none')
			{
			sma_loadBigImg($(activePage+"_l").style.backgroundImage);
			this.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_reducir_l.png')";
			$('sma_ampliar_r').style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_reducir_r.png')";
			}
		else
			{
			sma_unloadBigImg();
			this.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_l.png')";
			$('sma_ampliar_r').style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_r.png')";
			}
		}
	ampli.appendChild(obj);
		
	var obj = document.createElement("div");
	obj.id = 'sma_back';
	obj.style.position = 'absolute';
	obj.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_previous.png')";
	obj.style.width = "50px";
	obj.style.height = "50px";
	obj.style.top = "490px";
	obj.style.left = "-50px";
	obj.style.cursor = "pointer";
	obj.onclick = function()
		{
		if($('sma_bigImg').style.display == 'none')
			{
			sma_goBack(activePage);
			}
		}
	ampli.appendChild(obj);

	var ampli = document.createElement("div");
	ampli.style.position = "absolute";
	ampli.style.top = "0px";
	ampli.style.left = (oWidth)+"px";
	ampli.style.width = "50px";
	ampli.style.height = "100%";
	$('sma_magazine').appendChild(ampli);
		
	var obj = document.createElement("div");
	obj.id = 'sma_ampliar_r';
	obj.style.position = 'absolute';
	obj.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_r.png')";
	obj.style.width = "50px";
	obj.style.height = "50px";
	obj.style.top = "546px";
	obj.style.left = "0px";
	obj.style.cursor = "pointer";
	obj.onclick = function()
		{
		if($('sma_bigImg').style.display == 'none')
			{
			sma_loadBigImg($(activePage+"_r").style.backgroundImage);
			this.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_reducir_r.png')";
			$('sma_ampliar_l').style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_reducir_l.png')";
			}
		else
			{
			sma_unloadBigImg();
			this.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_r.png')";
			$('sma_ampliar_l').style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_ampliar_l.png')";
			}
		}
	ampli.appendChild(obj);

	var obj = document.createElement("div");
	obj.id = 'sma_next';
	obj.style.position = 'absolute';
	obj.style.backgroundImage = "url('http://shared.smawebsite.net/img/sma_next.png')";
	obj.style.width = "50px";
	obj.style.height = "50px";
	obj.style.top = "490px";
	obj.style.left = "0px";
	obj.style.cursor = "pointer";
	obj.onclick = function()
		{
		if($('sma_bigImg').style.display == 'none')
			{
			sma_goNext(activePage);
			}
		}
	ampli.appendChild(obj);

	var obj = document.createElement("div");
	obj.id = 'close';
	obj.style.position = 'absolute';
	obj.style.backgroundImage = "url('http://shared.smawebsite.net/img/close.png')";
	obj.style.width = "50px";
	obj.style.height = "50px";
	obj.style.top = "0px";
	obj.style.left = "0px";
	obj.style.cursor = "pointer";
	obj.onclick = function()
		{
		sma_hideMagazine()
		}
	ampli.appendChild(obj);

	var bigImg = document.createElement("div");
	bigImg.id = 'sma_bigImg';
	bigImg.style.position = "absolute";
	bigImg.style.left = "2px";
	bigImg.style.top = "2px";
	bigImg.style.width = oWidth-6+"px";
	bigImg.style.height = "590px";
	bigImg.style.display = 'none';
	bigImg.style.backgroundColor = '#000';
	bigImg.style.border = '1px solid #000';
	bigImg.style.overflow = 'auto';
	$('sma_magazine').appendChild(bigImg);

	}

function sma_goNext(id)
	{
	if($((id+1)+"_l"))
		{
		activePage++;
		sma_right2Right(id);
		setTimeout("sma_left2Left("+id+")","800");
		}
	}
function sma_goBack(id)
	{
	if($((id-1)+"_l"))
		{
		activePage--;
		sma_left2Right((id-1));
		setTimeout("sma_right2Left("+(id-1)+")","800");
		}
	}

function sma_right2Right(id)
	{
	new Effect.Morph(id+'_r', {style: 'background:#AAA; width:0px;'}, {duration: 0.1});
	}

function sma_right2Left(id)
	{
	new Effect.Morph(id+'_r', {style: 'background:#FFF; width:'+page_width+'px;'}, {duration: 0.8});
	}

function sma_left2Left(id)
	{
	new Effect.Morph(id+'_l', {style: 'background:#AAA; width:0px;'}, {duration: 0.8});
	}

function sma_left2Right(id)
	{
	new Effect.Morph(id+'_l', {style: 'background:#FFF; width:'+page_width+'px;'}, {duration: 0.8});
	}

function sma_loadBigImg(html)
	{
	var aux = html.replace("url(http://shared.smawebsite.net/aspectratio.php?p=", "").replace("&w="+page_width+"&h=590)", "");
	$('sma_bigImg').innerHTML = "<img src='"+aux+"' width='"+(page_width*2-20)+"'>";
	Effect.Appear('sma_bigImg');
	}

function sma_unloadBigImg()
	{
	$('sma_bigImg').scrollTop = 0;
	$('sma_bigImg').style.display = 'none';
	}