﻿
function makeScrollbarB(content,scrollbar,handle,horizontal,ignoreMouse){

if ( content.getScrollSize().y-content.getSize().y > 0){
		var slider = new Slider(scrollbar, handle, {
		steps: 100,
		mode: (horizontal?'horizontal':'vertical'),
			onChange: function(step){
			// Scrolls the content element in x or y direction.
				var x = (horizontal?(((content.getScrollSize().x-content.getSize().x)/100)*step):0);
				var y = (horizontal?0:(((content.getScrollSize().y-content.getSize().y)/100)*step));
				content.scrollTo(x,y);
			}
		}).set(0);
		
		if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the
		// content or the scrollbar element.
				$$(content, scrollbar).addEvent('mousewheel', function(e){
					e = new Event(e).stop();
					var step = slider.step - e.wheel * 2;
					slider.set(step);
				});
		}
		
		// Stops the handle dragging process when the mouse leaves the document body.
		$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}else {

	scrollbar.fade(0);

}
}
	
	window.addEvent('domready',function(){
										
										
	var customTips = $$('.tooltip');

var toolTips = new Tips(customTips, {
	//this will set how long before 
	//the tooltip will wait to show up
	//when you mouseover the element
	//in milliseconds
	showDelay: 50,    //default is 100
	
	//this is how long the tooltip
	//will delay bofore hiding
	//when you leave
	hideDelay: 50,   //default is 100
	
	//this will add a wrapper div 
	//with the following class to your tooltips
	//this lets you have different styles of tooltips
	//on the same page
	className: 'bocata', //default is null
	
	//this sets the x and y offets
	offsets: {
		'x': 16,       //default is 16
		'y': 16        //default is 16
	},
	
	//this determines whether the tooltip
	//remains staitionary or follows your cursor
	//true makes it stationary
 	fixed: false,      //default is false
	
	//if you call the functions outside of the options
	//then it may "flash" a bit on transitions
	//much smoother if you leave them in here
	onShow: function(toolTipElement){
	    //passes the tooltip element
		//you can fade in to full opacity
		//or leave them a little transparent
    	toolTipElement.fade(.9);
		$('show').highlight('#FFF504');
	},
	onHide: function(toolTipElement){
    	toolTipElement.fade(0);
		$('hide').highlight('#FFF504');
	}
});
										
										
	

		if ($('filetoncontenido')) {
		// PESTAÑAS PRINCIPALES
			var Videos = new noobSlide({
				box: $('filetoncontenido'),
				items: $$('#filetoncontenido div'),
				size: 503,
				handles: $$('#opcionesvideo li'),
				onWalk: function(currentItem,currentHandle){
				//	$('info4').set('html',currentItem.getFirst().innerHTML);
					this.handles.removeClass('filetonactivo');
					currentHandle.addClass('filetonactivo');
				}
			});
		}


		if ($('filetonnoticias')) {
			var Noticias = new noobSlide({
				box: $('filetonnoticias'),
				items: $$('#filetonnoticias div'),
				size: 345,
				handles: $$('#opcionesnoticias li'),
				onWalk: function(currentItem,currentHandle){
				//	$('info4').set('html',currentItem.getFirst().innerHTML);
					this.handles.removeClass('filetonactivo');
					currentHandle.addClass('filetonactivo');
				}
			});
		}
		
		if ($('filetonnoticiasrepor')) {
			var Noticias = new noobSlide({
				box: $('filetonnoticiasrepor'),
				items: $$('#filetonnoticiasrepor div'),
				size: 345,
				handles: $$('#opcionesnoticiasrepor li'),
				onWalk: function(currentItem,currentHandle){
				//	$('info4').set('html',currentItem.getFirst().innerHTML);
					this.handles.removeClass('filetonactivo');
					currentHandle.addClass('filetonactivo');
				}
			});
		}
		
		
		if ($('filetonvideosrelac')) {
			var Videorel = new noobSlide({
				box: $('filetonvideosrelac'),
				items: $$('#filetonvideosrelac div'),
				size: 322,
				handles: $$('#numvr span'),
				onWalk: function(currentItem,currentHandle){
				//	$('info4').set('html',currentItem.getFirst().innerHTML);
					this.handles.removeClass('videoinverso');
					currentHandle.addClass('videoinverso');
				}
			});
		}



	if ($('noticiasscroll1')) {
		// SCROLLBAR
		
		// -- first example, vertical scrollbar --
				makeScrollbarB( $('noticiasscroll1'), $('scrollbar1'), $('handle1') );
				makeScrollbarB( $('noticiasscroll2'), $('scrollbar2'), $('handle2') );
				makeScrollbarB( $('noticiasscroll3'), $('scrollbar3'), $('handle3') );
				makeScrollbarB( $('noticiasscroll4'), $('scrollbar4'), $('handle4') );
				// -- second example, horizontal scrollbar --
				//makeScrollbar( $('content2'), $('scrollbar2'), $('handle2'), true );
				// -- third example, horizontal and vertical scrollbars
				//makeScrollbar( $('content3'), $('scrollbar3'), $('handle3'), false );
				//makeScrollbar( $('content3'), $('scrollbar4'), $('handle4'), true, true );
	};
	

	});
	
	
	
			
	
	
	
	
	
