function addEvent(src,evt,func){
	if (src.addEventListener){ // DOM Standard
		src.addEventListener(evt,func,false);
		return true;
	}
	else if (src.attachEvent) return src.attachEvent("on"+evt,func); // IE
	else eval('src.on'+evt+'=func'); // navigateurs sans DOM
}//addEvent

function getEvent(e){ // moulinette pour IE
	if (e==null && window.event) e=window.event;
	if (e.target==null && e.srcElement) e.target=e.srcElement;
	if (!e.preventDefault) e.preventDefault=function (){ this.returnValue=false; };
	return e;
}

function stopEvent(e){
	if (e && e.stopPropagation) e.stopPropagation();
	if (window.event) window.event.cancelBubble=true;
}

function popUp(event){
	var e=getEvent(event);
	var lien=e.target;
	while (lien.tagName.toLowerCase()!='a') lien=lien.parentNode;
	window.open(lien.href,'_blank');
	e.preventDefault();
	return false;
}//popUp

function remplaceLiens(){
	var lst=document.getElementsByTagName('a') ;
	for(var i=0;i<lst.length;i++){
		var lien=lst[i];
		if (lien.href && lien.rel && lien.rel=='externe') addEvent(lien,'click',popUp);
	}
}//remplaceLiens 

$(document).ready(function(){
	$('.switchFontSize a').easyfs();
	
	/*Remove inputValue onfocus and recall default inputValue onblur*/
	$('input, textarea', '.search').focus(function() {
		value=$(this).val();
		if($(this).val()!=="Enter keyword(s)") {
			$(this).val(value);
		}else if($(this).val()=="Enter keyword(s)"){
			$(this).val("");
		}
	}).blur(function() {
		value=$(this).val();
		if($(this).val()!=="") {
			$(this).val(value);
		}else if($(this).val()==""){
			$(this).val("Enter keyword(s)");
		}
	});
	
	jQuery.event.add(window, "load", resizeFrame);
	jQuery.event.add(window, "resize", resizeFrame);

	function resizeFrame(){
		var winH = $(window).height() - 50;
		var leftH = $('#colLeft').height();
		var rightH = $('#colRight .content').height();
		if (navigator.userAgent.indexOf("MSIE 6") != -1){
		    $('#wrapper').css('height', winH + 25)
		} else if(leftH < winH && rightH < winH - 82 - 55){
			$('#colLeft').css('height', winH );
			$('#colRight .content').css('min-height', winH - 82 - 55);
			if (rightH < winH - 82 - 55 - 35) {
			    $('#colRight .pbs').css('min-height', winH - 82 - 55 - 35);
			}
		}else if(rightH > winH - 82){
			$('#colLeft').css('height', rightH + 82 + 55 );
			$('#colRight .content').css('height', rightH );
		}else{$('#contentWrapper').css('min-height', winH)};
	}
	
	
	/*hide and show content*/
	$('.botWrapHidden').hide();
	$('.viewmore').live('click', function(){
		$('.botWrapHidden').slideToggle('slow', function(){
			var docH = $('#colRight').css('height');
			$('#colLeft').css('height', docH);
		});
		$(this).hide();
		
	});
	$('.expand').live('click', function(){
		$('.botWrapHidden').slideToggle('slow', function(){
			var docH = $('#colRight').css('height');
			$('#colLeft').css('height', docH);
		});
		
	});
	/*NyroModal for e-booklet*/
 	$('a.bookletModal').nyroModal({
 		width:		1200,
 		height:		924
 	});
	$('#disclaimer').nyroModal({
		width:		548,
		height:		445
	});
	$('.modal').nyroModal({
		width:		548,
		height:		445
	});
	$('.nyroCarousel').nyroModal({
		width:		802,
		height:		754
	});
	/*Accordeon*/
	$('.acc').accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true
	});
	
	/*tabs*/
	$('#tabs').tabs();
	
	$('#partnersLinks ul').hide();
	$('#partnersLinks>li>a').click(function(){
		$(this).next().slideToggle('fast');
		$('body').click(function(){
			$('#partnersLinks ul').hide();
		});
	});
	
	/*Internal Collective Funds*/
	$('#InternalFunds tr').hover(
			function(){
				$(this).children().children().show();
				$(this).css('background', '#f7f5f4');
			},
			function(){
				$(this).children().children().hide();
				$(this).css('background', 'transparent');
			}
		);
	
	/*recommend this page*/
	$(".share").click(function(){
		$(this).toggleClass('selected');
		$('#sendToFriends').toggle();
	});
	$('#shut').click(function(){
		$(".share").filter('.selected').removeClass('selected');
		$('#sendToFriends').hide();
	});
	
	/* target _blank XHTML supa tricks */
 	remplaceLiens();
 	
 	zebraRows('.listNews>tbody>tr:even td', 'even');  
 	
 	//default each row to visible
 	  $('.listNews>tbody>tr').addClass('visible');

 	  $('#filter').change(function(event) {

 	      //we want each row to be visible because if nothing
 	      //is entered then all rows are matched.
 	      $('.listNews>tbody>tr').removeClass('visible').show().addClass('visible');
 	    
 	    //if there is text, lets filter
 	    
 	    filter('tbody .lang', $(this).val());
 	  
 	    //reapply zebra rows
 	    $('.listNews>tbody>.visible td').removeClass('even');
 	    zebraRows('.listNews>tbody>.visible:even td', 'even');


 	}).trigger('change');

 	//language selector
 	$('.switchLang').hover(function () {
 	    $(this).addClass('switchLang-hover');
 	}, function () {
 	    $(this).removeClass('switchLang-hover');
 	});

 	//direct access (careers)
 	$('.directAccess').hover(function () {
 	    $(this).addClass('directAccess-hover');
 	}, function () {
 	    $(this).removeClass('directAccess-hover');
 	});
 	
});

//filter results based on query
function filter(selector, query) {
  query	=	$.trim(query); //trim white space
  query = query.replace(/ /gi, '|'); //add OR for regex query

  $(selector).each(function() {
    ($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).parent().hide().removeClass('visible') : $(this).parent().show().addClass('visible');
  });
}

function zebraRows(selector, className)  
{  
  $(selector).removeClass(className).addClass(className);  
}

window.oncontextmenu = function () {
	   return false;
	}

