/* ------------------------------------------------------------------------
	Things to load when the dom is ready!
------------------------------------------------------------------------- */

	$(document).ready(function(){
		initARC('languageForm', 'radioOn', 'radioOff', 'checkboxOn', 'checkboxOff');
	});


/* ------------------------------------------------------------------------
	Class: Pretty Comments

	Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
	Inspired By: The facebook textarea :)
	Version: 1.1

	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top, w00t
------------------------------------------------------------------------- */

	var prettyComments = {
		version : '1.1',
		options : {
			'animate' : true,
			'animationSpeed' : 'normal', /* fast/slow/normal */
			'alreadyAnimed' : false,
			'padding' : 30,
			'init' : true /* DONT CHANGE */
		},
		init : function(which){
			// IE doubles the padding value 
			if($.browser.msie && parseFloat($.browser.version) < 7) this.options['padding'] = this.options['padding']/2;

			prettyComments.theTextarea = $('#' + which);

			// Create the div in which the content will be copied
			$('body').append('<div id="hidden_'+ this.theTextarea.attr('id') +'"></div>');

			prettyComments.theHiddenDiv = $('#hidden_' + this.theTextarea.attr('id'));

			// Now set the hiden div dimensions the same as the textarea (min-height is set differently in IE/Firefox, YAY for shitty browsers);
			this.theHiddenDiv.css({
				'display' : 'none',
				'width' : this.theTextarea.width() + 'px',
				'font-family' : this.theTextarea.css('font-family'),
				'font-size' : this.theTextarea.css('font-size'),
				'line-height' : this.theTextarea.css('line-height')
			});

			this.theTextarea.css({'overflow':'hidden','display':'inline'});

			if($.browser.msie && parseFloat($.browser.version) < 7){
				this.theHiddenDiv.css('height',this.theTextarea.height() + 'px');
			}else{
				this.theHiddenDiv.css('min-height',this.theTextarea.height() + 'px');
			};

			this.options['initialHeight'] = this.theTextarea.height();

			this.theTextarea.bind('keyup',function(){
				prettyComments.copyContent();
			});

			// On the init, make sure the textarea has the right dimensions
			this.copyContent();
		},
		copyContent : function(){
			// Convert the line feeds into BRs
			theValue = "";
			theValue += this.theTextarea.attr('value');
			theValue = theValue.replace(new RegExp( "\\n", "g" ),'<br />');

			this.theHiddenDiv.html(theValue);

			if(this.theHiddenDiv.height() > this.theTextarea.height() - this.options['padding']){
				this.expand();
			}else if(this.theHiddenDiv.height() < this.theTextarea.height() - this.options['padding']){
				this.shrink();
			};
		},
		expand : function(){			                                                              
			if(this.options['animate'] && !this.options['alreadyAnimed'] && !this.options['init']){
				if(!$.browser.safari){
					this.options['alreadyAnimed'] = true;
					this.theTextarea.animate({'height':this.theHiddenDiv.height() + this.options['padding']},this.options['animationSpeed'],function(){
						prettyComments.options['alreadyAnimed'] = false;
					});
				}else{
					this.theTextarea.height(this.theHiddenDiv.height() + this.options['padding']);
				}
			}else if(!this.options['animate'] && !this.options['alreadyAnimed'] && !this.options['init']){
				this.theTextarea.height(this.theHiddenDiv.height() + this.options['padding']);
			}else if(this.options['init']){
				this.theTextarea.height(this.theHiddenDiv.height());
				this.options['init'] = false;
			};
		},
		shrink : function(){
			this.options['alreadyAnimed'] = true;
			this.theTextarea.animate({'height':this.theHiddenDiv.height() + this.options['padding']},this.options['animationSpeed'],function(){
				prettyComments.options['alreadyAnimed'] = false;
			});
		}
	};


/* ------------------------------------------------------------------------
	Class: fixHeight
	Use: To make sure the main content is alway the same height as the sidebar
	By: Stéphane Caron
------------------------------------------------------------------------- */

	fixHeight = {
		init : function() {
			// The mainContentHeight is the total of the sidebar minus the newsCloud at the top.
			mainContentHeight = $('div#sidebar').height() + $('div.about').height();
			mainContentHeight = mainContentHeight - $('div.newsCloud').height();
			
			// No need to stretch the content area if it's already longer.
			if($('div.mainContentPattern').height() < (mainContentHeight + 20)){
				$('div.mainContentPattern').height(mainContentHeight + 20);
			}else{
				$('div.mainContentPattern').height('auto');
			}
		}
	}


/* ------------------------------------------------------------------------
	Class: fixNewsCloud
	Use: To make sure the newsCloud items are all the same height.
	By: Stéphane Caron
------------------------------------------------------------------------- */

	fixNewsCloud = {
		init : function() {
			longestDD = 0;
			$('.newsCloud dl dd').each(function(){
				if($(this).height() > longestDD){
					longestDD = $(this).height();
				}
			});
			
			// Apply the height to all the DDs
			$('.newsCloud dl dd').height(longestDD);
		}
	}


/* ------------------------------------------------------------------------
	Class: posts
	Use: Fetch the posts filtering out the undesired languages
	By: Stéphane Caron
------------------------------------------------------------------------- */

	posts = {
		refresh : function(templateURL){
			// Show the loader
			$('div.loaderDiv').show();
			
			// Change the content filtering properties
			$.get(templateURL + '/contentFiltering.php',$('form#languageForm').serialize() + '&change=true',function(){
				// Once that's done, load the new posts. 
				$.get(templateURL + '/get_posts.php','',function(data){
					// Put the returned posts in the content aread
					$('div.mainContentPattern').html(data);
					
					// Re-init the sIFR to display the nice fonts
					sIFR.replace(gillSans, {
					        selector: '.mainContent h1',
					        css: [
					                '.sIFR-root { color: #9f9893; }',
					                'a { text-decoration: none; }',
					                'a:link { color: #9f9893; }',
					                'a:hover { color: #CCCCCC; }'           
					        ],
					    wmode: 'transparent'                                               
					});

					sIFR.replace(gillSans, {
					        selector: '.mainContent h2',
					        css: [
					                '.sIFR-root { color: #9f9893; }',
					                'a { text-decoration: none; }',
					                'a:link { color: #9f9893; }',
					                'a:hover { color: #CCCCCC; }'           
					        ],
					    wmode: 'transparent'                                               
					});
					
					// Recalculate the content height
					fixHeight.init();
					
					// Hide the loader
					$('div.loaderDiv').hide();
				});
			}); 
		}
	}


/* ------------------------------------------------------------------------
	Function: toggleHeader
	Use: Resize the header when the user click on contact us
	By: Stéphane Caron
------------------------------------------------------------------------- */

	function toggleHeader(open){
		if(open){
			$('#flashMenu').height(357);
		}else{
			$('#flashMenu').height(38);
		}
	}

/* ------------------------------------------------------------------------
	Function: toggleHeader
	Use: Resize the header when the user click on contact us
	By: Stéphane Caron
------------------------------------------------------------------------- */

	function gotoRoot(){ location.href="/"; }