

// init SVP VARS *****************************************************************
var SSG_defaultVideoWidth = 320;
var SSG_defaultVideoHeight = 180;
var SSG_defaultVideoConsoleHeight = 37;

var SSG_ConfigData = new Object()
 SSG_ConfigData.WIDTH = SSG_defaultVideoWidth;
 SSG_ConfigData.HEIGHT = SSG_defaultVideoHeight;
 SSG_ConfigData.SKIN_URL = "http://www.tv3.cat/svp2/themes/svp2_skinRitmes.swf";
var SSG_FlashParams = new Object()
 SSG_FlashParams.bgcolor = "#ffffff";
 SSG_FlashParams.quality = "high";
 SSG_FlashParams.swLiveConnect = "true";
 SSG_FlashParams.menu = "true";
 SSG_FlashParams.wmode = "transparent";
 SSG_FlashParams.scale = "noscale";
 SSG_FlashParams.allowFullScreen = "true";
 SSG_FlashParams.width = SSG_defaultVideoWidth;
 SSG_FlashParams.height = SSG_defaultVideoHeight + SSG_defaultVideoConsoleHeight;
// end SVP VARS *****************************************************************


// Bool to block first hit
var SSG_blocksFirstHit = true;

// init RECULL ELS VALORS DEL ITEM **********************************************
function getNodeData(node){
	if( $(".SSG") != null ) {
		// VALORS
		var titol_html = jQuery(".desc_fl > h2",node).text();
		var sub_titol_html = jQuery(".desc_fl > h3",node).text();
		var id_html = jQuery(".desc_fl > span",node).text();
		var desc_html = jQuery(".desc_fl > p",node).text();
		// SET VIDEO DESTACAT DESCRIPTION
		setVideoDescription(titol_html,sub_titol_html,desc_html);
		setVideoRollover(titol_html,sub_titol_html);
		// MIREM SI ENTRA UN ID NUMERIC O UNA URL AMB UNA EXTENSIÃ“ DE FITXER
		if(id_html.toString().indexOf(".") == -1){
		// LOAD SVP ITEM
		loadSVP(id_html);
	
		}else{
		loadImage(id_html);
		}
		// RESALTA EL ITEM SELECCIONAT
		selectItemInGallery(".SSG",node);
		// AJAX OJD HIT
		if( !SSG_blocksFirstHit ) { 	
			ajaxSite_DoHit(); 	
		}
		SSG_blocksFirstHit = false;	
	}
}
// end RECULL ELS VALORS DEL ITEM ***********************************************

// METODES . SET DESCRIPCIÃ“ DEL DESTACAT, CARREGA SVP, CARREGA IMATGE
function setVideoDescription(t,st,d){
	if( $(".SSG") != null ) {
		document.getElementById("SGG_video_title").innerHTML = t;
		document.getElementById("SGG_video_sub_title").innerHTML = st;
		document.getElementById("SGG_video_description").innerHTML = d;
	}
}
function setVideoRollover(t,st){
	if( $(".SSG") != null ) {
		document.getElementById("SGG_item_common_title").innerHTML = t;	
		document.getElementById("SGG_item_common_sub_title").innerHTML = st;
	}
}

function loadSVP(id){
	if( $(".SSG") != null ) {
		jQuery(".SSG_image_container").html("");
		jQuery(".SSG_image_container").css("display","none");
		jQuery(".SSG_video_container").css("display","block");
		SSG_ConfigData.VIDEO_ID = id;
		insertaSVP( "SSG_video_container", SSG_ConfigData , SSG_FlashParams );
	}
}

function loadImage(id){
	if( $(".SSG") != null ) {
		jQuery(".SSG_video_container").html("");
		jQuery(".SSG_video_container").css("display","none");
		jQuery(".SSG_image_container").css("display","block");
		document.getElementById("SGG_image_container").innerHTML = "<img src='"+id+"' border= 0>";
	}
}

// CARREGA CATEGORIA
function mostraVideoCategoria(selectedIndex){
	if( $(".SSG") != null ) {
		var elementsLlistat = jQuery(".categories li");
		var tot = elementsLlistat.length;
		
		//var selectedIndex = obj.selectedIndex; // returns the index of the selected option, ie: 0,1,2...
		for (var i =1;i<=tot; i++){
			jQuery(".categoria"+(i)).css("display","none");
			jQuery(elementsLlistat[i-1]).removeClass("selected");
			if(i == selectedIndex){
			jQuery(".categoria"+(i)).css("display","block");
			jQuery(elementsLlistat[i-1]).addClass("selected");
			}
		}
	}
}


// FUNCIO PER SELECCIONAR / RESALTAR EL ITEM CLICAT
function selectItemInGallery(gallery,obj){
	if( $(".SSG") != null ) {
		jQuery(".item",gallery).fadeTo("fast", 1);
		jQuery(obj).fadeTo("fast", 0.33);
	}
}


// INICIALITZA EL COMPORTAMENT DELS ITEMS DEL CAROUSEL
function init_comportament_items_galeria(){
	if( $(".SSG") != null ) {
		$('div.news_items div.item')
			.hover(function () { // ROLLOVER ITEMS
			  var titol_html = jQuery(".desc_fl h2",this).text();
					var sub_titol_html = jQuery(".desc_fl h3",this).text();
					jQuery("#SGG_item_common_title").html(titol_html);
					jQuery("#SGG_item_common_sub_title").html(sub_titol_html);
					jQuery("#SGG_item_common_title,#SGG_item_common_sub_title").show();
					jQuery("div.player",this).addClass('player-on');
			},
			function () {
					jQuery("#SGG_item_common_title,#SGG_item_common_sub_title").hide();
					jQuery("div.player",this).removeClass('player-on');
			}
		  )
		  .append("<div class='player'></div>");//AFEGEIX LA IMATGE 'PLAYER' SOBRE CADA ITEM
	}
}




// ********************************************************************************************************************
// INIT GALLERY // HEM DE INICIALIZAR LES GALERIES QUE TENIM EN PÃ€GINA
// AQUEST PAS HO PODEM DEIXAR A LA PLANA, SI VOLEM

$(function() {
	if( $(".SSG") != null ) {
		/*
		newsHeadline: "Galeria"  (String)          |  Per defecte al header surt la paraula "Galeria". Si volem, modifiquem aqui.
		newsSpeed: "normal"          (String/Integer)  |  "slow","normal","fast", o un numero, con 1 mÃ¡s rapido
		*/
	
		$(".categoria1").accessNews({
			newsHeadline: "Nom Categoria 1",
			newsSpeed: "normal"
		});
	
		$(".categoria2").accessNews({
			newsHeadline: "Nom Categoria 2",
			newsSpeed: "normal"
		});
	
		$(".categoria3").accessNews({
			newsHeadline: "Nom Categoria 3",
			newsSpeed: "normal"
		});
	}

});

// INICIALIZEM AMB EL ELEMENT
$(document).ready(function() {
	if( document.getElementById("SGG_video_title") != null ) {
		getNodeData(document.getElementById("STARTER"));
		jQuery(".news_items").css("display","block");
		jQuery(".categories ul li:first").addClass("selected");
		init_comportament_items_galeria();
	}
});