var actual = '';

var altura1 = 0;

var alturaL1 = 0;
var alturat1 = 0;

var alturav1 = 0;
var altura = 0;
var DO_NO_RESIZE=false;

//~ if(NO_CALC_BOT==undefined){
	//~ //alert('NOOO');
	 //~ var NO_CALC_BOT=false;
 //~ }


function insertSimpleFlashById(url,w,h,id) { 
	 var str=''; 
	 str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ w +'" height="'+ h +'"  name="'+id+'"  id="'+id+'">';
	 
	 str+='<param name="movie" value="'+url+'" />'; 
	 str+='<param name="quality" value="high" />'; 
	 str+='<param name="wmode" value="opaque" />'; 
	 str+='<param name="menu" value="false" />'; 
	 str+='<param value="exactfit" name="scale" />'; 
	 str+='<embed src="'+url+'" quality="high" wmode="opaque" scale="exactfit" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" swLiveConnect="true" width="'+ w +'" height="'+ h +'" name="'+id+'"></embed>';
	 
	 str+='</object>'; 
	 document.write(str); 
} 
function hideOverMenus() {
	
	if(actual!=$('.subm.active').attr('id')){
	
	
		$('.subm').stop(true,true);
		$('.subm').hide();
		
		$('.subm.active').parent().addClass("hover");
		$('.subm.active').slideDown('fast');
		
	}
	
	$('#'+actual).removeClass('on');
	actual = $('ul.dropdown>li.active').attr('id');
	$('ul.dropdown>li.active').addClass('on');
	
	return false;
	
}

