/*
 * Created by Endymis Media
 * http://www.endymis.fr/
 *
 * Copyright 2011-2012, Nicolas Nunge, Endymis Media
 * Package: Backstage Rodeo Official Website
 */
 
/*function removeHomeSection () {
	$(".homeSectionC").animate({
		top: "-=1500"
	}, 500)
}

function goHome() {
	$(".homeSectionC").animate({
		top: "10%"
	}, 500)
	$(".homeSectionC").fadeIn('slow');
}*/

var isHome = 1;

function removeHomeSection () {
	$(".homeSectionC").animate({
		top: "-1500px"
	}, 500)
}

$(document).ready(function(){
	$(window).hashchange(function(){
		var arg = window.location.hash.substring(3);
		var link = "http://www.backstagerodeo.com/"+arg;
		if(arg == 'home') {
			$(".homeSectionC").animate({
				top: "10%"
			}, 500)
			$(".homeSectionC").fadeIn('slow');
			$("#mainContent").animate({left: '-9999px'}, 400);
			isHome = 1;
		} else if(arg == 'forums/') {
			window.location.href = 'http://forums.backstagerodeo.com';
		} else {
			$.ajax({
				url:link,
				processData:true,
				dataType:'html',
				cache: false,
				success:function(data){
					//console.log(data);
					data = innerShiv(data,false); //on passe le résultat dans innershiv
					var title = $(data).filter('title').text(); //on trouve le titre de la page
					document.title = title; //on change le titre
					var contenu = $(data).filter('div#mainContent');
					if(isHome == 1) {
						removeHomeSection();
						$('#mainContent').html(contenu.html()).animate({left: '400'}, 500, function(){ //on masque le contenu à changer...
							Shadowbox.clearCache();
							if(arg == 'presse/') {
								Shadowbox.setup('a.presseLink', {handleOversize: "drag"});
							} else {
								Shadowbox.setup();
							}
							isHome = 0;
						});
					} else {
						$('#mainContent').fadeOut(200, function(){ //on masque le contenu à changer...
							$(this).html(contenu.html()).fadeIn(200, function() {
								Shadowbox.clearCache();
								if(arg == 'presse/') {
									Shadowbox.setup('a.presseLink', {handleOversize: "drag"});
								} else {
									Shadowbox.setup();
								}
							});
						});
					}
					/*var contenu = $(data).find("#mainContent"); //on trouve la balise qui nous intéresse
					$('#mainContent').fadeOut('200',function(){ //on masque le contenu à changer...
						console.log(contenu);
						$(this).html(contenu.html()).fadeIn('200'); //...puis on charge le nouveau et on affiche
					});*/
				}
			});
		}
	});
	
	if(window.location.hash.substring(3)!=''){
		$(window).trigger( 'hashchange' );
	}
	
	$(function() {
	    $('img[data-hover]').hover(function() {
	        $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp');
	    }).each(function() {
	        $('<img />').attr('src', $(this).attr('data-hover'));
	    });;
	});
});
