$(function(e) {
	var $p = $('#contenu_droite_grand p, #contenu2_droite p');
	
	var fontSize = readCookie('fontSize');

	$('a.fontsizeMax').click(function() {
		$p.css('font-size', '18px');
		$p.css('line-height', '20px');
		createCookie('fontSize', 'MAX', 30);
		return false;
	});
	
	$('a.fontsizeMed').click(function() {
		$p.css('font-size', '16px');
		$p.css('line-height', '18px');
		createCookie('fontSize', 'MED', 30);
		return false;
	});
	
	$('a.fontsizeNorm').click(function() {
		$p.css('font-size', '12px');
		$p.css('line-height', '15px');
		createCookie('fontSize', 'NORM', 30);
		return false;
	});
	
	if(fontSize != null) {
		if(fontSize == 'MAX') {
			$('a.fontsizeMax').click();
		}
		else if(fontSize == 'MED') {
			$('a.fontsizeMed').click();
		}
		else if(fontSize == 'NORM') {
			$('a.fontsizeNorm').click();
		}
	}

	$('#radio_gtq').click(function(e) {
		window.open(root+'shows/radio', 'RadioGTQ', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=490,height=250');
	});
	
	/* SELECT BOX REPLACEMENT */
	$('#ShowC').selectbox({debug: false});
	$('#ShowQ').focus(function() { $(this).val(''); });
	
	$('li.external a').attr('target', '_blank');
	
	/* BACKGROUND BY WINDOW SIZE */
	setBG($(window).width());
	
	$(window).resize(function() {
		setBG($(window).width());
	});

});

function setBG(windowWidth) {
	if(windowWidth <= 1024) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1024.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1280 && windowWidth > 1024) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1280.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1370 && windowWidth > 1280) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1370.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1450 && windowWidth > 1370) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1450.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1600 && windowWidth > 1450) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1600.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1700 && windowWidth > 1600) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1700.jpg) no-repeat fixed center top');
	}
	else if(windowWidth <= 1920 && windowWidth > 1700) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1920.jpg) no-repeat fixed center top');
	}
	else if(windowWidth >= 1920) {
		$('body').css('background', '#574F43 url('+root+'img/fonds/fond1/fond1_1920.jpg) no-repeat fixed center top');
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
