// IE detection

var IE6 = false;

var detect;
detect = navigator.userAgent.toLowerCase();
var OS,browser,total,thestring;
var version = 0;
var ie;

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

if (checkIt('msie')){
	browser = "Internet Explorer";
	ie = true;
}else{
	ie = false;	
}

if (!version) {
	version = detect.charAt(place + thestring.length);
}

if (version <= 6){
	IE6 = true;
}

$(document).ready(function() {
	// Menu action

	$('#menu li:not(#currentPage, #blogLi)').mouseover(function(){
		$(this).children('.menuTxt').children('.menuLink').children('a').css('color', '#ea3e16');
		$(this).children('.menuTxt').children('.menuLine').css("border-left", "#ea3e16 1px solid");
	}).mouseout(function(){
		$(this).children('.menuTxt').children('.menuLink').children('a').css('color', '#c48e00');
		$(this).children('.menuTxt').children('.menuLine').css("border-left", "#c8a342 1px solid");
	});
	

	
	var bodyID = $('body').attr('id');
	
	if(bodyID != "home"){
		// Rollover logo
		$('#logotop').mouseover(function(){
			$(this).children('a').children('img').stop().animate({"opacity":"0"}, 300);
		}).mouseout(function(){
			$(this).children('a').children('img').stop().animate({"opacity":"1"}, 300);
		});
	}
	
	$('a.fadeout').css("opacity", "1");
	
	$('a.fadeout').mouseover(function(){
		$(this).stop().animate({"opacity": "0"});
	}).mouseout(function(){
		$(this).stop().animate({"opacity": "1"});
	});
	
	if(bodyID == "work"){
		// On s'occupe des créas
		var param = document.location.search;
		var num;
		if(param == ""){
			// Pas de paramètres, afficher la premiere créa
			num = 1;
		}else{
			// Parametre, on récupere le numéro et on affiche la créa correspondante
			num = param.indexOf("w");
			num = param.substr(num+2);
			
			var calc = 11 + ((num - 1) * 18);
			$('#arrowCrea').stop().animate({"margin-top": calc + "px"});
			$('html,body').stop().animate({scrollTop: "650px"}, 1500);
		}
		$.ajax({
                type: "POST",
                url: "work/crea"+num+".html",
                success: function(resp){
                    $('#workzone').append(resp);
					$('#slider').nivoSlider({manualAdvance:true, effect: 'fade'});
                }
         });
		 
		 $('#p'+num).css("color", "#ea3e16");
	}
	
	$('.pjt').click(function(){
		var n = $(this).attr('id').substr(1);
		
		var calc = 11 + ((n - 1) * 18);
		$('#arrowCrea').stop().animate({"margin-top": calc + "px"});
		
		$.ajax({
                type: "POST",
                url: "work/crea"+n+".html",
                success: function(resp){
					$('.pjt').css("color", "#c8a342");
                    $('#workzone').stop().animate({"opacity": "0"}, 300, function(){
						$('#p'+n).css("color", "#ea3e16");
						$('#workzone').empty().append(resp).animate({"opacity" : "1"}, 300);
						$('#slider').nivoSlider({manualAdvance:true, effect: 'fade'});
					});
                }
         });
		return false;
	});
	
	if(!ie){
		// Bouton Back to top
		$('#back').click(function(){
			$('html,body').stop().animate({scrollTop: "0px"}, 1000);
			return false;	
		});
		
		var $scrollingDiv = $('#backtop');
		$scrollingDiv.css("opacity", ($(window).scrollTop() / 1000) * 3);
		
		var coeff;
		if($('body').attr("id") == "404"){
			coeff = 5;	
		}else{
			coeff = 2;	
		}
		
		$(window).scroll(function(){
			var alpha = ($(window).scrollTop() / 1000) * coeff;
			$scrollingDiv.stop().css({"opacity" : alpha});
		});
	}
		
	// Twitter status
	$("#tweets").getTwitter({
		userName: "JeanDelbrel",
		numTweets: 2,
		loaderText: "Loading tweets...",
		slideIn: false,
		slideDuration: 750,
		showHeading: false,
		headingText: "",
		showProfileLink: false,
		showTimestamp: true
	});
	
});
