// JavaScript Document
var contentheight;
var contentwidth;
var crossobj;
var moveupvar;
var movedownvar;
var moverightvar;
var moveleftvar;
var remainPix;
var currentSpeed;
var speedCoeficient;
var movebiopicvar;
var animating=false;
var speed=2;
var flashObj;
var oFlyer;


appendEventListener(window, 'load', OnLoad);

function OnLoad()
{
	if(document.location.href.search(/index.html/) != -1)
	{
		preloadImages()
	}
	else if(document.location.href.search(/miMusica.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
			correctPNG();
			
		document.getElementById('mainContainer').style.visibility = 'visible';
		
		appendEventListener(document.getElementById('arrowUp'), 'mouseover', moveup);
		appendEventListener(document.getElementById('arrowUp'), 'mouseout', function(){clearTimeout(moveupvar)});
		appendEventListener(document.getElementById('arrowDown'), 'mouseover', movedown);
		appendEventListener(document.getElementById('arrowDown'), 'mouseout', function(){clearTimeout(movedownvar)});
		appendEventListener(document.getElementById('imgStop'), 'click', stopSong);
		appendEventListener(document.getElementById('imgPlay'), 'click', playSong);
																									 
		crossobj=document.getElementById("content");
		contentheight=crossobj.offsetHeight;
		
		if (navigator.appName.indexOf("Microsoft") != -1) 
			flashObj = document.getElementById('playpause1');
		else 
			flashObj = document.getElementsByTagName('embed')[1];
	}
	else if(document.location.href.search(/paraVos.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
			correctPNG();
			
		document.getElementById('mainContainer').style.visibility = 'visible';
		
		appendEventListener(document.getElementById('arrowUp'), 'mouseover', moveup);
		appendEventListener(document.getElementById('arrowUp'), 'mouseout', function(){clearTimeout(moveupvar)});
		appendEventListener(document.getElementById('arrowDown'), 'mouseover', movedown);
		appendEventListener(document.getElementById('arrowDown'), 'mouseout', function(){clearTimeout(movedownvar)});
																									 
		crossobj=document.getElementById("content");
		contentheight=crossobj.offsetHeight;
	}
	else if(document.location.href.search(/fans.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
			correctPNG();
			
		document.getElementById('mainContainer').style.visibility = 'visible';
		
		appendEventListener(document.getElementById('arrowUp'), 'mouseover', moveupFClub);
		appendEventListener(document.getElementById('arrowUp'), 'mouseout', function(){clearTimeout(moveupvar); window.status='';});
		appendEventListener(document.getElementById('arrowDown'), 'mouseover', movedownFClub);
		appendEventListener(document.getElementById('arrowDown'), 'mouseout', function(){clearTimeout(movedownvar); window.status='';});
		
		crossobj=document.getElementById("content");
		contentheight=crossobj.offsetHeight;
	}
	else if(document.location.href.search(/qiro.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
			correctPNG();
			
		document.getElementById('mainContainer').style.visibility = 'visible';
		
		appendEventListener(document.getElementById('next'), 'click', nextClick);
		appendEventListener(document.getElementById('previous'), 'click', previousClick);		
		appendEventListener(document.getElementById('windowClose'), 'click', closeWindow);
		appendEventListener(document.getElementById('winButImg'), 'click', showWindow);
		
		crossobj=document.getElementById("content");
		contentwidth=crossobj.offsetWidth;
	}
	else if(document.location.href.search(/contacto.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
		{
			correctPNG();
		}
					
		document.getElementById('mainContainer').style.visibility = 'visible';
		
		ShowMsgSent();
	}
	else if(document.location.href.search(/novedades.html/) != -1)
	{
		if(navigator.userAgent.indexOf('MSIE 6') != -1)
		{
			correctPNG();
		}
					
		document.getElementById('mainContainer').style.visibility = 'visible';
	}
}

function appendEventListener(object, sEvent, handler) 
{
	if (object.addEventListener)	
		object.addEventListener(sEvent,handler,false);
	else if (object.attachEvent) 
		object.attachEvent("on"+sEvent, handler);
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='Image');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function movedown()
{
	if (parseInt(crossobj.style.top)>=(contentheight*(-1)+315))
		crossobj.style.top=parseInt(crossobj.style.top)-speed+"px";
		
	movedownvar=setTimeout("movedown()",20);
}

function moveup()
{
	if (parseInt(crossobj.style.top)<=0)
		crossobj.style.top=parseInt(crossobj.style.top)+speed+"px";
		
	moveupvar=setTimeout("moveup()",20);
}

function movedownFClub()
{window.status=crossobj.style.top + ' ' + contentheight;
	if (parseInt(crossobj.style.top)>=(contentheight*(-1)+370))
		crossobj.style.top=parseInt(crossobj.style.top)-speed+"px";
		
	movedownvar=setTimeout("movedownFClub()",20);
}

function moveupFClub()
{window.status=crossobj.style.top;
	if (parseInt(crossobj.style.top)<=0)
		crossobj.style.top=parseInt(crossobj.style.top)+speed+"px";
		
	moveupvar=setTimeout("moveupFClub()",20);
}

function nextClick()
{
	if (!(parseInt(crossobj.style.left)-375<-1085) && !animating)
	{
		remainPix = 375;
		speedCoeficient = 1;
		movebiopicvar = setInterval("animateText()", 20)
		animating = true;
	}
}

function animateText()
{
	if(remainPix > 30)	
	{
		currentSpeed = 30;
		crossobj.style.left=parseInt(crossobj.style.left)-currentSpeed*speedCoeficient+"px";
	}
	else if (remainPix > 10)
	{		
		currentSpeed = 5;
		crossobj.style.left=parseInt(crossobj.style.left)-currentSpeed*speedCoeficient+"px";	
	}
	else if (remainPix > 3)
	{
		
		currentSpeed = 2;
		crossobj.style.left=parseInt(crossobj.style.left)-currentSpeed*speedCoeficient+"px";	
	}
	else if (remainPix > 1)
	{
		
		currentSpeed = 1;
		crossobj.style.left=parseInt(crossobj.style.left)-currentSpeed*speedCoeficient+"px";	
	}
	
	remainPix -= currentSpeed;
	
	if(remainPix==0)
	{
		clearInterval(movebiopicvar);	
		animating = false;
	}
}

/*function previousClick()
{
	if (!(parseInt(crossobj.style.left)+375>0))
		crossobj.style.left=parseInt(crossobj.style.left)+375+"px";
	else
		crossobj.style.left='0px';
}*/

function previousClick()
{
	if (!(parseInt(crossobj.style.left)+375>1) && !animating)
	{
		remainPix = 375;
		speedCoeficient = -1;
		movebiopicvar = setInterval("animateText()", 20)
		animating = true;
	}
}

		
function ShowMsgSent()
{
	if(document.location.search.length >0)
	{
		var sent = false;
		sent = document.location.search.substring(document.location.search.indexOf('sent=')+5);

		if(sent == 1)
			alert('El mensaje se envio correctamente.');
		else if(sent == 0)
			alert('Error al enviar el mensaje.\r\nEnvíe su mensaje directamente a info@qiroweb.com.\r\nDisculpe las molestias.');
	}
}
		
function playSong()
{
	flashObj.playSong('incomp.mp3');
}

function stopSong()
{
	flashObj.stopIt();
}

function closeWindow()
{
	document.getElementById('downWindow').style.visibility = 'hidden';	
}

function showWindow()
{
	document.getElementById('downWindow').style.visibility = 'visible';	
}

function preloadImages()
{	
	simplePreload('logochico.png', 'fondo2.png', 'biohead.png', 'qiro2.png', 'textobio.png', 'arrowlt.png', 'arrowrt.png', 'botonmp3.png', 'closeWindow.png', 'downloadArrow.png', 'fondo2_incom.png', 'incomprendidohead.png', 'letra.png', 'arrowup.png', 'arrowdn.png', 'stop.png', 'play.png', 'fondo2.png', 'qiro3.png', 'descargashead.png', 'wallpaper1.gif', 'wallpaper2.gif', 'wallpaper3.gif', 'wallpaper4.gif', 'wallpaper5.gif', 'wallpaper6.gif', 'fondonovedades.png', 'qiro6.png', 'fondocontacto.png', 'qiro4.png', 'btnSubmit.png', 'fondo3.png', 'fansHead.png', 'mapa.png', 'fondoFans1.png', 'fondoFans2.png', 'fondoFans3.png', 'fondoFans4.png');
}


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 = 'images/' + args[i];

  }
}

var windowState = (function()
{
	var readScroll = {scrollLeft:0,scrollTop:0};
	var readSize = {clientWidth:0,clientHeight:0};
	var readScrollX = 'scrollLeft';
	var readScrollY = 'scrollTop';
	var readWidth = 'clientWidth';
	var readHeight = 'clientHeight';
	
	function otherWindowTest(obj)
	{
		if((document.compatMode)&&(document.compatMode == 'CSS1Compat')&&(document.documentElement))
		{
			return document.documentElement;
		}
		else if(document.body)
		{
			return document.body;
		}
		else
		{
			return obj;
		}
	};
	
	if((typeof this.innerHeight == 'number')&&(typeof this.innerWidth == 'number'))
	{
		readSize = this;
		readWidth = 'innerWidth';
		readHeight = 'innerHeight';
	}
	else
	{
		readSize = otherWindowTest(readSize);
	}
	
	if((typeof this.pageYOffset == 'number')&&(typeof this.pageXOffset == 'number'))
	{
		readScroll = this;
		readScrollY = 'pageYOffset';
		readScrollX = 'pageXOffset';
	}
	else
	{
		readScroll = otherWindowTest(readScroll);
	}
	
	return{
		getScrollX:function()
		{
			return (readScroll[readScrollX]||0);
		},
		getScrollY:function()
		{
			return (readScroll[readScrollY]||0);
		},
		getWidth:function()
		{
			return (readSize[readWidth]||0);
		},
		getHeight:function()
		{
			return (readSize[readHeight]||0);
		}
	};
})();

function popupFlyer(URL, width, height)
{
	window.open(URL, 'popFlyer', 'location=no,status=no,scrollbars=no,menubar=no,toolbar=no,directories=no,width='+width+',height='+height);
}

function showFlyer(URL, width, height)
{
	var iWidth = windowState.getWidth();
	var iLeft = (iWidth - width) / 2;
	
	var sLayer = '<div id="flyer" width="' + width + '" height="' + height + '" style="position: absolute; top: 0px; left: ' + iLeft + 'px">';
	sLayer += '<iframe id="ifrFlyer" name="ifrFlyer" src="' + URL + '" frameborder="0" scrolling="no" allowtransparency="true" width="' + width + '" height="' + height + '"></iframe></div>';
	document.write(sLayer);
	
	oFlyer = document.getElementById('flyer');
}

function closeFlyer()
{
	var oFlyer = top.oFlyer;
	var oParent = oFlyer.parentNode;
	oParent.removeChild(oFlyer);
}