
// Function for displaying hint text in text inputs
// http://web.covertprestige.info/test/45-champ-formulaire-texte-au-focus.html

function textInputDynamicValue (input_selector, text_to_use, def_class) {
	if (text_to_use == undefined) text_to_use = 'title';
	if (def_class == undefined) def_class = 'hint';
	$(input_selector).each(function() {
		var dynamic_value
		switch (text_to_use) {
			case 'title' :
				dynamic_value = $(this).attr('title');
				break;
			case 'value' :
				dynamic_value = $(this).attr('value');
				break;
			default :
				dynamic_value = text_to_use;
		}
		$(this).attr('value', dynamic_value).addClass(def_class)
		.focus(function() {
			if (this.value == dynamic_value) {
				this.value = '';
				$(this).removeClass(def_class);
			}
		})
		.blur(function() {
			if (this.value == '') {
				this.value = dynamic_value;
				$(this).addClass(def_class);
			};
		});
	});
};

$(document).ready(function(){
	textInputDynamicValue('input.use-hint');
	
	/*EUROTWEETS.eu
	if needed on more than one page, please add it in an externale JS file*/
	var cfg={
		/*configurations*/
		btn_countries:"#btn_countries",
		tab_countries:"#o_countries",
		btn_parties:"#btn_parties",
		tab_parties:"#o_parties",
		btn_translate:"#btn_translate",
		tab_translate:"#o_translate",
		tab_btn_close:".tab_btn_close",
		mask:"#mask"
	}
	var addMask=function(){
		//adding a mask
		$("body").prepend('<div id="'+cfg.mask.substring(1,cfg.mask.length)+'" style="height:'+$("body").height()+'px;">&nbsp;<\/div>');
		$(cfg.mask).bind("click",function(){
			$(cfg.tab_countries+","+cfg.tab_parties+","+cfg.mask).hide();
			//$("body").css({overflow:"auto"});
		});
	}
	var showTab=function(id,elm){
		//show and position selected tab
		//$("body").css({overflow:"hidden"});
		$(cfg.mask).show();
		$(id).css({top:$(elm).offset().top-8+'px',left:$(elm).offset().left-6+'px'}).show();
	}
	
			addMask.call();
		//binding events
		$(cfg.btn_countries).bind("click",function(e){showTab(cfg.tab_countries,cfg.btn_countries);return false;});
		$(cfg.btn_parties).bind("click",function(e){showTab(cfg.tab_parties,cfg.btn_parties);return false;});
		$(cfg.btn_translate).bind("click",function(e){showTab(cfg.tab_translate,cfg.btn_translate);return false;});
		
		//close button
		$(cfg.tab_btn_close).each(function(){
			var that=this;
			$(this).bind("click",function(){$(that).parents(".tab_wrapper").hide().end();return false;});
		});

});


// Function for hiding and then displaying the login form

$(document).ready(function(){
	$('#login').hide();
	$('#user .main strong.button').replaceWith('<a class="button" href="#login">Log in</a>')
	$('#user .main a.button').click(function(){
		$('#login').show();
		$("#post").hide();
		$("#username").focus();
//		$(this).replaceWith('<strong class="button">Log in</strong>')
		return false;
	});
});


// Hover effets for IE6

$(document).ready(function(){
	$('#activity .tweet').hover(function(){
		$(this).addClass('tweet-hover');
	},
	function(){
		$(this).removeClass('tweet-hover');
	});
});

