$(document).ready ( function() {
	//dropdown menus (li:hover) per ie6
	$('#main-menu li, #funcionalitats li, .box-videos-canal ul li .opcions .info, .llistat-portada-canal ul li .opcions .info').hover(
		function(){             
			$(this).addClass('hover');
		}, 
		function(){     
			$(this).removeClass('hover');
		}
	); 
	
	//carroussels
	 if($('.modul-galeria ul').length != 0){
		$('.modul-galeria ul').jcarousel({
		 animation: 800,
		 scroll: 1,
		 itemVisibleInCallback : setpaginador
		});
	 }
	 
	 function setpaginador(object, li, index, state)
	 {
		var total = object.size();
		$('.modul-galeria .info').html(index + "/" + total);
		
	 }
	//lightbox
	//$('.galeria a, .fotos a').lightBox();
	
	//--- desplegable comentaris
	var velocidad = 600;
	$('#form-comentaris').hide();
	$('#comentaris .mes').click(function(){
		$('#form-comentaris').slideDown(velocidad);
	});
	
	//--- rollovers colors
	$('#xarxa a').each(function(i){
		var img = $(this).find('img');
		var src = img.attr('src');
		var indexos = [src.lastIndexOf('/'),src.lastIndexOf('-')];
		var nomGris = 'gris';
		var ruta = src.substring(0,indexos[0]+1);
		var nomFitxer = src.substring(indexos[0]+1,indexos[1]);
		var format = src.substring(indexos[1]+nomGris.length+1);
		$(this).hover(
			function () {
				img.attr('src',ruta + nomFitxer + format);
			}, 
			function () {
				img.attr('src',ruta + nomFitxer + '-' + nomGris + format);
			}
		);	
	});
	
	//thickbox: recomanar: 320x195
	var tb_pathToImage = "/images/loading.gif";
	//on page load call tb_init
	if ($('a.recomanar').length > 0){
		var link = $('a.recomanar').attr('href');
		$('a.recomanar').attr('href',link+'&TB_iframe=true&width=520&height=506');
	}
	tb_init('a.thickbox, a.recomanar');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	
	//nova finestra
	$('a.popup, #xarxa a').click(function(){
		var ventana = window.open(this.href, 'Finestra', 'width=800, height=600, menubar=1, location=1, toolbar=1, directories=1, status=1, resizable=1, scrollbars=1');
		if (window.focus) ventana.focus();
		return false;
	});
	/*
	//popup audio, video: 596x480
	$('.audios-relacionats li a, .videos-relacionats li a').click(function(){
		var ventana = window.open(this.href, 'Finestra', 'width=617, height=480, menubar=0, location=0, toolbar=0, directories=0, status=0, resizable=0, scrollbars=1');
		if (window.focus) ventana.focus();
		return false;
	});
	*/
	
	//imprimir
	$('a.imprimir').click(function(){
		print();
		return false;
	});
	//carroussels
	if($('.box-videos-canal ul').length != 0){
		$('.box-videos-canal ul').jcarousel({
			animation: 1000,
			scroll: 3
		});
	}
	if($('#ciutv #ultims-videos ul').length != 0){
		$('#ciutv #ultims-videos ul').jcarousel({
			animation: 1000,
			scroll: 3,
			vertical: true
		});
	}
	
	//tabs videos populars
	$('#populars .box-videos-canal').each(function(i){
		if(i > 0){
			$(this).hide();
		}
	});
	$('.cap-populars li').each(function(i){
		if (i == 0) $(this).addClass('actual');
		$(this).click(function(){
			$('.cap-populars li').removeClass('actual');
			$(this).addClass('actual');
			$('#populars .box-videos-canal').hide();
			$('#populars .box-videos-canal').each(function(j){
				if(i == j){
					$(this).show();
				}
			});
			return false;
		});
	});
	
	//players audio
	$('.llistat-audios .bot-audio').click(function(){
		if ($(this).hasClass('bot-audio-actiu')){
			$(this).removeClass('bot-audio-actiu');
			$(this).parent().find('.audio-player').fadeOut(300);
		}else{
			$(this).addClass('bot-audio-actiu');
			$(this).parent().find('.audio-player').fadeIn(300);
		}
		return false;
	});			
	
	jQuery(function() {
	  SSS.preloadimages("../images/","ico-player-on.png");
	  SSS.menuinit();
	});
	
	
});
	function canviaVideo(id)
	{
		$.post("ajax/canviaVideo.php", {id:id},
		function(data) {	
			$("#div-video").html(data);
		});			
	}		
	
	function votarVideo(id, lang)
	{
        var votar;
        var vote_ok;
        
        switch (lang)
        {
            case 'es':
                votar = 'Votar';
                vote_ok = 'Tu voto ha sido almacenado';
                break;
            case 'en':
                votar = 'Vote';
                vote_ok = 'Your vote has been recorded';
                break;
            default:
                votar = 'Votar';
                vote_ok = 'El teu vot ha quedat enregistrat';
                break;
        }
		$.post("ajax/votarVideo.php", {v:id},
		function(data) {	
			$("#votsVideo").html(data);
		});		
		$("#textVotar").html('<span class="votar" id="votarVideo" style="color:#F68B1E">'+votar+'</span><p>'+vote_ok+'</p>');
	}
