jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();
jQuery.fn.pagination = function(maxentries, opts){
	opts = jQuery.extend({items_per_page:10,num_display_entries:10,current_page:0,num_edge_entries:0,link_to:"#",prev_text:"Prev",next_text:"Next",ellipse_text:"...",prev_show_always:true,next_show_always:true,callback:function(){return false;}},opts||{});
	return this.each(function() {
		function numPages() {return Math.ceil(maxentries/opts.items_per_page);}
		function getInterval()  {var ne_half = Math.ceil(opts.num_display_entries/2);var np = numPages();var upper_limit = np-opts.num_display_entries;var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), 0):0;var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np);return [start,end];}
		function pageSelected(page_id, evt){current_page = page_id;drawLinks();var continuePropagation = opts.callback(page_id, panel);if (!continuePropagation) {if (evt.stopPropagation) {evt.stopPropagation();}else {evt.cancelBubble = true;}}return continuePropagation;}
		function drawLinks() {
			panel.empty();
			var interval = getInterval();
			var np = numPages();
			var getClickHandler = function(page_id) {return function(evt){ return pageSelected(page_id,evt); }}
			var appendItem = function(page_id, appendopts){page_id = page_id<0?0:(page_id<np?page_id:np-1);appendopts = jQuery.extend({text:page_id+1, classes:""}, appendopts||{});if(page_id == current_page){var lnk = $("<span class='current'>"+(appendopts.text)+"</span>");}else{var a = $("<a>"+(appendopts.text)+"</a>").bind("click", getClickHandler(page_id)).attr('href', opts.link_to.replace(/__id__/,page_id));var lnk = $("<span></span>").append(a);}if(appendopts.classes){lnk.addClass(appendopts.classes);}panel.append(lnk);}
			if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){appendItem(current_page-1,{text:opts.prev_text, classes:"prev"});}
			if(opts.next_text && (current_page < np-1 || opts.next_show_always)){appendItem(current_page+1,{text:opts.next_text, classes:"next"});}
			if (interval[0] > 0 && opts.num_edge_entries > 0){var end = Math.min(opts.num_edge_entries, interval[0]);for(var i=0; i<end; i++) {appendItem(i);}if(opts.num_edge_entries < interval[0] && opts.ellipse_text){jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);}}
			for(var i=interval[0]; i<interval[1]; i++) {appendItem(i);}
			if (interval[1] < np && opts.num_edge_entries > 0){if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text){jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);}var begin = Math.max(np-opts.num_edge_entries, interval[1]);for(var i=begin; i<np; i++) {appendItem(i);}}
		}
		var current_page = opts.current_page;
		maxentries = (!maxentries || maxentries < 0)?1:maxentries;
		opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0)?1:opts.items_per_page;
		var panel = jQuery(this);
		this.selectPage = function(page_id){ pageSelected(page_id);}
		this.prevPage = function(){ if (current_page > 0) {pageSelected(current_page - 1);return true;}else {return false;}}
		this.nextPage = function(){ if(current_page < numPages()-1) {pageSelected(current_page+1);return true;}else {return false;}}
		drawLinks();
	});
}
var videoParams =  {
		wmode: "transparent", 
		bgcolor: "transparent", 
		width: "486", 
		height: "412", 
		publisherID: "1445083406", 
		isVid: "true", 
		isUI: "true", 
		cacheAMFURL: "http://services.brightcove.com/services/messagebroker/amf", 
		playerID: "64304801001", 
		base: "http://admin.brightcove.com", 
		allowScriptAccess: "always"
	},
	videoPage = "video_vancouver",
	pageName,
	player, charEx = new RegExp('[^a-zA-Z_0-9]', "g"), pages, filter = new Object(), lastVideo,
	startTag= ["olimpiadi", "vancouver"], tags = [startTag],
	disciplineData = {
		biathlon: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_pietro_nicolodi_548_113x70.jpg", reporter: "Pietro Nicolodi", linkReporter: "/sport/olimpiadi/2009/10/30/nicolodi_pietro_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/biathlon_scheda.html", idWidget: 6},
		pattinaggio_figura: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_danilo_freri_548_113x70.jpg", reporter: "Danilo Freri", linkReporter: "/sport/olimpiadi/2009/10/29/freri_danilo_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/pattinaggio_artistico_scheda.html", idWidget: 55},		
		short_track: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_danilo_freri_548_113x70.jpg", reporter: "Danilo Freri", linkReporter: "/sport/olimpiadi/2009/10/29/freri_danilo_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/short_track_scheda.html", idWidget: 56},		
		pattinaggio_velocita: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_paolo_leopizzi_548_113x70.jpg", reporter: "Paolo Leopizzi", linkReporter: "/sport/olimpiadi/2009/10/29/leopizzi_paolo_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/pattinaggio_di_velocita_scheda.html", idWidget: 57},	
		hockey: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_luca_boschetto_548_113x70.jpg", reporter: "Luca Boschetto", linkReporter: "/sport/olimpiadi/2009/10/29/boschetto_luca_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/hockey_su_ghiaccio.html", idWidget: 60},	
		bob: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_nicola_roggero_548_113x70.jpg", reporter: "Nicola Roggero", linkReporter: "/sport/olimpiadi/2009/10/30/roggero_nicola_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/bob_scheda.html", idWidget: 63},	
		salto_con_gli_sci: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_pietro_nicolodi_548_113x70.jpg", reporter: "Pietro Nicolodi", linkReporter: "/sport/olimpiadi/2009/10/30/nicolodi_pietro_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/salto_con_gli_sci_scheda.html", idWidget: 65},	
		sci_alpino: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_carlo_vanzini_548_113x70.jpg", reporter: "Carlo Vanzini", linkReporter: "/sport/olimpiadi/2009/10/29/vanzini_carlo_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/sci_alpino_scheda.html", idWidget: 66},	
		sci_freestyle: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_zoran_filicic_548_113x70.jpg", reporter: "Zoran Filicic", linkReporter: "/sport/olimpiadi/2009/10/29/filicic_zoran_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/freestyle_scheda.html", idWidget: 67},
		sci_di_fondo: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_pietro_nicolodi_548_113x70.jpg", reporter: "Pietro Nicolodi", linkReporter: "/sport/olimpiadi/2009/10/30/nicolodi_pietro_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/sci_di_fondo_scheda.html", idWidget: 69},		
		slittino: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_nicola_roggero_548_113x70.jpg", reporter: "Nicola Roggero", linkReporter: "/sport/olimpiadi/2009/10/30/roggero_nicola_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/slittino_scheda.html", idWidget: 70},		
		snowboard: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_zoran_filicic_548_113x70.jpg", reporter: "Zoran Filicic", linkReporter: "/sport/olimpiadi/2009/10/29/filicic_zoran_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/snowboard_scheda.html", idWidget: 71},		
		curling: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_lucio_rizzica_548_113x70.jpg", reporter: "Lucio Rizzica", linkReporter: "/sport/olimpiadi/2009/10/29/rizzica_lucio_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/22/curling_scheda.html", idWidget: 72},		
		skeleton: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_nicola_roggero_548_113x70.jpg", reporter: "Nicola Roggero", linkReporter: "/sport/olimpiadi/2009/10/30/roggero_nicola_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/skeleton_scheda.html", idWidget: 73},
		combinata_nordica: {img: "/static/contentimages/resized/sezioni/sport/olimpiadi/2009/10/27/foto_giornalisti_olimpici_nicola_roggero_548_113x70.jpg", reporter: "Nicola Roggero", linkReporter: "/sport/olimpiadi/2009/10/30/roggero_nicola_scheda_giornalista.html", linkDiscipline: "/sport/olimpiadi/2009/10/23/combinata_nordica_scheda.html", idWidget: 75}
	},
	brightcoveOpt = {command : "find_videos_by_tags",and_tags: tags,sort_by : "PUBLISH_DATE",sort_order : "DESC",token : "eU8gJZcBG78eTUrQKDiJRML3aTCWmsCSJmu_zcX5fn8.",page_size :1,page_number:0};