// SEGUIMIENTO STREAMING

function gid(name) {
	return document.getElementById(name);
}

function thisMovie(movieName) {
	return document.getElementById(movieName);
	/*
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
	*/
};

var tracing = false;
var videoini= false;
function printTrace(str) {

	if(videoini == false) {
		// Aqui puede ir algo que queramos que haga al principio
		videoini=true;
	
	}

	if(tracing == true) {
		var itm = gid('tracecode');
		var txt = itm.innerHTML + str + '\n';
		itm.innerHTML = txt;
		itm.scrollTop = itm.scrollHeight;
	}
};

function toggleTrace() {
	var itm = gid('tracecode');
	if (tracing == true) { 
		tracing = false;
		itm.style.display = 'none';
	} else { 
		tracing = true;
		itm.innerHTML = '';
		itm.style.display = 'block';
	}
};

var configobj;
var playlistobj;
function printConfig() {
	tracing = false; 
	var cfg = thisMovie('videocp').getConfig();
	configobj = cfg;
	printData(cfg);
}
function printPlaylist() {
	tracing = false;
	var ply = thisMovie('videocp').getPlaylist();
	playlistobj = ply;
	var txt = "";
	for(var i=0; i<ply.length; i++) {
		txt += i+":\r\n";
		for(var itm in ply[i]) {
			txt += "-> "+itm+": "+ply[i][itm]+"\r\n";
		}
	}
	var itm = gid('tracecode');
	itm.innerHTML = txt;
}
function printData(cfg) { 
	var txt = "";
	for(var itm in cfg) {
		txt += itm+": "+cfg[itm]+"\r\n";
	}
	var itm = gid('tracecode');
	itm.innerHTML = txt;
	itm.style.display = 'block';
}			
						


function getUpdate(typ,pr1,pr2,swf) { 
	if(typ == "time") { currentPosition = pr1; pr2 == undefined ? null: currentRemaining = Math.round(pr2); }
	else if(typ == "volume") { currentVolume = pr1; } 
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100);}
	else if(typ == "state") { currentState = pr1; }
	else if(typ == "load") { currentLoad = pr1; }
	else if(typ == "size") { currentXsize = "X=" + pr1; pr2 == undefined ? null: currentYsize = "Y=" + Math.round(pr2); } 

	var tmp = document.getElementById("pid"); if ((tmp)&&(swf != "null")) { tmp.innerHTML = "(received from the player with the id: <i><b>"+swf+"</b></i>)"; } 
		
	var tmp = document.getElementById("time"); if (tmp) { tmp.innerHTML = "<b>Time:</b> " + currentPosition + "&nbsp;&nbsp;<b>Remaining:</b> " + currentRemaining; } 
	var tmp = document.getElementById("volume"); if (tmp) { tmp.innerHTML = "<b>Volume:</b> " + currentVolume; } 
	var tmp = document.getElementById("item"); if (tmp) { tmp.innerHTML = "<b>Item:</b> " + currentItem; } 
	var tmp = document.getElementById("state"); if (tmp) { tmp.innerHTML = "<b>State:</b> " + currentState + "&nbsp;&nbsp; (0:ready/paused, 1:loading, 2:playing, 3:finished)"; } 
	var tmp = document.getElementById("load"); if (tmp) { tmp.innerHTML = "<b>Load:</b> " + currentLoad; }
	var tmp = document.getElementById("size"); if (tmp) { tmp.innerHTML = "<b>Size:</b> " + currentXsize + ", " + currentYsize; } 
};	