var v_y;
var v_x;
var _optimal;

var v_page;
var v_rubrique;

var _nom = {
    "accueil": " :: Accueil",
    "graphisme": " :: Graphisme",
    "logotype": " :: Logotype",
    "multimedia": " :: Multimédia",
	"contact": " :: Contact"
}

var _sousnom = {
	"collectiontheatrale": " :: Collection théâtrale",
    "pagesdegarde": " :: Pages de garde",
    "contrastedescouleurs": " :: Le contraste des couleurs"
}

$(document).ready(function () {
		
	style();
	
	/* --- Nav. principale */
	
	$('#entete>h1').click( function () {
		navigate('accueil');
		return false;
	});
	$('#accueil').click( function () {
		navigate('accueil');
		return false;
	});
	$('#graphisme').click( function () {
		navigate('graphisme');
		return false;
	});
	$('#logotype').click( function () {
		navigate('logotype');
		return false;
	});

	$('#multimedia').click( function () {
		navigate('multimedia');
		return false;
	});
	
	$('#contact').click( function () {
		navigate('contact');
		return false;
	});
	
	/* --- Fin nav. principale */
	
	creerSousNav();
	
	survol();
	
});

$(window).resize( function() {
	
	style();

});



function style(){
		
	v_x = document.body.clientWidth;
	
	if (self.innerHeight) {// all except Explorer
		v_y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		v_y = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		v_y = document.body.clientHeight;
	}
	
	$("#footer > p").before('<canvas datasrc="../js/processing.pjs"></canvas>');
	
	//alert( v_x + "x" + v_y );
	
	if( v_x >= 1180 && v_y >= 275 ){
		
		// Passe en affichage optimal
		_optimal = true;
		
		$("body").attr("id", function(arr) {
			$(this).removeAttr("id");
			$(this).attr("id", "optimal");
		});
		
		v_height="max-height:"+ (v_y-55) +"px;";
		
		$("#section_b").attr("style", v_height);
	
	} else{
		
		// Passe en affichage optimisé
		_optimal = false;
		
		$("body").attr("id", function (arr) {
			$(this).removeAttr("id");
			$(this).attr("id", "optimise");
		});
		
	}
	
}

function navigate(_page) {

	v_page = _page;
	
	$.ajax({
		url: "./pages/" + _page +  ".html",
		cache: false,
		success: function(_html){
			
			document.title = "Pomme+Alt+Shift+S :: Julien Gargot"+_nom[_page];
			
			$("#section_a").fadeOut(200, function() {
			$(this).html( _html ).fadeIn(500);
				survol();
				creerSousNav();
			});
			$("#section_b").fadeOut(200, function() {
				$(this).html( "" )
			});
			$("#footer > p").html("Pomme+alt+shift+s " + _nom[_page]);
		
		}
	});

}

function sousNavigate(_rubrique) {
	
	$.ajax({
		url: "pages/rubriques/" + _rubrique +  ".html",
		cache: false,
		success: function(_html){
			document.title = "Pomme+Alt+Shift+S :: Julien Gargot"+_nom[v_page]+ _sousnom[_rubrique];
				$("#section_b").fadeOut(200, function() {
					$(this).html( _html ).fadeIn(500);
					$('#gallerie > a').lightBox();
				});
				$("#footer > p").html("Pomme+alt+shift+s " + _nom[v_page] + _sousnom[_rubrique]);
				$("a").css("cursor","default");
		}
	});

}

function survol() {
	
	$("li")
	.hover(
		function () {
			$(this).children("img").fadeIn(200);
		}, 
		function () {
			$(this).children("img").fadeOut(500);
		}
	);
}

function creerSousNav(){
	
	/* --- Nav. secondaire */
	
	$('#collectiontheatrale').click( function () {
		sousNavigate('collectiontheatrale');
		return false;
	});
	$('#pagesdegarde').click( function () {
		sousNavigate('pagesdegarde');
		return false;
	});

	$('#contrastedescouleurs').click( function () {
		sousNavigate('contrastedescouleurs');
		return false;
	});
	
	$("a").css("cursor","default");
	$("#temp > a").css("cursor","pointer");
	
	/* --- Fin nav. secondaire */
	
}

