/*sIFR*/
var agendaLite = { 
		src: '/flash/AgendaLite.swf',
		ratios: [7, 1.32, 11, 1.31, 19, 1.23, 22, 1.2, 29, 1.19, 36, 1.18, 51, 1.17, 56, 1.16, 57, 1.17, 84, 1.16, 85, 1.15, 87, 1.16, 91, 1.15, 93, 1.16, 98, 1.15, 99, 1.16, 1.15]
};
var agendaBold = { src: '/flash/AgendaBold.swf' };
sIFR.activate(agendaLite, agendaBold);


if($('.sifr_h3_header') && $('.sifr_h3_header').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.sifr_h3_header',
		css: {'.sIFR-root': { 
			'color': rgb2hex($('.sifr_h3_header').css('color')),
			'font-size': '22',
			'leading': '-5'
			} 
		},
		wmode: 'transparent'
	});
}
if($('.sifr_h2_lite') && $('.sifr_h2_lite').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.sifr_h2_lite',
		css: {'.sIFR-root': { 
			'color': rgb2hex($('.sifr_h2_lite').css('color')),
			'font-size': '24',
			'leading': '-5'
			} 
		},
		wmode: 'transparent'
	});
}
if($('.sifr_h3_lite') && $('.sifr_h3_lite').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.sifr_h3_lite',
		css: {'.sIFR-root': { 
			'color': rgb2hex($('.sifr_h3_lite').css('color')),
			'font-size': '22',
			'leading': '-5'
			} 
		},
		wmode: 'transparent'
	});
}
if($('.sifr_h4_lite') && $('.sifr_h4_lite').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.sifr_h4_lite',
		css: {'.sIFR-root': { 
			'color': rgb2hex($('.sifr_h4_lite').css('color')),
			'font-size': '18',
			'leading': '-5'
			} 
		},
		wmode: 'transparent'
	});
}
if($('.sifr_h2_connect') && $('.sifr_h2_connect').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.sifr_h2_connect',
		css: {'.sIFR-root': { 
			'color': rgb2hex($('.sifr_h2_connect').css('color')),
			'font-size': '24',
			'leading': '-5'
			} 
		},
		wmode: 'transparent'
	})
}
if($('.strapline4 h4') && $('.strapline4 h4').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '.strapline4 h4',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('.strapline4 h4').css('color')),
				'background-color': rgb2hex($('.strapline4 h4').css('background-color')),
				'font-style': 'italic',
				'font-size': '12',
				'text-align': 'center' 
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	})
}


/*
 * 
 * LEGACY STRAPLINES
 * 
 */

