function news() {
	loadUrl('./');
}

function club() {
	loadUrl('le-club');
}

function infos() {
	loadUrl('infos');
}

function affiliation() {
	loadUrl('affiliation');
}

function loadUrl(hash) {
	        if(hash) {
				$j("#loader").css({visibility:"visible"}); 
				$j("#loader").css({opacity:"1"});
				$j("#loader").css({display:"block"});  
				
				window.location.hash = hash;
				pageload(hash);
				
				/*if(hash == 'index') hash = '';
	            $j("#contentwrap").load(hash + " #content",'',function(){
	                if($j('img:last',this).get(0)) {
	                    $j('img:last',this).load(function(){
						$j("#loader").fadeTo(1000, 0);
	                    });
	                } else {
	                    $j("#loader").fadeTo(1000, 0);
	                }
	
				});*/
	        }
	}
	
function showNewContent() {
			$j("#loader").fadeTo(1000, 0);
	}
	
function pageload(hash) {
	        if(hash) {
	            $j("#contentwrap").load(hash + " #content",'',function(){
	                if($j('img:last',this).get(0)) {
	                    $j('img:last',this).load(function(){
	                        showNewContent();
	                    });
	                } else {
	                    showNewContent();
	                }
	
	            });
	        } else {
	            $j("#contentwrap").load(window.location.href + ' #content');
	        }
	}

$j(document).ready(function() {

	var google_analytics = "";
	// Google Analytics code
	if(google_analytics && google_analytics != "") {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");  
	jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){  
	  var pageTracker = _gat._getTracker(google_analytics);  
	  pageTracker._initData();  
	  pageTracker._trackPageview();  
	});  
	}
	
	$j('#contact').livequery('click',function(evt) {    
        $j('div.wpcf7 > form').ajaxSubmit({
            beforeSubmit: wpcf7BeforeSubmit,
            dataType: 'json',
            success: wpcf7ProcessJson
        });

        $j('div.wpcf7 > form').each(function(i, n) {
            wpcf7ToggleSubmit($j(n));
        });
		
		return false;
	});
	
	$j('#submit').livequery('click',function(evt) { 
    
	$j('#commentform').after('<div id="error"></div>');
	$j('#submit').after('<img src="http://www.shihaishinkai.com/wp-content/themes/karate/images/loading.gif" id="cloading" alt="Chargement..." />');
	$j('#cloading').hide();
	var form = $j('#commentform');
	var err = $j('#error');
	
	// WP Ajax Edit Comments hook
	if (window.AjaxEditComments) {
   	AjaxEditComments.init();
	} // end if
	
  if(form.find('#author')[0]) {
      if(form.find('#author').val() == '') {
		   err.html('<span class="error">Veuillez entrer votre nom</span>');
		   return false;
	   } // end if
		if(form.find('#email').val() == '') {
			err.html('<span class="error">Veuillez entrer une adresse email</span>');
			return false;
		} // end if
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!filter.test(form.find('#email').val())) {
			err.html('<span class="error">Veuillez entrer une adresse email valide</span>');
			if (evt.preventDefault) {evt.preventDefault();}
      return false;
		} // end if
	} // end if
	
	if(form.find('#comment').val() == '') {
		err.html('<span class="error">Veuillez entrer votre commentaire</span>');
		return false;
	} // end if
	
    $j('#commentform').ajaxSubmit({
						   
		beforeSubmit: function() {
			$j('#cloading').show();
			$j('#submit').attr('disabled','disabled');
		}, // end beforeSubmit

		error: function(request){
				err.empty();
				var data = request.responseText.match(/<p>(.*)<\/p>/);
				err.html('<span class="error">'+ data[1] +'</span>');
				$j('#cloading').hide();
				$j('#submit').removeAttr("disabled");
				return false;
		}, // end error()

        success: function(data) {
           try {
				var response = $j(".commentlist",data).html();
				var response2 = $j("#comments",data).html();

				if(response != "") {
					$j('.commentlist').append($j(".commentlist li:last",data).html());
				} else {
					$j('#respond').before(response);
				}
				if (response2 != "") {
					$j('#comments').html(response2);
				} else {
					$j('.commentlist').before(response2);
				}
				err.empty();
				$j('#cloading').hide();	
				$j('#respond').slideUp();
				$j('#submit').removeAttr("disabled");
                
            } catch (e) {
                $j('#cloading').hide();
				$j('#submit').removeAttr("disabled");
            } // end try
            
            // WP Ajax Edit Comments hook
				if (window.AjaxEditComments) {
   				AjaxEditComments.init();
				} // end if
						   
			} // end success()
			
		}); // end ajaxSubmit()
		
        return false; 
		
	}); // end form.submit()
	
	function showNewContent() {
			//$j('#contentwrap').hide('normal');
			//$j('#contentwrap').show('normal');
			$j("#loader").fadeTo(1000, 0);
	}
	
	function showLoading(){    
	        $j("#loader").css({visibility:"visible"}); 
	        $j("#loader").css({opacity:"1"});
	        $j("#loader").css({display:"block"});  
	} 
	
	function pageload(hash) {
			//showNewContent();
	        if(hash) {
	            $j("#contentwrap").load(hash + " #content",'',function(){
	                if($j('img:last',this).get(0)) {
	                    $j('img:last',this).load(function(){
	                        showNewContent();
	                    });
	                } else {
	                    showNewContent();
	                }
	
	            });
	        } else {
	            $j("#contentwrap").load(window.location.href + ' #content');
	        }
	}
		
	jQuery.history.init(pageload);
	
	$j('a.load, .navigation a, .category a').livequery('click',function(){
		var toLoad = $j(this).attr('href')+' #content';
		showLoading();
		
		var hash = $j(this).attr('href');
	    var reg=new RegExp("(http://www.shihaishinkai.com/)", "g");
	    hash = hash.replace(reg, '');
		window.location.hash = hash;
		pageload(hash);
				
		return false;
		
	});

});