function parseLabel(date, discipline, more){
	var month = ["GENNAIO", "FEBBRAIO", "MARZO"]
	var label = date != undefined ?  "VIDEO " + date.split('-')[0] + " " + month[parseInt(date.split('-')[1])-1] : date;
	label = discipline != undefined ?  (label || "VIDEO") + (label != undefined ? ", " : " ") + discipline : (label || undefined);
	label = more != undefined ?  (label || "VIDEO") + (label != undefined ? ", " : " ") + more : (label || undefined);
	return label;
};
function updateLabel(container){
	container.prev('.label').attr({"id" : "olimpiadi-videoPlayer-anchor", "name" : "olimpiadi-videoPlayer-anchor"});
	return container.prev('.label').html(parseLabel(filter["date"], filter["discipline"], filter["more"]) || "gli ultimi Video");
};
function updatePlayerContent(playerTitle, playerAbstract){
	$('#olimpiadi-videoPlayer-container #olimpiadi-videoPlayer-title').html(playerTitle);
	$('#olimpiadi-videoPlayer-container #olimpiadi-videoPlayer-abstract').html(playerAbstract);
	if (playerAbstract == '')$('#olimpiadi-videoPlayer-container #olimpiadi-videoPlayer-abstract').hide();
	return true;
};
function createPlayer (idVideo){
	$('#olimpiadi-videoPlayer-container #olimpiadi-videoPlayer').empty();
	player = brightcove.createElement("object");
	player.id = idVideo;
	videoParams["@videoPlayer"] = idVideo;
	var parameter;
	for (var i in videoParams) {
		parameter = brightcove.createElement("param");
		parameter.name = i;
		parameter.value = videoParams[i];
		player.appendChild(parameter);
	}
	updateLabel($('#olimpiadi-videoPlayer-container'));
	lastVideo = idVideo;
	return brightcove.createExperience(player, document.getElementById('olimpiadi-videoPlayer'), true);
};
function updatePlayer(idVideo){
	bcExp = brightcove.getExperience(player.id);
	modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
	updateLabel($('#olimpiadi-videoPlayer-container'));
	lastVideo = idVideo;
	nielsenRefresh(document.location.href+"#video");
	return modVP.loadVideo(idVideo);
};
function loadContents(page_id){
	if (page_id != null){
		getVideo(page_id, tags, false);
		nielsenRefresh(document.location.href+"#video");
		return true;
	}
	return false;
};
function createBlock(i, obj, idVideo){
	var newDiv = $("<div>").addClass("olimpiadi-thumb").attr({"id": idVideo});
	if (i==0){newDiv.addClass('videoResults-selected');}
	$('<img>').attr({"src": (obj.thumbnailURL == null ? "/static/images/sezioni/sport/olimpiadi/no_thumb.gif" : obj.thumbnailURL)}).addClass("olimpiadi-thumb-img").appendTo(newDiv).bind("click", function(){$(this).next(".olimpiadi-thumb-title").trigger("click");});
	$('<a></a>').attr({"href": "#olimpiadi-videoPlayer"}).text(obj.name).addClass("olimpiadi-thumb-title").appendTo(newDiv).bind("click", function(){
		$('.videoResults-selected').removeClass('videoResults-selected');
		updatePlayer($(this).parent().addClass('videoResults-selected').attr('id'));
		updatePlayerContent($(this).text(), $(this).next(".olimpiadi-thumb-abstract").text() || '');
		self.location.href = "#olimpiadi-videoPlayer-anchor";
	});
	$('<span></span>').text(obj.shortDescription || '').addClass("olimpiadi-thumb-abstract").appendTo(newDiv);
	newDiv.appendTo("#olimpiadi-videoResults");
	return true;
};
function updateBlock(i, obj, idVideo){
	var resultDivContainer = $('#olimpiadi-videoResults div.olimpiadi-thumb:eq('+i+')');
	resultDivContainer.attr({'id':idVideo})
	resultDivContainer.find('img.olimpiadi-thumb-img').attr({"src": (obj.thumbnailURL == null ? "/static/images/sezioni/sport/olimpiadi/no_thumb.gif" : obj.thumbnailURL)});
	resultDivContainer.find('a.olimpiadi-thumb-title').html(obj.name);
	resultDivContainer.find('span.olimpiadi-thumb-abstract').html(obj.shortDescription);
	if (resultDivContainer.children().is(':hidden'))resultDivContainer.removeClass("hidden-background").children().show();
	if (lastVideo == idVideo){resultDivContainer.addClass('videoResults-selected');
	}else if (resultDivContainer.hasClass('videoResults-selected')){resultDivContainer.removeClass('videoResults-selected');}
	return true; 
};
function getVideo(page, tags, flag){
	var ajaxOpt = {url: null, global: false,type: "GET",cache: false,dataType: null,success:null, data:null};
	ajaxOpt['url'] = "http://api.brightcove.com/services/library";
	brightcoveOpt['page_size'] = 10;
	brightcoveOpt['get_item_count'] = true;
	brightcoveOpt['and_tags'] = tags;
	brightcoveOpt['page_number'] = page;
	brightcoveOpt['video_fields'] = "id,name,thumbnailURL,shortDescription";
	brightcoveOpt['sort_by'] = "MODIFIED_DATE";
	brightcoveOpt['sort_order'] = "DESC";
	ajaxOpt['data'] = brightcoveOpt;
	ajaxOpt['dataType'] = 'jsonp';
	ajaxOpt['success'] = function(data){
		pages = data.total_count;
		if(flag){$("#olimpiadi-videoResults, #olimpiadi-videoResults-footer").empty();}
		else if(data.items.length < 10){$('#olimpiadi-videoResults > .olimpiadi-thumb:gt('+(data.items.length-1)+')').each(function(){$(this).addClass("hidden-background").children().hide();});}
		if (parseInt(pages) == 0){
			$("#olimpiadi-videoResults").html('<span class="olimpiadi-search-alert">Siamo spiacenti, ma non risulta nessun video per i tag selezionati: ' +tags+'</span>');
			return false;
		}
		$(data.items).each(function (i, obj){
			var idVideo = (obj.id);
			if(i == 0 && flag){createPlayer(idVideo);updatePlayerContent(obj.name, obj.shortDescription || '');}
			if(flag){createBlock(i, obj, idVideo);}
			else{updateBlock(i, obj, idVideo);}
			if (flag){var pagination = $("#olimpiadi-videoResults-footer").pagination(pages, {current_page: 0,items_per_page:10, num_edge_entries: 1,num_display_entries: 10,next_show_always: true,prev_show_always: true,next_text:'AVANTI',prev_text: 'INDIETRO',link_to: 'javascript:void(0);',ellipse_text:'-',callback: loadContents});}
		});
	};
	ajaxOpt['error'] = function(){alert("error");};
	$.ajax(ajaxOpt);
	return true;
};
function setVideoPlay(tags){
	var ajaxOpt = {url: null, global: false,type: "GET",cache: false,dataType: null,success:null, data:null};
	ajaxOpt['url'] = "http://api.brightcove.com/services/library";
	brightcoveOpt['and_tags'] = tags;
	brightcoveOpt['video_fields'] = "id,name,shortDescription";
	brightcoveOpt['sort_by'] = "MODIFIED_DATE";
	brightcoveOpt['sort_order'] = "DESC";
	ajaxOpt['data'] = brightcoveOpt;
	ajaxOpt['dataType'] = 'jsonp';
	ajaxOpt['success'] = function(data){
		/*if (data.total_count == -1){
			//$('#olimpiadi-videoPlayer-container').html('<span class="olimpiadi-search-alert">Siamo spiacenti, nessun video disponibile.</span>')
			$('#olimpiadi-videoPlayer-container').parent().parent().hide();
			return false;
		}*/
		$(data.items).each(function (i, obj){
			createPlayer(obj.id);
			updatePlayerContent(obj.name, obj.shortDescription || '');
		});
	};
	ajaxOpt['error'] = function(){alert("error");};
	$.ajax(ajaxOpt);
	return true;
};
function highlitsTags(paramTags){
	if (paramTags == undefined){return false;}
	else{jQuery.each(paramTags.split(','), function (i, obj){
		var currentTag = $("div#olimpiadi-date-param input.olimpiadi-date-button[value="+jQuery.trim(obj)+"]");
		if (currentTag.length != 0){
			currentTag.parent().find(".olimpiadi-button-checked").removeClass("olimpiadi-button-checked olimpiadi-all-checked");
			currentTag.addClass("olimpiadi-button-checked");
			filter["date"] = obj.split('/')[0] + '-0' +obj.split('/')[1] + '-10';
		}
		currentTag = $("div#olimpiadi-discipline-filter select.olimpiadi-discipline-filter-selectbox option[value="+jQuery.trim(obj)+"]");
		if (currentTag.length != 0){
			currentTag.parent().find(":selected").removeAttr("selected");
			currentTag.attr({"selected":"selected"});
			filter["discipline"] = obj;
		}
		currentTag = $("div#olimpiadi-more-filter select.olimpiadi-more-filter-selectbox option[value="+jQuery.trim(obj)+"]");
		if (currentTag.length != 0){
			currentTag.parent().find(":selected").removeAttr("selected");
			currentTag.attr({"selected":"selected"});
			filter["more"] = obj;
		}
	});}
	return true;
};
function filterResults(){
	nielsenRefresh(document.location.href+"#video");
	tags=[startTag];
	filter["date"] != undefined ? tags.push(filter["date"]) : '';
	filter["discipline"] != undefined ? tags.push(filter["discipline"]) : '';
	filter["more"] != undefined ? tags.push(filter["more"]) : '';
	tags = tags.join(',');
	return getVideo(0, tags, true);
};
function bindTags(){
	var addAll = function(obj) {
		obj.addClass("olimpiadi-all-checked");
		return undefined;
	}
	$("div#olimpiadi-date-param input.olimpiadi-date-button").bind("click", function(){
		$("div#olimpiadi-date-param input.olimpiadi-button-checked").removeClass("olimpiadi-button-checked olimpiadi-all-checked");
		$(this).addClass("olimpiadi-button-checked");
		var dateText = jQuery.trim($(this).val());
		filter["date"] =  dateText != "tutte" ? (dateText.split('/')[0] + '-0' +dateText.split('/')[1] + '-10') : addAll($(this));
		return filterResults();
	});
	$("div#olimpiadi-discipline-filter select.olimpiadi-discipline-filter-selectbox").bind("change", function(){
		var disciplineText = jQuery.trim($(this).find("option:selected").text());
		filter["discipline"] = disciplineText != "tutte" ? disciplineText.toLowerCase() : undefined;
		return filterResults();
	});
	$("div#olimpiadi-more-filter select.olimpiadi-more-filter-selectbox").bind("change", function(){
		var moreText = jQuery.trim($(this).find("option:selected").val());
		filter["more"] = moreText != "tutte" ? moreText.toLowerCase() : undefined;
		return filterResults();
	});
};
function setVideoPlaylist(tags){
	getVideo(0, tags, true);
	bindTags();
	return true;
};
function upperCaseFirst(str){
	return str.slice(0,1).toUpperCase()+ str.slice(1);
}
function setReporter(pageName){
	var genericElement = $('<a></a>').attr({"href":disciplineData[pageName].linkDiscipline}).text(upperCaseFirst(pageName.replace(/_/g," ") || ''));
	$('#olimpiadi-discipline-brick .discipline-brick-title').append(genericElement);
	genericElement = $('<span></span>').text(' | ve lo racconta');
	$('#olimpiadi-discipline-brick .discipline-brick-title').append(genericElement);
	genericElement = $('<a></a>').attr({"href":disciplineData[pageName].linkReporter}).addClass('discipline-reporter-name').text(disciplineData[pageName].reporter || "");
	$('#olimpiadi-discipline-brick .discipline-brick-title').append(genericElement);
	$('#olimpiadi-discipline-brick .discipline-brick-img').attr({
		"src" : disciplineData[pageName].img || "/static/images/sezioni/sport/olimpiadi/no_thumb.gif" , 
		"alt" : disciplineData[pageName].reporter || "", 
		"title" : disciplineData[pageName].reporter || ""
	})
	return true;
};
function setDisciplineAllVideo(url, pageName){
	$('#all_video_discipline').bind("click", function(){
		document.location.href=url + ".html?tags=" + pageName;
	});
};
function setPodioWidget(pageName){
	$('#olimpiadi-podio-widget-iframe').attr(
		{'src':"http://sport.sky.it/sport/olimpiadi/statistiche/widget_cal_discipline.shtml?border=1&width=552&height=400&id=calendario_disciplina&discipline_id="+disciplineData[pageName].idWidget+"&scrollbar=yes"}
	); 
};
function parseDiscipline(pageName){
	var replaced = {"salto_con_gli_sci" : "sci_salto", "sci_di_fondo" : "sci_fondo"};
	return replaced[pageName] || pageName;
};
$(document).ready(function() {
	pageName = jQuery.url.attr("file").replace(".html", "").replace("disciplina_", "");
	var	paramTags = jQuery.url.param("tags");
	tags = tags.join(',') + (paramTags != undefined ? "," + paramTags : '');
	if (pageName == videoPage){
		highlitsTags(paramTags);
		return setVideoPlaylist(tags);
	}else if (pageName != "guidatv"){
		setReporter(pageName);
		setDisciplineAllVideo(videoPage, parseDiscipline(pageName).replace(/_/g," "));
		setPodioWidget(pageName);
		return setVideoPlay(tags + "," + parseDiscipline(pageName).replace(/_/g," "));
	}
});



