var etiquetas = new Array();

var direccion;

var str='<script src="http://widgets.outbrain.com/OutbrainRater.js" type="text/javascript"><\/script>';

var critica = new Boolean() ;

var critica = false;

var rate;

var id;

var nro;

var vuelta=0;

var htmlenlaces ='<h2>Art&iacute;culos relacionados</h2><ul>';

var htmlrecomendadaCine;

var recomendadasCine=new Array();


// CUANDO CARGA

$(document).ready(function(){
enlazar();
recomendadaDVD();
});

// ARTICULOS RELACIONADOS






function relacionar(vuelta) {

	if ( etiquetas.length > 1 && isNaN(etiquetas[vuelta]) && (etiquetas[vuelta].indexOf("Genero-") == -1) && (etiquetas[vuelta].indexOf("Categoria-") == -1) && (etiquetas[vuelta].indexOf("Recomendada") == -1) ) {
               
		nro=vuelta;

		document.getElementById("relaciones").innerHTML="<h2>Art&iacute;culos relacionados</h2><img src='http://cablemodem.fibertel.com.ar/gvarela/ajax-loader.gif' style='position:relative; top:10px; left:240px;'/>";

		feedurl = 'http://www.thescreeners.com.ar/feeds/posts/default/-/' + etiquetas[vuelta] + '?orderby=published&max-results=100&alt=json-in-script&callback=juntar';

  		var script = document.createElement('script');

		script.setAttribute('src', feedurl);

		script.setAttribute('id', 'jsonScript');

		script.setAttribute('type', 'text/javascript');

		document.documentElement.firstChild.appendChild(script);

	}

	else {

	    if (vuelta == etiquetas.length-1) {

		   if (htmlenlaces =='<h2>Art&iacute;culos relacionados</h2><ul>') htmlenlaces += 'No existe ninguno';

 	   	   htmlenlaces += '</ul>';

		   document.getElementById("relaciones").innerHTML = htmlenlaces;

	    }

	    if (etiquetas.length>1 && etiquetas.length-1>vuelta) {

		vuelta++;

		relacionar(vuelta);

	    }

	}

}



function juntar(json) {



if (json.feed.entry.length!=1){



var label=etiquetas[nro];



htmlenlaces += '<br/>Sobre <b>' + label + '</b>';



for (var i = 0; i < json.feed.entry.length; i++) {



    var entry = json.feed.entry[i]; 



    var feedid = entry.id.$t;

    var start = feedid.indexOf('post-');

    var postid = feedid.substr(start+5);   

    var categoria;

    var titulo = entry.title.$t;



    for (var l=0; l < entry.category.length; l++) {

	if (entry.category[l].term.indexOf("Categoria-")!= -1) {

		categoria=entry.category[l].term.substring(10);

        }





    }



    for (var k = 0; k < entry.link.length; k++) {

      if (entry.link[k].rel == 'alternate') {

          break;

      }

    }



    var link=entry.link[k].href; 



    if (id!=postid) {

	htmlenlaces += '<li><a href="' + link + '">' + titulo + '</a> - ' + categoria + '</li>';

    }



}}



if (nro == etiquetas.length-1) {

if (htmlenlaces =='<h2>Art&iacute;culos relacionados</h2><ul>') htmlenlaces += 'No existe ninguno';

   htmlenlaces += '</ul>';

   document.getElementById("relaciones").innerHTML = htmlenlaces;

}



else {

   nro++;

   relacionar(nro);

}







}







// ESTRELLAS



function criticas(){


	for (var i = 0; i < etiquetas.length; i++) {

	   if (etiquetas[i]=='Categoria-Criticas') critica=true;

	   if (etiquetas[i]<=5) rate=etiquetas[i];

	   if (etiquetas[i].indexOf("Recomendada") != -1) document.getElementById('recomendada').innerHTML= "<img src='http://cablemodem.fibertel.com.ar/gvarela/check.png' height='80' width='80' style='float:right'>";
	}

}



// CAMBIAR TARGET ENLACES QUE NO SON LOCALES