if ($('#strapline1 h2') && $('#strapline1 h2').length > 0) {
	sIFR.replace(agendaLite, {
		selector: '#strapline1 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline1 h2').css('color')),
				'background-color': rgb2hex($('#strapline1 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center' 
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline1 h2').css('background', 'none')
}

if ($('#strapline11 h2') && $('#strapline11 h2').length > 0) {
	sIFR.replace(agendaLite, {
		selector: '#strapline11 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline11 h2').css('color')),
				'background-color': rgb2hex($('#strapline11 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center' 
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline11 h2').css('background', 'none')
}


if ($('#strapline2 h2') && $('#strapline2 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline2 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline2 h2').css('color')),
				'background-color': rgb2hex($('#strapline2 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline2 h2').css('background', 'none')
}

if ($('#strapline22 h2') && $('#strapline22 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline22 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline22 h2').css('color')),
				'background-color': rgb2hex($('#strapline22 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline22 h2').css('background', 'none')
}


if ($('#strapline3 h2') && $('#strapline3 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline3 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline3 h2').css('color')),
				'background-color': rgb2hex($('#strapline3 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline3 h2').css('background', 'none')
}

if ($('#strapline33 h2') && $('#strapline33 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline33 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline33 h2').css('color')),
				'background-color': rgb2hex($('#strapline33 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline33 h2').css('background', 'none')
}


if ($('#strapline4 h2') && $('#strapline4 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline4 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline4 h2').css('color')),
				'background-color': rgb2hex($('#strapline4 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline4 h2').css('background', 'none')
}
if ($('#strapline5 h2') && $('#strapline5 h2').length > 0)
{
	sIFR.replace(agendaLite, {
		selector: '#strapline5 h2',
		css: {'.sIFR-root': { 
				'color': rgb2hex($('#strapline5 h2').css('color')),
				'background-color': rgb2hex($('#strapline5 h2').css('background-color')),
				'font-style': 'normal',
				'text-align': 'center',
				'text-transform': 'uppercase'
			} 
		},
		fixWrap: true,
		tuneHeight: ((($.browser.msie == true) && ($.browser.version == "8.0")) ? -6 : -3)
	});
	$('#strapline5 h2').css('background', 'none')
}


if($('#start') && $('#start').length > 0)
{

	/*make rounded corner*/
	$('.trailbox .inner').corner('bottom').parent().css('padding', '0 2px 1px 2px').corner('bottom');
}

if($('#logged') && $('#logged').length > 0)
{	
	$("ul.tabs").tabs("div.panes > div"); 
}

/*account log*/
if($("#account") && $("#account").length > 0)
{
	var $offset = [];
	if($.browser.msie && ($.browser.version == "8.0")) 
	{
		$offset = [0, -273];
	}
	else if ($.browser.msie && ($.browser.version == "7.0")) 
	{
		$offset = [2, -272];
	} 
	else if ($.browser.msie && ($.browser.version == "6.0")) 
	{
		$offset = [1, -274];
	} 
	else if (!$.browser.msie)
	{
		$offset = [2, -274];
	}

	$('#account').tooltip({
		tip: '#tipbox',
		position: ['bottom', 'right'],
		offset: $offset,
		onShow: function(){
			if ( $.browser.msie && ($.browser.version == "6.0") ) 
			{
				if($('select#ville_meteo').length > 0) $('select#ville_meteo').hide();	
			}
		},
		onHide: function(){
			if ( $.browser.msie && ($.browser.version == "6.0") ) 
			{
				if($('select#ville_meteo').length > 0) $('select#ville_meteo').show();	
			}
		}
	});
}
/*DESCBOX and NFOBOX HOVER*/
if ($('.nfobox') && $('.nfobox').length > 0 && $.browser.msie && ($.browser.version == "6.0") || $('.descbox').length > 0 && $.browser.msie && ($.browser.version == "6.0"))
{
	$('.descbox').hover(
		function(){
			$(this).toggleClass('hover');
		},
		function(){
			$(this).toggleClass('hover');
		}
	)
	$('.nfobox').hover(
		function(){
			$(this).toggleClass('hover');
		},
		function(){
			$(this).toggleClass('hover');
		}
	)
}

/*sub navigation*/
$('.subnav li').each(function(index){
	$(this).click(function(){
		$('.subnav li').removeClass('selected')
		$(this).addClass('selected');
	})	
})

/*toggleme*/
$('.toggleme').click(function(){
	var $prev = $(this).prev();
	$('.dummy').slideToggle('fast'); 
	
	if($prev.hasClass('rightto')){
		$prev.removeClass('rightto');
		$prev.addClass('downto');
	}
	else if($prev.hasClass('downto'))
	{
		$prev.removeClass('downto');
		$prev.addClass('rightto');
	}
});


function openPopin(popin,target)
{
	$(popin).overlay({
		target: target,
		expose: {
			color: '#000',
			loadSpeed: 100,
			opacity: 0.25
		},
		closeOnClick: true,
		top: '10%'
	}).dblclick();
	
}	
	
/*===========[ Utility methods ]================================================================*/
/**
 * Function: rgb2hex
 * Used to convert Firefox's computed css colour values from rgb to standard hex
 * e.g. rgb(255, 255, 255) = #FFFFFF;
 **/
function rgb2hex(input) {
	if (/#[\dabcdef]{3,6}/i.test(input) == true) return input;
	var rgb = input.substring(4,input.length-1).split(',');
	if (rgb.length !== 3) return false;
	var output = '#' + dec2hex(rgb[0]) +  dec2hex(rgb[1]) +  dec2hex(rgb[2]);
	return output;
}
/**
 * Function: dec2hex
 * Converts any decimal number to it's hexidecimal equivalent
 **/
function dec2hex(dec) {
	var hexChars = "0123456789ABCDEF";
	dec = parseInt(dec);
	var a = dec % 16;
	var b = (dec - a) / 16;
	var hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
	return hex;
}