
// init SVP VARS *****************************************************************
var SSG_defaultVideoWidth = 400;
var SSG_defaultVideoHeight = 225;
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_super3_skin.swf";
    SSG_ConfigData.SKIN_FORM_URL = "http://www.tv3.cat//svp2/themes/svp2_super3_skinForm.swf";
    SSG_ConfigData.SKIN_VOLUME_URL = "http://www.tv3.cat//svp2/themes/svp2_super3_skinVolume.swf";
    SSG_ConfigData.TOPLAYER_VEIL_ALPHA  = 0;
	SSG_ConfigData.LINK_RELATEDVIDEO_URL = "http://www.super3.cat/psuper3/sp3Item.jsp?item=video_mm%26seccio=video%26idint=ZZVIDEOIDZZ";
	SSG_ConfigData.USE_RELATEDITEMS_URLPATTERN = "true";

	
var SSG_FlashParams = new Object()
	SSG_FlashParams.bgcolor = "#f74507";
	SSG_FlashParams.quality = "high";
	SSG_FlashParams.swLiveConnect = "true";
	SSG_FlashParams.menu = "true";
	SSG_FlashParams.scale = "noscale";
	SSG_FlashParams.allowFullScreen = "true";
	SSG_FlashParams.wmode = "transparent";
	SSG_FlashParams.width = SSG_defaultVideoWidth;
	SSG_FlashParams.height = SSG_defaultVideoHeight + SSG_defaultVideoConsoleHeight;	
// end SVP VARS *****************************************************************
	
// init RECULL ELS VALORS DEL ITEM **********************************************
function getNodeData(node){
	// VALORS
	var titol_html = jQuery(".desc_fl > h2",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,desc_html,id_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);
	$('#overtit_fl').css("display","none");
	// AJAX OJD HIT
	ajaxSite_DoHit();
}
// end RECULL ELS VALORS DEL ITEM ***********************************************

// METODES . SET DESCRIPCIÓ DEL DESTACAT, CARREGA SVP, CARREGA IMATGE
function setVideoDescription(t,d,i){
	document.getElementById("SGG_video_title").innerHTML = '<a href="/psuper3/sp3Item.jsp?item=video_mm&seccio=video&idint='+i+'">'+t+'</a>';
	if(document.getElementById("SSG_opino")){
		document.getElementById("SSG_opino").href = '/psuper3/sp3Item.jsp?item=video_mm&seccio=video&idint='+i+'#comments';
	}
	if(d!=""&d!=undefined&d!=" "){
		document.getElementById("SGG_video_description").innerHTML = d;
	}
	}

function loadSVP(id){
	jQuery(".SSG_image_container").html("");
	jQuery(".SSG_image_container").css("display","none");
	jQuery(".SSG_video_container").css("display","block");
	jQuery("#SGG_video_title").css("display","block");
	jQuery("#SGG_video_description").css("display","block");
	SSG_ConfigData.VIDEO_ID = id;
	insertaSVP( "SSG_video_container", SSG_ConfigData , SSG_FlashParams );
	}
	
function loadImage(id){
	jQuery("#SGG_image_container").css("opacity","0");
	jQuery(".SSG_video_container").html("");
	jQuery(".SSG_video_container").css("display","none");
	jQuery(".SSG_image_container").css("display","block");
	jQuery("#SGG_video_title").css("display","none");
	$('#SGG_image_container').css("background","url("+id+")");
	document.getElementById("SGG_image_container").innerHTML='<img src="http://www.super3.cat/img/marcSSG_taronja.gif">';
	}

// CARREGA CATEGORIA 
function mostraVideoCategoria(selectedIndex){
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){
	jQuery(".item .fl",gallery).fadeTo("fast", 1);
	jQuery(obj).find(".fl").fadeTo("fast", 0.33);
	jQuery("#SGG_image_container").fadeTo(0, 1);
	}


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

$(function() {
		   
	/*
    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"
    });

});

// INICIALIZEM AMB EL ELEMENT
$(document).ready(function() {
	if(document.getElementById("STARTER")){
 	getNodeData(document.getElementById("STARTER"));
	jQuery(".news_items").css("display","block");
	jQuery(".categories ul li:first").addClass("selected");
	// Títols tooltip |AMT|
	$(".categoria1 .news_items .container .item").mouseover(
		function(){
			//$(this).find(".desc_fl").css("display", "block");
			titolh2=$(this).find(".desc_fl h2").text();
			if(titolh2!=''&titolh2!=undefined&titolh2!=" "){
				$('#overtit_fl span').text(titolh2);
				$('#overtit_fl').css("display","block");
				$('#overtit_fl').css("position","absolute");
				elem=$(this).get(0);
				twidth=$("#overtit_fl").get(0).clientWidth;
				$('#overtit_fl').css("width","auto");
				if(twidth>270){
					$("#overtit_fl span").css("white-space","normal").css("width","270px");
					if(270+elem.parentNode.offsetLeft+elem.offsetLeft+40>415){
						$("#overtit_fl").addClass("overtit_fl_l").removeClass("overtit_fl_r");
						$('#overtit_fl').css("left",elem.parentNode.offsetLeft+elem.offsetLeft-175+"px");
					}else{
						$("#overtit_fl").addClass("overtit_fl_r").removeClass("overtit_fl_l");
						$('#overtit_fl').css("left",elem.parentNode.offsetLeft+elem.offsetLeft+40+"px");
					}
				}else{
					if(twidth+elem.parentNode.offsetLeft+elem.offsetLeft+40>415){
						$("#overtit_fl").addClass("overtit_fl_l").removeClass("overtit_fl_r");
						$('#overtit_fl').css("left",elem.parentNode.offsetLeft+elem.offsetLeft-twidth+105+"px");
					}else{
						$("#overtit_fl").addClass("overtit_fl_r").removeClass("overtit_fl_l");
						$('#overtit_fl').css("left",elem.parentNode.offsetLeft+elem.offsetLeft+40+"px");
					}
					$('#overtit_fl').css("top",elem.parentNode.parentNode.parentNode.offsetTop+58+"px");
				}
			}
		}
	);
	$(".categoria1 .news_items .container .item").mouseout(
		function(){
			//$(this).find(".desc_fl").css("display", "none");
			$('#overtit_fl').css("display","none");
			$("#overtit_fl span").css("white-space","nowrap").css("width","auto");
		}
	);
	}
});