function enlazar() {

if(location.href.indexOf("thescreeners.com.ar")!=-1){
    enlaces = document.getElementById('wrap').getElementsByTagName('a');

    for (var k = 0; k < enlaces.length; k++) {

      if (enlaces[k].href.indexOf('screeners') == -1 || enlaces[k].href.indexOf('javascript')!= -1) {

        enlaces[k].target="_blank";

      }

    }

}
else {
enlaces = document.getElementsByTagName('a');
    for (var k = 0; k < enlaces.length; k++) {
enlaces[k].target="_blank";
}
}
}

// BORDES REDONDEADOS



function NiftyCheck() {

  if(!document.getElementById || !document.createElement) {

    return false;

  }

  var b = navigator.userAgent.toLowerCase();

  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {

    return false;

  }

  return true;

}



function Rounded(className, sizex, sizey, sizex_b, sizey_b) {

	var bk;

	if (!NiftyCheck()) return;

	if (typeof(sizex_b) == 'undefined')

		sizex_b = sizex;

	if (typeof(sizey_b) == 'undefined')

		sizey_b = sizey;

	var v = getElements(className);

	var l = v.length;

	for (var i = 0; i < l; i++) {

		color = get_current_style(v[i],"background-color","transparent");

		bk = get_current_style(v[i].parentNode,"background-color","transparent");

		AddRounded(v[i], bk, color, sizex, sizey, true);

		AddRounded(v[i], bk, color, sizex_b, sizey_b, false);

	}

}



Math.sqr = function (x) {

  return x*x;

};



function Blend(a, b, alpha) {



  var ca = Array(

    parseInt('0x' + a.substring(1, 3)), 

    parseInt('0x' + a.substring(3, 5)), 

    parseInt('0x' + a.substring(5, 7))

  );

  var cb = Array(

    parseInt('0x' + b.substring(1, 3)), 

    parseInt('0x' + b.substring(3, 5)), 

    parseInt('0x' + b.substring(5, 7))

  );

  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)

             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)

             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);



  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)

             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)

             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);

}



function AddRounded(el, bk, color, sizex, sizey, top) {

  if (!sizex && !sizey)

	return;

  var i, j;

  var d = document.createElement("div");

  d.style.backgroundColor = bk;

  var lastarc = 0;

  for (i = 1; i <= sizey; i++) {

    var coverage, arc2, arc3;

    // Find intersection of arc with bottom of pixel row

    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;

    // Calculate how many pixels are bg, fg and blended.

    var n_bg = sizex - Math.ceil(arc);

    var n_fg = Math.floor(lastarc);

    var n_aa = sizex - n_bg - n_fg;

    // Create pixel row wrapper

    var x = document.createElement("div");

    var y = d;

    x.style.margin = "0px " + n_bg + "px";

	x.style.height='1px';

	x.style.overflow='hidden';

    // Make a wrapper per anti-aliased pixel (at least one)

    for (j = 1; j <= n_aa; j++) {

      // Calculate coverage per pixel

      // (approximates circle by a line within the pixel)

      if (j == 1) {

        if (j == n_aa) {

          // Single pixel

          coverage = ((arc + lastarc) * .5) - n_fg;

        }

        else {

          // First in a run

          arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;

          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;

          // Coverage is incorrect. Why?

          coverage = 0;

        }

      }

      else if (j == n_aa) {

        // Last in a run

        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;

        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;

      }

      else {

        // Middle of a run

        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;

        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;

        coverage = ((arc2 + arc3) * .5) - (sizey - i);

      }

      

      x.style.backgroundColor = Blend(bk, color, coverage);

	  if (top)

	      y.appendChild(x);

      else

	      y.insertBefore(x, y.firstChild);

      y = x;

      var x = document.createElement("div");

		x.style.height='1px';

		x.style.overflow='hidden';

      x.style.margin = "0px 1px";

    }

    x.style.backgroundColor = color;

    if (top)

	    y.appendChild(x);

    else

		y.insertBefore(x, y.firstChild);

    lastarc = arc;

  }

  if (top)

	  el.insertBefore(d, el.firstChild);

  else

	  el.appendChild(d);

}



function getElements(className) {

	var elements = [];

	var el = document.getElementsByTagName('DIV');  

	var regexp=new RegExp("\\b"+className+"\\b");

	for (var i = 0; i < el.length; i++) 

	{

		if (regexp.test(el[i].className)) 

			elements.push(el[i]);

	}

	return elements;

}



