if (window.console){	var c=console.log}
$(function(){ 
	if(_('banner-inner')){	$('#banner-inner').cycle({random:false,delay:2000,cleartype:  true,  cleartypeNoBg:true})	}
	if(_('home-events')){	$('#home-events').cycle({ delay:1100,fx:'scrollVert',cleartype:  true,  cleartypeNoBg:true})	}
	if(_('banner-overlay')){	$('#banner-overlay').cycle({ delay:2000,cleartype:  true,  cleartypeNoBg:true})	}
	
	
	})
function _(id){return document.getElementById(id)}
function is_email(_s){return (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/).test(_s);}
function  ajax_submit(f,return_funct){
	method 	= f.method.toUpperCase()
	data	= $(f).serialize()
	uri		= method=='POST' ? f.action : f.action + '?'+data
	$.ajax({    type: method
			   ,url: uri
			   ,data: data
			   ,success: function(msg){    return_funct(  msg );   }})		
	return false
}
function Document(){
	that = this
	this.load = function(){
		that.home_event()
		that.font_change()
		that.diaz_link()
		that.gallerie()
	}
}

Document.prototype.font_change = function(){
	if (!document.getElementById('f-size')){ return}
	change = function(s){
		size = s=='+' ? 16 : (s=='-') ? 12 : 13	
		$('.box-cont').css({fontSize:size})
	}
	$('#f-size small').click(function(){change('-')})
	$('#f-size span').click(function(){change('=')})
	$('#f-size big').click(function(){change('+')})
}
Document.prototype.home_event = function(){
	if (!document.getElementById('home-event-cont')){return} ;	
	iCurr 	= 1
	image_h = 143
	delay	= 4000
	speed	= 1000
	get_cont	= function(){
		return ['<strong>Compétition trimestrielle</strong><br />Découvrez sans plus attendre tous les résultats'
				,'<strong>123 trimestrielle</strong><br />Découvrez sans plus attendre tous les résultats'
				,'<strong>456 trimestrielle</strong><br />Découvrez sans plus attendre tous les résultats']
	}
	move_flip	= function(){   
		$('#home-event-text').html(cont_a[iCurr])
		$('#home-event-cont img').animate({top: pos_y},speed,process)
	}
	pos_y	= 0
	process = function(){
		pos_y	= -(image_h * iCurr)
		setTimeout( move_flip  ,delay   );
		iCurr++
		if (iCurr == 3){iCurr = 0}
	}
	cont_a = get_cont()
	process()
}
Document.prototype.popup = function(URL){
	var width 		= 800
	var height 		= 600
	var scrollbarS 	= "1"
	var viewer	 	= "no"
	id = (new Date()).getTime();
	if (viewer == "no") {
		uri = "page" + id + " = window.open(URL, '" + id 
		uri += "', 'toolbar=0,scrollbars=' + scrollbarS + ',location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height+'');"
		eval(uri);
	}else{ 
		if (viewer == "yes") {
			eval("page" + id + " = window.open(URL);");
		}
	}
}
Document.prototype.diaz_link = function(){
	call_ajax = function(uri,toObj,func){
		$.ajax({   url:uri,type:'get',success:function(ret){	$('#'+toObj).html(ret) ; if (func){eval(func +'()')}		 }	})
	}
	process_uri = function(params){
		ap = params.substring(params.indexOf('#')+1).split('/') // objreturn / url(no .php) / param / value / ?? func ??
		if (!ap[0]){return}
		uri = 'ajax/'+ap[1]+'.php?'+ap[2]+'='+encodeURIComponent(ap[3])
		func =  (ap.length == 5) ? 	ap[4] : null
		call_ajax(uri,ap[0],func)
	}
	set_class = function(){
		$('a[href^=#]').each(function(){this.className=''})	
	}
	$('a[href^=#]').click(function(){
		process_uri(this.href)
		set_class()
		this.className = 'selected'
	})
	if ( document.location.href.indexOf('#') > -1){
		process_uri(document.location.href)
		set_class()
		slink = document.location.href.substring(document.location.href.indexOf('#'))
		$('a[href='+slink+']').addClass('selected')
	}
}
Document.prototype.reload = function(){
	window.location.href = window.location.href  //pathname ;
}
Document.prototype.gallerie = function(){
	speed	= 500 
	return
	a_click = function (_a){
		_link = $(_a)
		_link.click(
			function(){
			_img = $(this).find('img')
			img_h = $('#gallerie-img-x').attr('src',this.href).height()
			screen_h = $(window).height()
			if (img_h >= screen_h){ img_h = screen_h -100}
			if (img_h < 1 ){ img_h = 100 }
			
			xtop = (screen_h - img_h) / 2			
			$('#gallerie-img-mask').css({display:'block'}).animate({opacity:0.9},speed)
			$('#gallerie-img-box').css({display:'block',height:img_h,top:xtop}).animate({opacity:1.0},speed)
						
			$('#gallerie-img-loading').attr('src',_img.attr('src')).attr('src',this.href).css({display:'block',opacity:1.0,maxHeight:img_h})
			
			return false
		  })				
	}
	$('a[href$=.jpg]').each(function(){
		// my preloader hope it doing somthing
		$('#gallerie-img-x').attr('src',this.href)
		a_click(this)
	})	
	html = '<img id="gallerie-img-x" style="display:none; position:absolute" /><div style="width:100%; position:fixed; z-index:999; top:10%; left:0; " id="gallerie-img-box">'
	html += '<img id="gallerie-img-loading" src="images/loading.gif" alt="Loading..." style="display:none;margin:0 auto;" /></div>'
	html += '<div style="height:1px;"></div>' // eventuelle left right buttons
	html += '<div id="gallerie-img-mask" '
	html += 'style="height:100%; width:100%; position:fixed; background:#333; display:block; left:0; top:0; z-index:100; display:none; cursor:pointer" ></div>'
	
	$('body').append( html )	
	$('#gallerie-img-loading, #gallerie-img-mask, #gallerie-img-box').css({cursor:'pointer',opacity:0.0})
			.click(function(){ 
				$('#gallerie-img-loading, #gallerie-img-mask, #gallerie-img-box')
					.animate(
									 {opacity:0.0}
										 ,100
											 ,function(){ $(this).css({display:'none'})	})
					})
	
}
doc = new Document

$(document).ready(doc.load)



function xinha_init(){
	var xinha_plugins =[ ];
	var xinha_editors =[ 'editor' ];
  if(!Xinha.loadPlugins(xinha_plugins, xinha_init)) return;
  var xinha_config = new Xinha.Config();
  //xinha_config.height 	= 300
  //xinha_config.width 	= 510
  xinha_config.toolbar =  [
	      [ "popupeditor","htmlmode","separator","bold","italic","underline","forecolor"
		   ,"separator","insertunorderedlist" /*,"outdent","indent"*/
		   ,"separator","insertimage","createlink"	   
		   ,"separator","killword","clearfonts","removeformat"
		   ,"separator","justifyleft","justifycenter","justifyright","justifyfull"		   
		   ,"separator","undo","redo" /*,"inserttable"*/
		  ]
	  ];
  xinha_config.pageStyle = 'body{ font-family:Arial;font-size:13px; margin:0;padding:30px}';
 xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
 Xinha.startEditors(xinha_editors);
}