/* Definición Twitter Search */

var player;

var seek = [1,195,420,660,880,1140,1390,1580,1834,2060,2378,2650,2820,3000,3210,3515,3713,4035,4245,4547,4770];
var rptcnt = 0;

var twSearchConfig = {
 version: 2,
 type: 'search',
 search: '#gepe',
 interval: 6000,
 title: '',
 subject: '',
 width: 866,
 height: 400,
 theme: {
   shell: {
     background: '#ffffff',
     color: '#ffffff'
   },
   tweets: {
     background: '#ffffff',
     color: '#444444',
     links: '#1985b5'
   }
 },
 features: {
   scrollbar: true,
   loop: false,
   live: true,
   hashtags: true,
   timestamp: true,
   avatars: true,
   toptweets: true,
   behavior: 'all'
 }
};
	
var EmbedCode = "&lt;object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='720' height='405' id='player' name='player'&gt;&lt;param name='movie' value='http://play.mediastreamonline.net/swf/player1.0.swf'&gt;&lt;param name='allowfullscreen' value='true'&gt;&lt;param name='allowscriptaccess' value='always'&gt;&lt;param name='wmode' value='transparent'&gt;&lt;param name='flashvars' value='config=http://play.mediastreamonline.net/events.xml?stream=gepe2010'&gt;&lt;embed type='application/x-shockwave-flash' id='player' name='player' src='http://play.mediastreamonline.net/swf/player1.0.swf' width='720'height='405' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' flashvars='config=http://play.mediastreamonline.net/events.xml?stream=gepe2010'/&gt;&lt;/object&gt;";


function timeTracker(sec)
{
	if(rptcnt == 0)
	{
		var pos = Math.round(sec.position);
		var f; // = $.inArray(pos,seek);
		
		
		$(seek).each(function(a,b,c){
			if( pos >= b && pos < seek[a+1])
			{
				f=a;
				return false;	
			}
			
			})
		if(f!=-1)
		{
			if(!$("#videonav").find("li").eq(f).hasClass("playing"))
			$("#videonav").find("li").removeClass("playing").eq(f).addClass("playing");
		}
	}
	rptcnt = rptcnt + 1;
	if(rptcnt == 10) rptcnt = 0;
	
}

function playerReady(object) {
  
  player = document.getElementById(object.id);
  player.addModelListener("time","timeTracker");
};

function hookPlayer()
{
	var so = new SWFObject('js/player.swf','ply','656','400','9','#000000');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','transparent');
	so.addVariable('autostart','true'); 
	so.addVariable('file','gepe-audiovision-gam.f4v');
	so.addVariable('streamer','rtmp://fms01.mediastream.cl:80/gepe');
	so.addVariable('controlbar','over');
	so.addVariable('backcolor','000000');
  so.addVariable('frontcolor','6efbb5');
  so.addVariable('playerReady','playerReady');	
	so.write('video');
}

function goToSec(sec)
{
	if(player != null )
	{
		if(player.getConfig().state != "PLAYING") player.sendEvent("PLAY",true)
		player.sendEvent("SEEK",sec);
	}
}




$(document).ready(function(){
	
	/* Comment Boxes */
	
	$(".comment_twitter").click(function(){
		if ( !$("#twitterbox").is(":visible") )
		{
			if($("#fbbox").is(":visible")) $("#fbbox").fadeOut(400,function(){ $("#twitterbox").fadeIn(400,function(){ if($("#tbox").find("iframe").size() == 0) { twttr.anywhere(function (T) { T("#tbox").tweetBox({defaultContent:"#gepe ",label:"",width:850,height:50});  });	}	});  });
			if($("#embedbox").is(":visible")) $("#embedbox").fadeOut(400,function(){ $("#twitterbox").fadeIn(400,function(){ if($("#tbox").find("iframe").size() == 0) { twttr.anywhere(function (T) { T("#tbox").tweetBox({defaultContent:"#gepe ",label:"",width:850,height:50});  });	}	});  });
			$(".comment_twitter,.comment_facebook,.embed_video").removeClass("active");
			$(".comment_twitter").addClass("active");
		}
	});
	
	$(".comment_facebook").click(function(){
		if ( !$("#fbbox").is(":visible") )
		{
			if($("#twitterbox").is(":visible")) $("#twitterbox").fadeOut(400,function(){ $("#fbbox").fadeIn(400); });
			if($("#embedbox").is(":visible")) $("#embedbox").fadeOut(400,function(){ $("#fbbox").fadeIn(400); });
			$(".comment_twitter,.comment_facebook,.embed_video").removeClass("active");
			$(".comment_facebook").addClass("active");
		}
	});
	
	$(".embed_video").click(function(){
		if ( !$("#embedbox").is(":visible") )
		{
			if($("#twitterbox").is(":visible")) $("#twitterbox").fadeOut(400,function(){ $("#embedbox").fadeIn(400); });
			if($("#fbbox").is(":visible")) $("#fbbox").fadeOut(400,function(){ $("#embedbox").fadeIn(400); });
			$(".comment_twitter,.comment_facebook,.embed_video").removeClass("active");
			$(".embed_video").addClass("active");
		}
	});
	
	/* Embed */ 
	$("#embedcode").html(EmbedCode).click(function(){$(this).select();});
	
	/* Flow */

	hookPlayer();
	
	
	$("#videonav").find("li").each(function(a,b,c){
	
		$(this).children("a").click(function(){ goToSec(seek[a]);});	

	});
	
});


/* Analytics */

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18384884-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


