/** Binding en/fr **/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

var pages_fr = [
	'affiliation-adfever.html',
	'annonceurs-et-agences.html',
	'annonceurs-et-reseaux.html',
	'bannieres-thematiques.html',
	'compte-active.html',
	'developpeurs-et-designeurs.html',
	'editeurs-et-blogueurs.html',
	'formats-publicitaires.html',
	'home.html',
	'index.html',
	'inscription.html',
	'interstitiel.html',
	'login.html',
	'marque-blanche-comparateur-de-prix.html',
	'parrainage-adfever.html',
	'partenaires-de-monétisation.html',
	'plateforme-adfever.html',
	'plugin-wordpress.html',
	'solutions-publicitaires.html',
	'xml.html'
	
];

var pages_en = [
	'referral-program.html',
	'advertisers-and-agencies.html',
	'advertisers-and-partners.html',
	'customized-banners.html',
	'active-account.html',
	'developpers-and-designers.html',
	'publishers-and-bloggers.html',
	'ad-formats.html',
	'home.html',
	'index.html',
	'register.html',
	'interstitiel.html',
	'login.html',
	'white-label-shopbot.html',
	'referral-program.html',
	'monetization-partner.html',
	'adfever-platform.html',
	'plugin-wordpress.html',
	'our-ad-solution.html',
	'xml.html'
];

function changeLang(lang) {
	var url = document.location.href;
	var uri = parseUri(url);	
	var lang = $.cookie('lang');
	
	
	
	if(lang=='fr') {
		if(uri['file'].indexOf('index.html')!=-1) {
			document.location.href = '/';
		}
		else {
			var idx = pages_en.indexOf(uri['file']);
			document.location.href = '/'+pages_fr[idx];
		}
	}
	else {
		if(uri['file']=='') {
			document.location.href = '/'+lang+'/index.html';
		}
		else {
			var idx = pages_fr.indexOf(uri['file']);
			document.location.href = '/'+lang+'/'+pages_en[idx];
		}
	}
} 