function get_current_style(element,property,not_accepted)

{

  var ee,i,val,apr;

  try

  {

    var cs=document.defaultView.getComputedStyle(element,'');

    val=cs.getPropertyValue(property);

  }

  catch(ee)

  {

    if(element.currentStyle)

  	{

	    apr=property.split("-");

	    for(i=1;i<apr.length;i++) apr[i]=apr[i].toUpperCase();

	    apr=apr.join("");

	    val=element.currentStyle.getAttribute(apr);

   }

  }

  if((val.indexOf("rgba") > -1 || val==not_accepted) && element.parentNode)

  {

	 if(element.parentNode != document) 

		 val=get_current_style(element.parentNode,property,not_accepted);

	 else

		 val = '#FFFFFF';

  }

  if (val.indexOf("rgb") > -1 && val.indexOf("rgba") == -1)

	  val = rgb2hex(val);

  if (val.length == 4)

	  val = '#'+val.substring(1,1)+val.substring(1,1)+val.substring(2,1)+val.substring(2,1)+val.substring(3,1)+val.substring(3,1);

  return val;

}



function rgb2hex(value)

{

	var x = 255;

	var hex = '';

	var i;

	var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;

	var array=regexp.exec(value);

	for(i=1;i<4;i++) hex += ('0'+parseInt(array[i]).toString(16)).slice(-2);

	return '#'+hex;

}



// FINAL BORDES REDONDEADOS



// RANDOM



function aleatorioentre(minVal,maxVal,floatVal)

{

  var randVal = minVal+(Math.random()*(maxVal-minVal));

  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);

}



// FINAL RANDOM



// RECOMENDADA



function recomendadaDVD() {

$.getJSON("http://www.thescreeners.com.ar/feeds/posts/default/-/Recomendada?orderby=published&max-results=100&alt=json-in-script&callback=?", function(json) {

htmlrecomendadaDVD = '';

$.each(json.feed.entry, function(i,entry){

    recomendadasDVD=new Array();


    for (var k = 0; k < entry.link.length; k++) {

      if (entry.link[k].rel == 'enclosure') {

          break;

      }

    }

	if (k!=entry.link.length){

	   recomendadasDVD[2] = entry.link[k].href;

	}

	else {

	recomendadasDVD[2]='http://cablemodem.fibertel.com.ar/gvarela/spacer.jpg';

	}

    

    for (var k = 0; k < entry.link.length; k++) {

      if (entry.link[k].rel == 'alternate') {

          break;

      }

    }

   

   recomendadasDVD[1] = entry.link[k].href;

   recomendadasDVD[0] = entry.title.$t;

   recomendadasDVD[3] = entry.author[0].name.$t;



   for (var k = 0; k < entry.category.length; k++) {

	if (entry.category[k].term <= 5) {

		recomendadasDVD[4] = entry.category[k].term;

		break;

	}

   }



htmlrecomendadaDVD += "<li><div onclick='location.href=\"" + recomendadasDVD[1] +"\";' style='cursor:pointer; width:190px;'>";

htmlrecomendadaDVD += "<center><h3>" + recomendadasDVD[0] + "</h3></center>";

htmlrecomendadaDVD += "<center><img height='134' src='" + recomendadasDVD[2] + "' width='95'/></center>";

htmlrecomendadaDVD += "<br/><center><img src='http://cablemodem.fibertel.com.ar/gvarela/" + recomendadasDVD[4] + ".png'/></center><p style='font-size:x-small; text-align:right;'>Cr&iacute;tica por " + recomendadasDVD[3] + "</p>";

htmlrecomendadaDVD += "</div></li>";

});

document.getElementById("loader-recDVD").innerHTML = "";
$('ul#recDVD').append(htmlrecomendadaDVD);
document.getElementById("recDVD").style.height="270px";
$('#recDVD').inerfade({
                        speed: 'slow',
                        timeout: 4000,
                        type: 'sequence',
                        containerheight: 	'280px',
                        slide_timer_on: 	'yes',
                        slide_ui_parent: 	'recDVD',
                       	pause_button_id: 	'',
                       	slide_nav_id:		''
                    	});
});
}



// FINAL RECOMENDADA