$(document).ready(
	function()
	{
		rules('all');
		SI.Files.stylizeAll();
	});

function rules(choice){
		switch(choice){
			default:
				/* Projets ----------------------------------------------------- */
				$('a.prev_proj').click(function(){
					var rel = $(this).attr("rel");
					projets(rel);
					return false;
				});
				
				$('a.suiv_proj').click(function(){
					var rel = $(this).attr("rel");
					projets(rel);
					return false;
				});
				
				/* Jobs ----------------------------------------------------- */
				$('a.prev_jobs').click(function(){
					var rel = $(this).attr("rel");
					jobs(rel);
					return false;
				});
				
				$('a.suiv_jobs').click(function(){
					var rel = $(this).attr("rel");
					jobs(rel);
					return false;
				});
				
				/* News ----------------------------------------------------- */
				$('a.prev_news').click(function(){
					var rel = $(this).attr("rel");
					news(rel);
					return false;
				});
				
				$('a.suiv_news').click(function(){
					var rel = $(this).attr("rel");
					news(rel);
					return false;
				});
			break;
			
			case "projs":
				/* Projets ----------------------------------------------------- */
				$('a.prev_proj').click(function(){
					var rel = $(this).attr("rel");
					projets(rel);
					return false;
				});
				
				$('a.suiv_proj').click(function(){
					var rel = $(this).attr("rel");
					projets(rel);
					return false;
				});
			break;
			
			case "jobs":
				/* Jobs ----------------------------------------------------- */
				$('a.prev_jobs').click(function(){
					var rel = $(this).attr("rel");
					jobs(rel);
					return false;
				});
				
				$('a.suiv_jobs').click(function(){
					var rel = $(this).attr("rel");
					jobs(rel);
					return false;
				});
			break;
			
			case "news":
				/* News ----------------------------------------------------- */
				$('a.prev_news').click(function(){
					var rel = $(this).attr("rel");
					news(rel);
					return false;
				});
				
				$('a.suiv_news').click(function(){
					var rel = $(this).attr("rel");
					news(rel);
					return false;
				});
			break;
		}
}

function news(start){	
	$.post('portail/pages/news.php', {js: 1, indice_news: start }, function(reponse){
		$('#fade-news').fadeOut(300, function(){
			$('#fade-news').html(reponse);
			$('#fade-news').fadeIn(300,function(){
				rules('news');									
			});				
		});																	
	});
}

function projets(start){
	$.post('portail/pages/projects.php', {js: 1, indice_projets: start }, function(reponse){
		$('#fade-projects').fadeOut(300, function(){
			$('#fade-projects').html(reponse);
			$('#fade-projects').fadeIn(300,function(){
				rules('projs');									
			});				
		});																	
	});
}

function jobs(start){
	$.post('portail/pages/jobs.php', {js: 1, indice_jobs: start }, function(reponse){
		$('#fade-jobs').fadeOut(300, function(){
			$('#fade-jobs').html(reponse);
			$('#fade-jobs').fadeIn(300,function(){
				$('#titrejobs').val(parseInt(start));
				rules('jobs');									
			});				
		});																	
	});
}

function loadSWF(){
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
		if (document.getElementById && version["major"] < 8) {
			/*	window.location.href="noflash.html";	*/
			$("body").css("background","#000000 url('images/noflash.jpg') no-repeat top center");
			$("#contentPortail").addClass("noflash");
			
			$("#contentPortail").append('<div class="getFlash"></div>');
			$(".getFlash").append('<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank"><img src="portail/images/get_flash_player.gif" alt="Get flash player" border="0" /></a>');
		}else{
			var soFlashDiplo = new SWFObject("site_public/site_portail/diploClub.swf" , "diplo_swf", "1000", "33", "9" , "#000000");
			soFlashDiplo.addParam("scale", "noscale");
			soFlashDiplo.addParam("menu", "false");
			soFlashDiplo.write("contentClub");
			
			var soFlashPortail = new SWFObject("site_public/site_portail/level0.swf" , "level0_swf", "100%", "655", "9" , "#000000");
			soFlashPortail.addParam("wmode","transparent");
			soFlashPortail.addParam("scale", "noscale");
			soFlashPortail.addParam("menu", "false");
			soFlashPortail.write("contentPortail");
		}
}

function findFile(file){
	var temp = file.value.split('\\');
	var nomFichier = temp[temp.length-1];
	var temp2 = nomFichier.split('.');
	var extensionFichier = temp2[temp2.length-1].toLowerCase();
	
	if(extensionFichier == "doc" || extensionFichier == "txt" || extensionFichier == "pdf"){
		$('#nomfichier').html(nomFichier);
	}else{
		$('#nomfichier').html("Invalid format - Only doc, pdf and txt format");
	}
}

if (!window.SI) { var SI = {}; };
SI.Files =
{
	htmlClass : 'cfile-style',
	fileClass : 'file',
	wrapClass : 'cfile',
	
	fini : false,
	able : false,
	init : function()
	{
		this.fini = true;
		
		var ie = 0 //@cc_on + @_jscript_version
		if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return; } // no support for opacity or the DOM
		this.able = true;
		
		var html = document.getElementsByTagName('html')[0];
		html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
	},
	
	stylize : function(elem)
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };
		
		elem.parentNode.file = elem;
	},
	
	stylizeById : function(id)
	{
		this.stylize(document.getElementById(id));
	},
	
	stylizeAll : function()
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };
		
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];
			if (input.type == 'file' && input.className.indexOf(this.fileClass) != -1 && input.parentNode.className.indexOf(this.wrapClass) != -1)
			{
				this.stylize(input);
			};
		};
	}
};