$(function() { 

var Navigation = function() {
var me = this;
var args = arguments;
	
var self = {
c: {
navItems: '#navigation .home, #navigation .pgscellier, #navigation .pglmnp, #navigation .lois, #navigation .contact',
navSpeed: ($.browser.safari ? 600 : 350),
snOpeningSpeed: ($.browser.safari ? 400 : 250),
snOpeningTimeout: 150,

snClosingSpeed: function() {if (self.subnavHovered()) return 123450; return 150;},
snClosingTimeout: 700},
		
init: function() {
$('.level_1', this.c.navItems).css({'opacity': 0});
this.initHoverFades();
},
		
subnavHovered: function() {var hovered = false;
$(self.c.navItems).each(function() {if (this.hovered) hovered = true;});
return hovered;
},
		
initHoverFades: function() {
$('#navigation .main').append('<span class="hover"></span>');
$('#navigation .hover').css('opacity', 0);
$('#navigation .main,#snav a').hover(function() {
self.fadeNavIn.apply(this);	}, function() {
var el = this;
setTimeout(function() {if (!el.open) self.fadeNavOut.apply(el);}, 10);});
},
		
fadeNavIn: function() {$('.hover', this).stop().animate({'opacity': 1}, self.c.navSpeed);},

fadeSubnavIn: function() {var el = this; $('.level_1', this)
.stop()
.css('display', 'block')
.animate({'top': '80px','opacity': 1}, self.c.snOpeningSpeed, function() { el.open = true; });},

fadeNavOut: function() {$('.hover', this).stop().animate({'opacity': 0}, self.c.navSpeed);},

fadeSubnavOut: function() {$('.level_1', this)
.stop()
.animate({'opacity': 0}, self.c.snClosingSpeed(), function() { $(this).css({'top': '70px', 'display': 'none'}); });},
		
initSubmenus: function() {$(this.c.navItems).hover(function() {
$(self.c.navItems).not(this).each(function() {
	self.fadeNavOut.apply(this);
	self.fadeSubnavOut.apply(this);});
this.hovered = true;
if ($('.level_1', this).length == 0) return;
var el = this;
self.fadeNavIn.apply(el);
clearTimeout(el.level1);
el.level1 = setTimeout(function() {self.fadeSubnavIn.apply(el);}, self.c.snOpeningTimeout);}, 
function() {this.hovered = false;
if ($('.level_1', this).length == 0) return;
var el = this;
clearTimeout(el.level1);
if (!el.open) self.fadeNavOut.apply(el);
el.level1 = setTimeout(function() {el.open = false;
self.fadeSubnavOut.apply(el);
self.fadeNavOut.apply(el);}, self.c.snClosingTimeout);});
}
};
self.init.apply(self);
return self;
};

function d(s) {}

$(function(){new Navigation();});

function initGradients(s) {$(function() {
$(s).each(function() {var el = this;
var from = '#ffffff', to = '#000000';
var
	fR = parseInt(from.substring(1, 3), 16),
	fG = parseInt(from.substring(3, 5), 16),
	fB = parseInt(from.substring(5, 7), 16),
	tR = parseInt(to.substring(1, 3), 16),
	tG = parseInt(to.substring(3, 5), 16),
	tB = parseInt(to.substring(5, 7), 16);
var h = $(this).height() * 1.5;
var html;

if (this.initHTML)
html = this.initHTML;
else
html = this.innerHTML;
this.initHTML = html;
this.innerHTML = '';

for (var i = 0; i < h; i++) {var c = '#' +
(Math.floor(fR * (h - i) / h + tR * (i / h))).toString(16) +
(Math.floor(fG * (h - i) / h + tG * (i / h))).toString(16) +
(Math.floor(fB * (h - i) / h + tB * (i / h))).toString(16);
$('<span class="rainbow rainbow-' + i + '" style="color: ' + c + ';"><span style="top: ' + (-i - 1) + 'px;">' + html + '</span></span>').appendTo(this);}
$('<span class="highlight">' + html + '</span>').appendTo(this);
$('<span class="shadow">' + html + '</span>').appendTo(this);});
});
}

initGradients('.rainbows');

 // ANI
nof = function(btm) {
$('.hover', btm).stop().animate({'opacity': 0}, 450)
$('a span.hover', btm).css('backgroundImage', 'url(http://www.atoutfisc.com/reduction-impot/template1e/lib/i/subnavigation/sprite_subnavigation_3.jpg)');
};

oon = function(btm) { if (!$('#body').is(btm)) {
$('a span.hover', btm).css('backgroundImage', 'url(http://www.atoutfisc.com/reduction-impot/template1e/lib/i/subnavigation/3tt.jpg)');
$('.hover', btm).stop().animate({'opacity': 1}, 450);
$("em",btm).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
}};

$(function() {initTooltips({timeout: 3000}); });

function initTooltips(o) {var showTip = function() {
var el = $('.tt', this).css('display', 'block')[0];
var ttHeight = $(el).height();
var ttOffset =  el.offsetHeight;
var ttTop = ttOffset + ttHeight;
$('.tt', this)
.stop()
.css({'opacity': 0,	'top': 30 - ttOffset})
.animate({'opacity': 1,	'top': 25 - ttOffset}, 250);
};

var hideTip = function() {var self = this;
var el = $('.tt', this).css('display', 'block')[0];
var ttHeight = $(el).height();
var ttOffset =  el.offsetHeight;
var ttTop = ttOffset + ttHeight;
$('.tt', this)
.stop()
.animate({'opacity': 0,	'top': 10 - ttOffset}, 250, function() {
	el.hiding = false;
	$(this).css('display', 'none');
});
	if ($(self).hasClass('pga')) {nof('.komens')};
	if ($(self).hasClass('pgb')) {nof('.mdeux')};
	if ($(self).hasClass('pgc')) {nof('.mtrois')};
	if ($(self).hasClass('pgd')) {nof('.mquatre')};
	if ($(self).hasClass('pge')) {nof('.mcinq')};
	if ($(self).hasClass('pgf')) {nof('.msix')};
	if ($(self).hasClass('pgg')) {nof('.msept')};
	if ($(self).hasClass('pgh')) {nof('.mhuit')};
	if ($(self).hasClass('pgi')) {nof('.mneuf')};
	if ($(self).hasClass('pgj')) {nof('.mdix')};
	if ($(self).hasClass('pgk')) {nof('.monze')};
	if ($(self).hasClass('pgl')) {nof('.mouze')};
	if ($(self).hasClass('pgm')) {nof('.meize')};
	if ($(self).hasClass('pgn')) {nof('.torz')};
	if ($(self).hasClass('pgo')) {nof('.qinz')};
	if ($(self).hasClass('pgp')) {nof('.sez')};
	if ($(self).hasClass('pgq')) {nof('.dset')};
	if ($(self).hasClass('pgr')) {nof('.duit')};
	if ($(self).hasClass('pgs')) {nof('.dneuf')};
	if ($(self).hasClass('pgt')) {nof('.vun')};
	if ($(self).hasClass('pgu')) {nof('.vetun')};
	if ($(self).hasClass('pgv')) {nof('.vdeu')};
	if ($(self).hasClass('pgw')) {nof('.fin')};
};

$('.tip .tt').hover(
function() { return false; },
function() { return true; }
);

obson = function() {$('.tip').hover(
function(){var self = this;

	if ($(self).hasClass('pga')) {oon('.komens')};
	if ($(self).hasClass('pgb')) {oon('.mdeux')};
	if ($(self).hasClass('pgc')) {oon('.mtrois')};
	if ($(self).hasClass('pgd')) {oon('.mquatre')};
	if ($(self).hasClass('pge')) {oon('.mcinq')};
	if ($(self).hasClass('pgf')) {oon('.msix')};
	if ($(self).hasClass('pgg')) {oon('.msept')};
	if ($(self).hasClass('pgh')) {oon('.mhuit')};
	if ($(self).hasClass('pgi')) {oon('.mneuf')};
	if ($(self).hasClass('pgj')) {oon('.mdix')};
	if ($(self).hasClass('pgk')) {oon('.monze')};
	if ($(self).hasClass('pgl')) {oon('.mouze')};
	if ($(self).hasClass('pgm')) {oon('.meize')};
	if ($(self).hasClass('pgn')) {oon('.torz')};
	if ($(self).hasClass('pgo')) {oon('.qinz')};
	if ($(self).hasClass('pgp')) {oon('.sez')};
	if ($(self).hasClass('pgq')) {oon('.dset')};
	if ($(self).hasClass('pgr')) {oon('.duit')};
	if ($(self).hasClass('pgs')) {oon('.dneuf')};
	if ($(self).hasClass('pgt')) {oon('.vun')};
	if ($(self).hasClass('pgu')) {oon('.vetun')};
	if ($(self).hasClass('pgv')) {oon('.vdeu')};
	if ($(self).hasClass('pgw')) {oon('.fin')};

showTip.apply(this);
if (o.timeout) this.tttimeout = setTimeout(function() { hideTip.apply(self) } , o.timeout);
},
function() {clearTimeout(this.tttimeout);
hideTip.apply(this);}
);
};	
 obson();

obsoff = function() {$(".tip").unbind('mouseenter mouseleave');};
}


Object.extend = function(destination, source) {
for (property in source) {destination[property] = source[property];}
return destination;
};

var Class = {create: function() {
return function() {this.initialize.apply(this, arguments);}
}
};

String.prototype.format = function() {var params = String.prototype.format.arguments;
var toReturn = this;

for (var i = 0; i < params.length; i++) {
var regex = new RegExp('\{[' + i + ']\}', 'g');
toReturn = toReturn.replace(regex, params[i]);}
return toReturn;
};

RegExp.escape = function(text) {
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
};


var ElasticLayout = Class.create();
ElasticLayout.prototype = {
initialize: function(options) {
var dOptions = {small: 1, large: 980, cSmall: 'anorexia', cLarge: 'whale'};
this.options = Object.extend(dOptions, options);
this.addResizeHandler();
this.checkWidth();},

addResizeHandler: function() {var self = this;
$(window).resize( function() {
self.checkWidth.apply(self);});
},

checkWidth: function() {var winWidth = this.getWidth();
var changeTo;
		 
switch(true) {
case winWidth >= this.options.large: 
	changeTo = this.options.cLarge;
	break;

case winWidth >= this.options.small: 
	changeTo = this.options.cSmall;
	break;
}
if (changeTo != this.curClass) this.changeClass(changeTo);
},

getWidth: function() {
if (window.innerWidth) return window.innerWidth;
if (document.documentElement && document.documentElement.clientWidth != 0)
return document.documentElement.clientWidth;
if (document.body) return document.body.clientWidth;
return 0;
},
	
changeClass: function(cName) {$('body')
.removeClass(this.options.cSmall)
.removeClass(this.options.cLarge)
.addClass(cName);}
};

$(function() {
if ($.browser.safari) $('body').addClass('safari');
$('body').addClass('mocha');
var fadeSpeed = ($.browser.safari ? 600 : 450);
$('#logotype, #favoris, ul.features a').append('<span class="hover"></span>');
$('.hover').css('opacity', 0);
$('.hover').parent().hover(function() {$('.hover', this).stop().animate({'opacity': 1}, fadeSpeed);}, 
function() {$('.hover', this).stop().animate({'opacity': 0}, fadeSpeed);});

$('#snav a').each(function() {var html = this.innerHTML;
$(this).html( html + '<span class="cap"></span>');});

$('#trailer').html('<div class="loading"><img src="http://www.atoutfisc.com/reduction-impot/template1e/lib/i/trspix.gif?x=' + Math.random() + '" class="bar" alt="" /><img src="http://www.atoutfisc.com/reduction-impot/template1e/lib/i/trspix.gif?x=' + Math.random() + '" class="bar_reflect" alt=""/></div>');

if( $('body').is('.timeline,.freshman') ) {setTimeout(function() {
$('.#trailer').fadeOut(2500);}, 4500);
setTimeout(function() {$('.#trailer img').animate({ opacity: 0 }, 1500);}, 2700);}
else { $('#trailer').fadeOut(900);}

$('.section').each(function() {var html = this.innerHTML;
$(this).html('<div class="highlight"><div class="shadow">' + html + '</div></div>');});

$("#sideblade ul,.features").each(function(i) {
var lis = $(this).children();
lis.filter(":first").addClass("first").end().filter(":last").addClass("last");
lis.each(function(x) {
	if (x % 2 == 0) { $(this).addClass("even"); }
	if (x % 2 == 1) { $(this).addClass("odd"); }
	if (x % 4 == 3) { $(this).addClass("doubleEven"); }	})
});
});

function getURLAnchor(){var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("#") > -1 ){strReturn = strHref.substr(strHref.indexOf("#") + 1).toLowerCase();}
return strReturn;
}

});
