$(function(){
	initFormFocus();
	initTabs();
	initFormFocusShare();
	initMenu();
	
	
	// Footer hover
	$('#menuFooter li').hover(function(){$(this).addClass('hover')}, function(){$(this).removeClass('hover')});
	
	$("#paristechlogo").mouseover( function() { $("#backtohome").css("display","block");});
	$("#paristechlogo").mouseout( function() { $("#backtohome").css("display","none");});
});


function getBrowser () {
	var IE6 = false, IE7 = false,
		FIREFOX2 = false, FIREFOX = false,
		NETSCAPE7 = false, NETSCAPE = false,
		OPERA9 = false, OPERA = false,
		AUTRE = false;
		
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChStart = strChUserAgent.substring(0,intSplitStart);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	var strChEnd = strChUserAgent.substring(strChEnd);
	
	if(strChMid.indexOf("MSIE 7") != -1)
		IE7 = true;
	else if(strChMid.indexOf("MSIE 6") != -1)
		IE6 = true;
	else if(strChEnd.indexOf("Firefox/2") != -1)
		FIREFOX2 = true;
	else if(strChEnd.indexOf("Firefox") != -1)
		FIREFOX = true;
	else if(strChEnd.indexOf("Netscape/7") != -1)
		NETSCAPE7 = true;
	else if(strChEnd.indexOf("Netscape") != -1)
		NETSCAPE = true;
	else if(strChStart.indexOf("Opera/9") != -1)
		OPERA9 = true;
	else if(strChStart.indexOf("Opera") != -1)
		OPERA = true;
	else
		AUTRE = true;
		
	return FIREFOX;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

// Form focus
function initFormFocus(){
	$('#ins_news, #s, #share_link').focus(function(){
		if($(this).attr('value') == this.defaultValue) $(this).attr('value', '');
	}).blur(function(){
		if($.trim(this.value) == '') this.value = (this.defaultValue ? this.defaultValue : '');
	}); 
}

function initFormFocusShare(){
	$('#share_link').focus(function(){
		$("fieldset").slideDown("slow");
	}); 
}

// Tabs (sidebar & footer)
function initTabs(){
	$('.tabsContainer').each(function(){
		var content = $(this);
		$(this).find('.menu a').click(function(){
			if(content.hasClass('.activeLi')){
				content.find('.menu li').removeClass('active');
				$(this).parent().addClass('active');
			}else{
				content.find('.menu a').removeClass('active');
				$(this).addClass('active');
			}
			
			content.find('.tab').hide();
			content.find('#'+$(this).attr('rel')).show();
			
			// Popular
			if($(this).attr('rel') == 'comPopular'){
				content.addClass('tabPopular');
			}else{
				content.removeClass('tabPopular');
			}
			
			return false;
		});
	});
}

// Main Menu
function initMenu(){
	$('#mainMenu > li').hover(function(){
		$('#mainMenu li').removeClass('active');
		$(this).addClass('active');
		$(this).find('ul').show();
	}, function(){
		$(this).removeClass('active');
		$(this).find('ul').hide();
	});
}