function calcBottom() {
	if(DO_NO_RESIZE){
		return;
	}
	$('#bottom').hide();
	var off = $(window).height() - $('#cols').height() - 340 - 82;
	var new_size = $('#cols').height() + off;
	if(new_size < ORIGINAL_LT_SIZE) new_size = ORIGINAL_LT_SIZE;
	$('#cols').height(new_size);
	$('#bottom').show();
}
function reposicionaBot(){
	//alert('reposiciona');
	//posicionament de la barra
	ORIGINAL_LT_SIZE = $('#cols').height();
	var off = $(window).height() - $('#cols').height() - 340 - 82;
	if(off < 0 ) off = 0;
	$('#cols').height(ORIGINAL_LT_SIZE + off);
	
	$(document).resize(calcBottom);
	$(window).resize(calcBottom);
	
	 jQuery('.SSG').each(function(){
		 if(jQuery(this).height()%2==0){
		 jQuery(this).css({paddingBottom:'8px'});
		}
      });
}
$(function() {
	//LITERATURA CIENTÍFICA
	$('a.liter').click(function(){
		
		//El dom no calcula bé el total d'alçada, el forcem:
 		//$('#cols').height(ORIGINAL_LT_SIZE);
 		
		$('.organs_govern.simp .cos').hide();
		$('a.tancar').hide();
		$('a.liter').show();
		$(this).parent().next().show();
		$(this).hide();
		$(this).parent().contents('a.tancar').show();
		$(this).parent().contents('a.tancar').css({display:'block'});
		
		$.scrollTo($(this).parent().prev().prev());
				
		/*/El dom no calcula bé el total d'alçada, el forcem:
		//aixo es perque el IE crida l'event de redimensionar si es canvia el height, ho evitem l'accio de reposicionament
		DO_NO_RESIZE=true;
		alturaL = $(this).parent().next().height();
		//~ alert(alturaL)
 		$('#cols').height(ORIGINAL_LT_SIZE+alturaL);
 		
 		//donem temps a colocar i restablim el comportament original
 		setTimeout("DO_NO_RESIZE=false;",100);*/
		
		return false;
	});
	$('a.tancar').click(function(){
		
		//El dom no calcula bé el total d'alçada, el forcem:
 		//$('#cols').height(ORIGINAL_LT_SIZE);
		
		$(this).parent().next().hide();
		$(this).hide();
		$(this).parent().contents('a.liter').show();
		return false;
	});	
	
	//Carousel disc Ilumnina 
	$('#carousel ul.belt>li a img').hover(function(){
		if(!$(this).parent().parent().hasClass('actual')) $(this).parent().parent().addClass('selected');
	},
	function(){
		if(!$(this).parent().parent().hasClass('actual')) $(this).parent().parent().removeClass('selected');
	});

	//SALTA DE DISC A DISC
	$('#carousel ul.belt>li a').click(function(){

		//El dom no calcula bé el total d'alçada, el forcem:
 //		$('#cols').height(ORIGINAL_LT_SIZE);
 		
		$('.infoCd.selected').removeClass('selected');
		$('#colRight2 .noticia.selected').removeClass('selected');
		$('#carousel ul.belt>li.selected').removeClass('selected');
		$('#carousel ul.belt>li.actual').removeClass('actual');

		$('#left-'+$(this).parent().attr('id')).addClass('selected');
		$('#right-'+$(this).parent().attr('id')).addClass('selected');
		$(this).parent().addClass('selected');
		$(this).parent().addClass('actual');
		
		$('.titoleldisc h2').text($(this).parent().contents('a').text());
	
/*		//El dom no calcula bé el total d'alçada, el forcem:
		//aixo es perque el IE crida l'event de redimensionar si es canvia el height, ho evitem l'accio de reposicionament
		DO_NO_RESIZE=true;
		altura = $('.infoCd.selected').height() - altura1;
 		$('#cols').height(ORIGINAL_LT_SIZE+altura);
 		
 		//donem temps a colocar i restablim el comportament original
 		setTimeout("DO_NO_RESIZE=false;",100); */
 		
		ajaxSite_DoHit();
		return false;
	});
	
 	//LLISTES DE CANÇONS, ENSENYA O AMAGA INFO
 		
	
	$('.llistatcancons ul>li>p.mesinfo a').click(function(event) {
		event.preventDefault();
		
		$(this).parent().parent().addClass('selected');
		var pare = $(this).parent().parent();		
		$('.info',pare).show();
		$('.cierre',pare).show();		
		$('.menysinfo',pare).show();		
		$('.mesinfo',pare).hide();
		$('.fragments',pare).hide();		
		
	});
	
	
	$('.llistatcancons ul>li>p.menysinfo a').click(function(event) {
  		event.preventDefault();
		
		$(this).parent().parent().removeClass('selected');
		var pare = $(this).parent().parent();		
		$('.info',pare).hide();
		$('.cierre',pare).hide();		
		$('.menysinfo',pare).hide();		
		$('.mesinfo',pare).show();
		$('.fragments',pare).show();		
		
	});	
	
 
 	$('.llistatcancons ul>li>p.escoltar a').click(function(){
 		$(this).parent().parent().contents('.escoltar').hide();
 		$(this).parent().parent().contents('.player.show').show();
		
 		return false;
 	});	
	
	
	 //ENSENYA O AMAGA FRAGMENTS DEL LLIBRE
 	$('.llistatcancons ul>li>p.fragments a').click(function(event) {
		event.preventDefault();
		
		$(this).parent().parent().addClass('selected');
		var pare = $(this).parent().parent();		
		$('.frag',pare).show();
		$('.cierre_frag',pare).show();		
		$('.fragmentsmenysinfo',pare).show();		
		$('.mesinfo',pare).hide();
		$('.fragments',pare).hide();
		
	});
	
	
	$('.llistatcancons ul>li>p.fragmentsmenysinfo a').click(function(event) {
  		event.preventDefault();
		
		$(this).parent().parent().removeClass('selected');
		var pare = $(this).parent().parent();		
		$('.frag',pare).hide();
		$('.cierre_frag',pare).hide();
		$('.fragmentsmenysinfo',pare).hide();
		$('.mesinfo',pare).show();
		$('.fragments',pare).show();	
		
	});
	
	
 
 	//TABS: HOVER
 	$('#tabs ul>li').hover(function(){
 		if($(this).hasClass('actiu')) return false;
 		else $(this).addClass('selected');
 		
 		return flase;
	},
	function(){
 		if($(this).hasClass('actiu')) return false;
 		else $(this).removeClass('selected');
		return flase;
	});
 
 	//TABS: CANVIA DE PESTANYA
 	$('#tabs ul>li>a').click(function(){
 		
 		//El dom no calcula bé el total d'alçada, el forcem:
 		//$('#cols').height(ORIGINAL_LT_SIZE);
 		
 		$('#tabs ul>li.selected').removeClass('selected');
 		$('#tabs ul>li.actiu').removeClass('actiu');
 		
 		$(this).parent().addClass("selected");
 		$(this).parent().addClass("actiu");
 		
 		$('.tab.selected').removeClass('selected');
 		$('#'+$(this).parent().attr('title')).addClass('selected');
 		
 		/*/El dom no calcula bé el total d'alçada, el forcem:
		//aixo es perque el IE crida l'event de redimensionar si es canvia el height, ho evitem l'accio de reposicionament
		DO_NO_RESIZE=true;
 		//Forcem el tamany original la posició original
 		alturat = $('.tab.selected').height() - alturat1;
 		$('#cols').height(ORIGINAL_LT_SIZE+alturat);
 		setTimeout("DO_NO_RESIZE=false;",100);*/

 		//~ ajaxSite_DoHit();
 		
 		return false;
	});
 
 	//Desplega la galería de videos MAXIMITZA/MINIMITZA
 	$('.bottom.despl a').click(function(){
 		

			//El dom no calcula bé el total d'alçada, el forcem:
			//$('#cols').height(ORIGINAL_LT_SIZE);
			
			$('.SSG.'+$(this).attr('rel')+' .news_items p.view_all a').click();
			
			if($(this).attr('name')=='video'){
				if($(this).text().indexOf("LLISTAT COMPLET DE VÍDEOS") != -1) $(this).text('MINIMITZA');
				else $(this).text('LLISTAT COMPLET DE VÍDEOS');
			}
			if($(this).attr('name')=='imatge'){
				if($(this).text().indexOf("LLISTAT COMPLET D'IMATGES") != -1) $(this).text('MINIMITZA');
				else $(this).text("LLISTAT COMPLET D'IMATGES");
			}
				
			alturav = $('.SSG.'+$(this).attr('rel')).height() - alturav1;
			//$('#cols').height(ORIGINAL_LT_SIZE+alturav);
			return false;

 		
	});
    
    //onchange del SELECT COMARQUES  
    $('#comarca').change(function(){	
		document.location = $(this).val();
	});
     
    //Hover de la img del boto next del carousel de thumbs de videos
    $('.next img').hover(function(){
    	$(this).attr({src:'/marato/img/next_over.gif'});
    },
    function(){
    	$(this).attr({src:'/marato/img/next.gif'});
    });
    
    //Hover de la img del boto prev del carousel de thumbs de videos
    $('.prev img').hover(function(){
    	$(this).attr({src:'/marato/img/prev_over.gif'});
    },
    function(){
    	$(this).attr({src:'/marato/img/prev.gif'});
    });
    
	$('ul.dropdown>li').hover(function(){
		
		if(!$(this).hasClass('idiomes')){
			
			$(this).addClass("hover");
			try {clearTimeout(ID_TM);}catch(e){}

			if(actual!='') $('#'+actual).removeClass('on');
			else actual = $('ul.dropdown>li.active').attr('id');
			
			if(actual!=$(this).attr('id')){
				
				$('.subm').stop(true,true);
				$('.subm').hide();
				$('ul',this).slideDown('fast');
				
			}
			
			$('ul.dropdown>li.active').removeClass('on');
			$(this).addClass('on');
			
			//if($(this).hasClass('on')) alert('si')
			actual = $(this).attr('id');
			
			
			return false;
		}
		else return false;
	},
	function (){
		
		try {clearTimeout(ID_TM);}catch(e){}
		
		actual = $(this).attr('id');		
	
		if($(this).hasClass('active')) {
			return false;
		}else{
			ID_TM = setTimeout(hideOverMenus,300);
			return false;
		}
	});



	$('.subm').hover(function(){
		try {clearTimeout(ID_TM);}catch(e){}
		return false;
	},
	function (){
		try {clearTimeout(ID_TM);}catch(e){}
		if($(this).hasClass('active')) {
			return false;
		}else{
			ID_TM = setTimeout(hideOverMenus,300);
			return false;
		}
	});


	$('ul.dropdown>li>ul.subm>li').hover(function(){
		
		try {clearTimeout(ID_TM);}catch(e){}
		
		$(this).addClass('on');
		
		return false;
	},
	function (){
		try {clearTimeout(ID_TM);}catch(e){}

		if(!$(this).hasClass('active')){
			$(this).removeClass('on');
		}
		
		if($(this).parent().parent().hasClass('active')) {	
			return false;
		}else{
			ID_TM = setTimeout(hideOverMenus,300);
			return false;
		}
	});
	
	
	$('.idiomes>ul>li').hover(function(){
		$(this).addClass('on');
		return false;
	},
	function (){
		if(!$(this).hasClass('active')){
			$(this).removeClass('on');
		}
		return false;
	});

});

