// JavaScript Document

var player = null;
var inicio = true;

$(document).ready(function() {
	$("#flvVideo").css({
	   width: $(window).width() * 0.80,
	   height: $(window).height() * 0.80
	});
});

$(document).ready(function() {
	presentacion=getCookie('presentacion');
	if (presentacion=="") {
		$("#flvVideo").css({
		   position:"absolute",
		   left: ($(window).width() - $("#flvVideo").outerWidth())/2,
		   top: ($(window).height() - $("#flvVideo").outerHeight())/2,
		   display:"block"
		});
	
		var so = new SWFObject("/2008/movies/player.swf","mpl",$(window).width() * 0.80,$(window).height() * 0.80 - 15,"9");
		//var so = new SWFObject("/2008/movies/player.swf","mpl",720,480,"9");
		so.addParam("allowfullscreen","true");
		so.addParam("allowscriptaccess","always");
		so.addParam("wmode","opaque");
		so.addVariable("file","/2008/movies/video.flv");
		so.addVariable("title","Lentax. Video Institucional");
		so.addVariable("autostart","true");
		so.write("Video");
		setCookie('presentacion',true,730);
	}

})

function cerrarVentana() {
	$("#mpl").stop();
	$("#flvVideo").css({
	   display:"none"
	});
}


function playerReady(thePlayer) {
	//player = $("#"+thePlayer.id);
	addListeners(thePlayer);
}


function addListeners(thePlayer) {
	var player = document.getElementById(thePlayer.id);
	if (player) { 
		player.addModelListener("STATE", "reproduccionCompleta");
	} else {
		setTimeout("addListeners();",100);
	}
}


function reproduccionCompleta(obj)	{
	currentState = obj.newstate; 
	previousState = obj.oldstate; 

	if ((currentState == "IDLE" || currentState == "COMPLETED") && (previousState == "PLAYING")) {
		$("#flvVideo").css({ display:"none" });
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function verVideo() {

		$("#flvVideo").css({
		width: $(window).width() * 0.80,
		height: $(window).height() * 0.80,
  	    position:"absolute",
		left: ($(window).width() - $("#flvVideo").outerWidth())/2,
		top: ($(window).height() - $("#flvVideo").outerHeight())/2,
		display:"block"
		});
	
		var so = new SWFObject("/2008/movies/player.swf","mpl",$(window).width() * 0.80,$(window).height() * 0.80 - 15,"9");
		//var so = new SWFObject("/2008/movies/player.swf","mpl",720,480,"9");
		so.addParam("allowfullscreen","true");
		so.addParam("allowscriptaccess","always");
		so.addParam("wmode","opaque");
		so.addVariable("file","/2008/movies/video.flv");
		so.addVariable("title","Lentax. Video Institucional");
		so.addVariable("autostart","true");
		so.write("Video");
		location = "#top";
}
