// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",	dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",	dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,	true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function writeDiv(idDiv,iLeft,iTop,iAncho,iAlto)
{
	document.write("<DIV id='"+idDiv+"_div' style='z-index:1;float:left;vertical-align:top;padding-top:0px;background-position:top;position:absolute;width:1px;height:1px;left:"+iLeft+"px;top:"+iTop+"px;'>");

	//document.write('<div id="'+idDiv+'_bar" class="moveBar" onmousedown="dragStart(event, \''+idDiv+'_div\');" onmousemove="iPosLeftIni = document.getElementById(\''+idDiv+'_div\').style.left;" style=\'width:'+iAncho+'px; height: 15px;background-color: #999999;\'><img src="/modulos/MEDIA/imgs/cross.gif" alt="Mover video"></div>');
	
	document.write("<div id='"+idDiv+"' style='float:left;background-position:top;padding-top:0px;vertical-align:top;left:0px;top:0px;width:"+iAncho+"px;height:"+iAlto+"px'> </div>"); // medida 1280
	document.write("</DIV>");
}

function setPosition(idDiv,iLeft,iTop)
{
	document.getElementById(idDiv).style.left = iLeft;
	document.getElementById(idDiv).style.top = iTop;
}

function hideShowBar(idDiv,iFlag)
{
	if(iFlag==0) document.getElementById(idDiv+"_bar").style.visibility = "visible";
	else if(iFlag==1) document.getElementById(idDiv+"_bar").style.visibility = "hidden";
}

function calculaPercent(iPercent,iValue)
{
	return iValue = parseInt(iValue + ((iValue * iPercent) / 100));
}

function increaseDecrease(iPercent,idDiv,idSwf)
{
	//alert(iPercent+" - "+idDiv+" - "+idSwf);
	var iWini = parseInt(document.getElementById(idDiv).style.width);
	var iHini = parseInt(document.getElementById(idDiv).style.height);
	var iWlimit = calculaPercent(iPercent,iWini);
	var iHlimit = calculaPercent(iPercent,iHini);
	var iWinc = calculaPercent(iPercent,parseInt(document.getElementById(idSwf).getAttribute("width")));
	var iHinc = calculaPercent(iPercent,parseInt(document.getElementById(idSwf).getAttribute("height")));
	
	if(iWlimit >= iWinc){ 
		iPosLeftIni = document.getElementById(idDiv+"_div").style.left;
		document.getElementById(idSwf).setAttribute("width",iWinc);
		document.getElementById(idDiv).style.left = strVideoPosILeft;//0;
		//document.getElementById(idDiv+"_div").style.left = parseInt(document.getElementById(idDiv+"_div").style.left) - parseInt(((iWini * iPercent) / 100) / 2);
		//document.getElementById(idDiv+"_bar").style.width = iWinc;
	}
	else{ 
		document.getElementById(idSwf).setAttribute("width",iWini);
		document.getElementById(idDiv).style.left = 0;
		document.getElementById(idDiv+"_div").style.left = strVideoPosILeft;//iPosLeftIni;
		//document.getElementById(idDiv+"_bar").style.width = iWini;
	}

	if(iHlimit >= iHinc) document.getElementById(idSwf).setAttribute("height",iHinc);
	else document.getElementById(idSwf).setAttribute("height",iHini);
}

function setMediaFile(idObjSWF,args,idDiv)
{
	//args+="&strAutoPlay=SI";

	//alert("idSwf: "+idSwf+" - idDiv: "+idDiv+" - fo:"+fo);
	idObjSWF.addParam('FlashVars',args);
	idObjSWF.addParam('wmode','transparent');
	idObjSWF.write(idDiv);
}

function getY_byRes(iResolucion,movY)
{
	var y;

	return y = (movY*iResolucion)/1280;
}

function setScroll(movY)
{
	var iResolucion=jsCheckMonitor();

	movY = getY_byRes(iResolucion,movY);

	scrollTo(0,movY);
}

function setFolder(iResolucion)
{
	var strFolder;
	iResolucion = parseInt(iResolucion);
	
	if(iResolucion <= 800) strFolder = "800";
	else if(iResolucion <= 1024 || iResolucion < 1260 ) strFolder = "1000";
		 else if(iResolucion >= 1260) strFolder = "1260";
			  else strFolder = "1000";

	return strFolder;
}

function SetDimensionBox(iResolucion)
{
	var constWidth = 1540; // proporcion ancho
	var constHeight = 1980; // proporcion alto

	iWidth = screen.width - 25; // se resta scrollbar
	iHeight = parseInt((constHeight * iWidth) / constWidth); // se calcula alto proporcional segun ancho
	/*
	iResolucion = parseInt(iResolucion);
	if(iResolucion <= 800){
		iWidth = 775;
		iHeight = 997;	
	}	
	else if(iResolucion <= 1024 || iResolucion < 1260 ){ 
			iWidth = 1000;
			iHeight = 1286;
		 }
		 else if(iResolucion >= 1260 && iResolucion < 1600){
				iWidth = 1255;
				iHeight = 1614;
		 }
		 else if(iResolucion >= 1600){
				iWidth = 1550;
				iHeight = 1980;
			  }	
			  else{
				iWidth = 1000;
				iHeight = 1286;
			  }
	*/
	/*switch(iResolucion){
		case "800": 
			iWidth = 775;
			iHeight = 997;
			strFolder = iResolucion;
			break;
		case "1024": 
			iWidth = 1000;
			iHeight = 1286;
			strFolder = 1000;
			break;
		case "1260": 
			iWidth = 1255;
			iHeight = 1614;
			strFolder = iResolucion;
			break;
		default:
			iWidth = 1255;
			iHeight = 1614;
			strFolder = iResolucion;
			break;
	}*/
}

function calculaPercentPVI(iPercent,iValue)
{
	return iValue = parseInt((iValue * iPercent) / 100);
}

function increaseDecreasePVI(iPercent,idDiv,idSwf,zoom)
{
	//alert(iPercent+" - "+idDiv+" - "+idSwf);
	var iWcurr = parseInt(document.getElementById(idSwf).getAttribute("width"));
	var iHcurr = parseInt(document.getElementById(idSwf).getAttribute("height"));
	var iWinc = calculaPercentPVI(iPercent,iWcurr);
	var iHinc = calculaPercentPVI(iPercent,iHcurr);
	var iWini = iWidth;
	var iHini = iHeight;

	if(zoom == '+'){
		document.getElementById(idSwf).setAttribute("width",iWcurr+iWinc);
		document.getElementById(idSwf).setAttribute("height",iHcurr+iHinc);
	}
	else{
		if(zoom == '-' && iWcurr > iWini){
			document.getElementById(idSwf).setAttribute("width",iWcurr-iWinc);
			document.getElementById(idSwf).setAttribute("height",iHcurr-iHinc);
		}
	}
}