jQuery(document).ready(function() {
	
 	$('.idiomes>ul>li.active').addClass('on');
	$('ul.dropdown>li>ul.subm>li.active').addClass('on');
	$('ul.dropdown>li.active').addClass('on');
	
	$('ul.dropdown>li.active').addClass("hover");
	$('ul.dropdown>li.active>ul.subm').slideDown('fast');


/*		//posicionament de la barra
		ORIGINAL_LT_SIZE = $('#cols').height();
		var off = $(window).height() - $('#cols').height() - 340 - 82;
		if(off < 0 ) off = 0;
		$('#cols').height(ORIGINAL_LT_SIZE + off);
		altura1 = $('.infoCd.selected').height();
		alturat1 = $('.tab.selected').height();
		alturav1 = $('.SSG.categoria1').height();
		//~ alturaL1 = $('.SSG.categoria1').height();
	//~ if(NO_CALC_BOT != true){
		$(document).resize(calcBottom);
		$(window).resize(calcBottom);
	//~ }	
*/
	 jQuery('.SSG').each(function(){

		if(jQuery(this).height()%2==0){
			jQuery(this).css({paddingBottom:'8px'});
		}
     });

});


function pintaHistoricComptes(i){
var str = '<div class="destacat blue">'+
        '<div class="botonssimpblau">'+
        '<span class="tit-historic-comptes">Històric de comptes</span></a>'+
        '</div>'+
        '<div class="cos forceVisibility">'+
          '<div class="historic_comptes">'+
		  '<ul>'+
              '<li class="first2"></li>'+
              '<li><a title="comptes" href="http://www.tv3.cat/marato/comptes">&Uacute;ltim exercici: gener – desembre 2010</a></li>'+
              '<li><a title="comptes_09_10" href="comptes_09_09.htm">Juliol &ndash; desembre 2009</a></li>'+
              '<li><a title="comptes_08_09" href="comptes_08_09.htm">Juliol 2008 &ndash; juny 2009</a></li>'+
              '<li><a title="comptes_07_08" href="comptes_07_08.htm">Juliol 2007 &ndash; juny 2008</a></li>'+
              '<li><a title="comptes_06_07" href="comptes_06_07.htm">Juliol 2006 &ndash; juny 2007</a></li>'+
              '<li><a title="comptes_05_06" href="comptes_05_06.htm">Juliol 2005 &ndash; juny 2006</a></li>'+
              '<li><a title="comptes_04_05" href="comptes_04_05.htm">Juliol 2004 &ndash; juny 2005</a></li>'+
              '<li><a title="comptes_03_04" href="comptes_03_04.htm">Juliol 2003 &ndash; juny 2004</a></li>'+
              '<li><a title="comptes_02_03" href="comptes_02_03.htm">Juliol 2002 &ndash; juny 2003</a></li>'+
              '<li><a title="comptes_01_02" href="comptes_01_02.htm">Juliol 2001 &ndash; juny 2002</a></li>'+
              '<li><a title="comptes_00_01" href="comptes_00_01.htm">Juliol 2000 &ndash; juny 2001</a> </li>'+
              '<li><a title="comptes_99_00" href="comptes_99_00.htm">Juliol 1999 &ndash; juny 2000</a></li>'+
              '<li><a title="comptes_gener_juny_1999" href="comptes_gener_juny_1999.htm">1999 (Gener &ndash; juny)</a> </li>'+
              '<li><a title="comptes_gener_desembre_1998" href="comptes_gener_desembre_1998.htm">1998 (Gener &ndash; desembre)</a></li>'+
              '<li><a title="comptes_gener_desembre_1997" href="comptes_gener_desembre_1997.htm">1997 (Gener &ndash; desembre)</a></li>'+
              '<li><a title="comptes_gener_desembre_1996" href="comptes_gener_desembre_1996.htm">1996 (Gener &ndash; desembre)</a></li>'+
              '<li class="last">&nbsp;</li>'+
            '</ul>'+		  
          '</div>'+
        '</div>'+
      '</div>'
document.write(str);

$("li > a",".historic_comptes").eq(i).addClass("dins");

}

