/**
*tag -- tag name. such as "div", "span"
*name_av -- value of "name" attribute inside tag.
**/

var auto_height = {};
auto_height.getElementsByName = function (tag,eltname){ 
	var elts=document.getElementsByTagName(tag); 
	var count=0; 
	var elements=[]; 
	for(var i=0;i<elts.length;i++){ 
		if(elts[i].getAttribute("name")==eltname){ 
			elements[count++]=elts[i];
		} 
	}
	return elements; 
} 

auto_height.maxHeight = function ( tag,name ){
	var els = auto_height.getElementsByName(tag, name);
	var h = "";
	for (var i=0;i<els.length;i++){
		h += els[i].clientHeight + ",";
	}
	h = h.slice(0, -1);
	h = eval('Math.max('+h+')');
	
	return h;
}	

auto_height.sameHeight = function (tag, name,h){
	var els = auto_height.getElementsByName(tag, name);
	
	if( !(h>0) ){
		
		h = auto_height.maxHeight( tag, name );
	}
	
	for (var j=0;j<els.length;j++){
		els[j].style.height = h+'px';
	}
}

function autoHeight_all(left, mid, right,hgt){
	var max = 0;
	
	for ( var i=1;i<=left;i++ ){
		if( document.getElementById( "height_anchor_1_"+i ).offsetHeight > max ){
			max = document.getElementById( "height_anchor_1_"+i ).offsetHeight;
		}
	}

	for ( var i=1;i<=mid;i++ ){
		if( document.getElementById( "height_anchor_2_"+i ).offsetHeight > max ){
			max = document.getElementById( "height_anchor_2_"+i ).offsetHeight;
		}
	}
	
	for ( var i=1;i<=right;i++ ){
		if( document.getElementById( "height_anchor_3_"+i ).offsetHeight > max ){
			max = document.getElementById( "height_anchor_3_"+i ).offsetHeight;
		}
	}
	
	for ( var i=1;i<=left;i++ ){
		max_1 = max+15;
		document.getElementById( "height_anchor_1_"+i ).style.height = max_1 +'px';
	}
	
	for ( var i=1;i<=mid;i++ ){
		max_2 = max+15;
		document.getElementById( "height_anchor_2_"+i ).style.height = max_2 +'px';
	}
	
	for ( var i=1;i<=right;i++ ){
		max_3 = max;
		document.getElementById( "height_anchor_3_"+i ).style.height = max_3 +'px';
	}
	
	max = max+40;
	
	document.getElementById( "slider_box_1" ).style.height = max +'px';
	document.getElementById( "slider_box_2" ).style.height = max +'px';
	document.getElementById( "slider_box_3" ).style.height = max +'px';
	
}

 function display_submenu(cid,total)
{	   	  
	  document.getElementById('first').style.display='none';
	  for(i=1;i<=total;i++)
	  {
	  	document.getElementById('submenu'+i).style.display='none';
	  	
	  	document.getElementById('main_menu_left'+i).className = 'main_menu_left';
	  	document.getElementById('main_menu_repeat'+i).className = 'main_menu_repeat';
	  	document.getElementById('main_menu_right'+i).className = 'main_menu_right';
	  }
	  
	  document.getElementById('submenu'+cid).style.display='inline';	 
	  
	  document.getElementById('main_menu_left'+cid).className = 'main_menu_left_active';
	  document.getElementById('main_menu_repeat'+cid).className = 'main_menu_repeat_active';
	  document.getElementById('main_menu_right'+cid).className = 'main_menu_right_active';	   	  
	    	  
}

function recoverMenu(total)
{
	  document.getElementById('first').style.display='none';
	  for(i=1;i<=total;i++)
	  {
	  	document.getElementById('submenu'+i).style.display='none';
	  	
	  	document.getElementById('main_menu_left'+i).className = 'main_menu_left';
	  	document.getElementById('main_menu_repeat'+i).className = 'main_menu_repeat';
	  	document.getElementById('main_menu_right'+i).className = 'main_menu_right';
	  }
}

function page_change(obj,site,lang,page){
	var objPageNum = obj;
	var value = objPageNum.options[objPageNum.selectedIndex].value;
	document.location = site + '/'+ page +'?start_num=' + value + '&lang='+lang+'&var_mode=recalcul';
}

function ajax_login_off(lang){
    $.ajax({
     type: "GET",
     url: "spip.php?page=login_check",
     data:"lang="+escape(lang)+"&type=loginoff",
     success: function( html ){ 
        //alert(html);
        //if(check_exites(html)){
            $('#islogin').html(html);
            $('.welcome_info').html('');
        //}
     }
    });
}

function check_exites( obj ){
    
    reg = /.*true.*/;
    if(reg.test(obj)){    
        return 1;   
    }
    
    reg = /.*false.*/;
    if(reg.test(obj)){
        return 0;
    }
    
}

$(document).ready(function() {
  $('.rss').click(function() {
    _gaq.push(['_trackEvent', 'rss', 'clicked', $(this).attr('title')]);
  });
  $('.adl').click(function() {
    _gaq.push(['_trackEvent', 'download', 'clicked', $(this).attr('title')]);
  });
});