/******************** GUIDA TV ************************************/

	var base_channel_data_url = "/sport/app/guidatv/contenuti/data/grid/";
	var base_channel_page_url = "http://guidatv.sky.it/guidatv/canale/"
	var base_programme_page_url = "http://guidatv.sky.it/guidatv/programma/" 
	
	function load_channels(category){
		var data = [{id:"6260",name:"SKY Olimpia 1",number:"206",service:"6260"},{id:"6320",name:"SKY Olimpia 2",number:"207",service:"6320"},{id:"6340",name:"SKY Olimpia 3",number:"208",service:"6340"},{id:"6341",name:"SKY Olimpia 4",number:"209",service:"6341"},{id:"6342",name:"SKY Olimpia 5",number:"210",service:"6342"}];
		var newChannelsCode = "";
			var newPlansCode = "";
			for (i=0;i<data.length;i++){
				if (userChannelMap[data[i].id] == null){
					newChannelsCode += create_channel_row(data[i], false);
					newPlansCode += create_plan_row(data[i]);
					data[i].loaded = false; //metadata for progressive loading
					channels.push(data[i]);
					}//else just discard it because already processes as user channel
				}
			document.getElementById('planlisting').innerHTML += newPlansCode;
			document.getElementById('channellisting').innerHTML += newChannelsCode;
			if (progressive_load == true)
				start_progressive_load();
			else
				load_plan(0, channels.length);
	} 
	
	//OVERRIDE PER LA DATA E ORA CORRENTE (VIA SERVLET)
	
	$.getJSON("/EtSkyIt/getServerDate.do",
        function(data){
          currentDate = o2s.parseDate(data.TIMESTAMP, "dd/mm/yyyy HH:ii:ss");
		  currentTime = currentDate.getHours();
        });


	//OVERRIDE PER VISUALIZZARE IL NUMERO DEL CANALE
	function create_channel_row(channel, isMyChannel){
		var newChannel = '<li id="ch_'+channel.id;
		newChannel += '" class="channel_head_row" _sky_number="'+channel.number+'"> <div class="channel_head"><span class="channel_number">';
		newChannel += channel.number;
		newChannel += '</span><a class="';
		if (!isUserLogged()){
		  //if not logged, cannot load user channels anyway, so they are all off
		  newChannel += 'supernote-click-loginrequired star off" title="Aggiungi ai miei preferiti" ';
		}else{
		  if (isMyChannel){
			newChannel += 'supernote-click-addedremovedchannel star on" title="Rimuovi dai miei preferiti" ';
		  }else{
			newChannel += 'supernote-click-addedremovedchannel star off" title="Aggiungi ai miei preferiti" ';
		  }
		}
		newChannel += 'href="javascript:void(0);" onclick="toggleMyChannels(\''+ channel.id +'\')" onfocus="this.blur()">Aggiungi</a>';
		newChannel += '<h4><span class="chanNum">'+channel.number+'</span><a class="channel_name" style="background: transparent url(http://guidatv.sky.it'+base_channel_img_url+'grid/'+channel.number+'_grid.gif) no-repeat scroll 0% 0%" title="';
		newChannel += channel.name+'"';
		if (show_channelpage_link == true && noPageChannels[channel.id] == null){
		  newChannel += ' href="'+getChannelUrl(channel)+'"';
		}
		newChannel += '>'+channel.name+'</a></h4></div></li>';
		return newChannel;
	}
	
	//OVERRIDE X LA STONDATURA DEI LI
	function show_channel_plan(channelid, plan, banned){

	  if (banned == null)
		banned = false;

	  var newEventHtml = "";
		
	  for (i=0;i<plan.length;i++){  
		var obj = plan[i];
		var fixedGenre = fixGenre(obj.genre);
		var fixedSubgenre = fixGenre(obj.subgenre);
		var fixedTitle = fixTitle(obj.title);
		var eventClass = '__'+fixedGenre;
		eventClass += ' __'+fixedSubgenre;
		if (obj.prima==true)
		  eventClass += ' __primavisione';
		var eventWidth = -1;
		
		if (obj.dur<=30) {
		  //eventClass = eventClass + ' d'+obj.dur;
		  eventClass = eventClass + ' dsmall';
		  eventWidth = Math.round((obj.dur/5)*12)-7;
		}else{
		  eventWidth = Math.round((obj.dur/5)*12)-15;
		}
		
		newEventHtml += "<li class='"+eventClass+"' style='";
		
		if (obj.id == -1){
		  newEventHtml += " visibility:hidden;";
		}else if (obj.dur == 0){
		  newEventHtml += " display:none;"
		}
		newEventHtml += "' title='"+fixedTitle+"'><div style=\"width:"+(eventWidth-5)+"px;\" class='block_center'>";

		if (obj.id.indexOf("FP")==-1){//non e' un 'Alle XX:XX'
		  if (show_event_popup){
			 var eventPageUrl = getProgrammeUrl(obj,fixedGenre, fixedSubgenre, false);
			newEventHtml += "<span class='titolo'><a href='javascript:void(0);'"+
			  "onclick='showGridEvent("+
				channelid+",\""+
				obj.starttime+"\",\""+
				eventPageUrl+"\",\""+
				banned+"\",\""+
				obj.id+"\",\""+
				obj.title.replace(/\'/g, "").replace(/\"/g, "")+
			  "\")'>";
		  }else{
			var eventUrl = getProgrammeUrl(obj,fixedGenre, fixedSubgenre, false);
			newEventHtml += "<span class='titolo'><a href='"+eventUrl+"'>";
		  }
		}else{
			newEventHtml += "<span class='titolo'><a href='javascript:void(0)'>";
		}

		newEventHtml += obj.title
					  + "</a></span><span class='descriz'>" + obj.desc
					  + "</span></div></li>"
	  }
	  
	  document.getElementById('chplan_' + channelid).innerHTML = "<ul class='channel'>" + newEventHtml + "</ul>";
	  applyToggledGenres('#chplan_' + channelid);
	} 
	
/********************************* FINE GUIDA TV ******************************************************/


