$(function() {
	showTime();
	setInterval(function() { showTime() }, 10000);

	$.facebox.settings.opacity = 0.9;
	$.facebox.settings.closeImage = site_root+'/js/jquery/plugins/facebox/closelabel.gif';
	$.facebox.settings.loadingImage = site_root+'/js/jquery/plugins/facebox/loading.gif';

	var $rightTabs = $('#rightTabs').tabs({
		selected: 0,
		select: function(event, ui) {
				$('li', $(ui.tab).closest('ul')).removeClass('active');
				$(ui.tab).closest('li').addClass('active');
			}
	});
	$rightTabs.tabs('rotate', 8000);

	jQuery("#ticker").ticker({
 		cursorList:  " ",
 		rate:        50,
 		delay:       4000
	}).trigger("play");
/*
	$('#ticker').easyticker({
		speed:	'fast',
		dureeAffichage: 5000
	});
	$().newsTicker({
  		newsList: "#ticker",
 		startDelay: 10
	});
*/

	$('div.newsletter a.b-enter').click(function() {
		var $inp = $(this).closest('div').find(':input');
		if ($inp.val() != $inp.attr('itemValue'))
		{
			$.ajax({
				type:		'POST',
				url:		site_root+'/ajax.php?a=newsletter&email='+$inp.val(),
				data:		'',
				dataType:	'json',
				success:	function (data, textStatus) {
					if ('undefined' != typeof data)
					{
						if (('undefined' != typeof data.result) && (data.result == 1))
						{
							$inp.val($inp.attr('itemValue'));
//							alert(data.message);
							$.facebox.settings.closeByClick = false;
							$.facebox('<div id="nl-added">'+newsletter_add_message+'</div>');
							$.facebox.settings.closeByClick = true;
//							window.setTimeout(function() { $(document).trigger('close.facebox'); }, 3000);
						}
					}
				}
			});
			
		}
		return false;
	}).closest('div').find(':input').each(function() {
		var $this = $(this);
		$this.focus(function() {
			if ($this.val() == $this.attr('itemValue'))
				$this.val('');
		}).blur(function() {
			if ($this.val() == '')
				$this.val($this.attr('itemValue'));
		}).trigger('blur');
	});

	$('div.find-video a').click(function() {
		var $div = $(this).closest('div');
		
		var val = trim($('input', $div).val());
		if (val.length > 0)
		{
			document.location = site_root+'/video-search/'+encodeURIComponent(encodeURIComponent(val));
		}
		return false;
	});
	$('div.find-video input').each(function() {
		var $this = $(this);
		$this.keypress(function (e) {
			functionenter("$('div.find-video a').trigger('click')",e);
		}).focus(function() {
			if ($this.val() == $this.attr('itemValue'))
				$this.val('');
		}).blur(function() {
			if ($this.val() == '')
				$this.val($this.attr('itemValue'));
		}).trigger('blur');
		
	});

	$('#search a').click(function() {
		var $div = $(this).closest('div');
		
		var val = trim($('input', $div).val());
		if (val.length > 0)
		{
			document.location = site_root+'/search/'+encodeURIComponent(encodeURIComponent(val));
		}
		return false;
	});
	$('#search input').each(function() {
		var $this = $(this);
		$this.keypress(function (e) {
			functionenter("$('#search a').trigger('click')",e);
		}).focus(function() {
			if ($this.val() == $this.attr('itemValue'))
				$this.val('');
		}).blur(function() {
			if ($this.val() == '')
				$this.val($this.attr('itemValue'));
		}).trigger('blur');
		
	});
});
function showTime()
{
    $('#time-date').html(formatDate());
}
function trim(s) {
	return s.replace(/^\s*(.*?)\s*$/, "$1");
}
function functionenter(function_name,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
   {
   eval(function_name);
   return false;
   }
else
   return true;
}

