$(function(){

	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'y';

	$('body').scrollTo( 0 );
	// Reset the screen to (0,0)
	$.scrollTo( 0 ); 
	$("#content").scrollTo( 0 );
	$(".forum").scrollTo( 0 );
	
	$.localScroll({
	target: 'body', // could be a selector or a jQuery object too.
	queue:true,
	duration:1500,
	easing:'easeOutExpo',
	//hash:true,
	onBefore:function( e, anchor, $target ){
	// The 'this' is the settings object, can be modified
	},
	onAfter:function( anchor, settings ){
	// show selected menu button

	}
	});
	
	// NEWS 
	// top scroller
	$("#news-scroller-top, #forum-scroller-top").hide();
	
	// scroller news and forum
	$("#news-scroller").click(function(){
		$('#content').stop().scrollTo( "+=350px", 800, { axis:'y' } ); 
		$("#news-scroller-top").fadeIn();
	});
	
	// scroller news and forum
	$("#news-scroller-top").click(function(){
		$('#content').stop().scrollTo( "-=350px", 800, { axis:'y' } );
		
		/* set variables locally for increased performance */
		var scroll_timer;
		//var displayed = false;
		var $message = $("#news-scroller-top");
		var $window = $("#content");
		var top = $(document.body).children(0).position().top;

		/* react to scroll event on window */
		$window.scroll(function () {
			window.clearTimeout(scroll_timer);
			scroll_timer = window.setTimeout(function () { // use a timer for performance
				if($window.scrollTop() == top) // hide if at the top of the page
				{
					//displayed = false;
					$message.fadeOut(500);
				}
			}, 200);
		});
	});
	
	
	// FORUM scroller
	$("#forum-scroller").click(function(){
		$('.forum').stop().scrollTo( "+=350px", 800, { axis:'y' } ); 
		$("#forum-scroller-top").fadeIn();
	});
	
	// click
	$("#forum-scroller-top").click(function(){
		$('.forum').stop().scrollTo( "-=350px", 800, { axis:'y' } );
		
		/* set variables locally for increased performance */
		var scroll_timer;
		//var displayed = false;
		var $message = $("#forum-scroller-top");
		var $window = $("#forum");
		var top = $(document.body).children(0).position().top;
	 
		/* react to scroll event on window */
		$window.scroll(function () {
			window.clearTimeout(scroll_timer);
			scroll_timer = window.setTimeout(function () { // use a timer for performance
				if($window.scrollTop() == top) // hide if at the top of the page
				{
					//displayed = false;
					$message.fadeOut(500);
				}
			}, 200);
		});
	});
	
	// mouseOut scroller (disappear)
	$("#forum-scroller-top").hover(function(){
		//
		}, function(){

	});

	// Index : block Forum - clean style on RSS Feed
	$(".forum ul li div, .forum ul li a").each(function(){
		$(this).removeAttr("style");
	});
	
	// clear both first DIV
	$(".forum ul li div").css({clear: "both"});
	
	//remove BR
	//$(".forum ul li br").remove();
	
	$(".forum ul li div").each(function(){
		$(this).children(":first").css({color: "#666666", fontStyle: "italic", paddingBottom: "4px", fontSize: "11px"});
	});
		
	
	//****************************************//
	//************* VIDEOS *****************//
	//****************************************//
	// transform youtube link in embed code
	// find all <a href> with 'youtube' inside
	$(".block .forum ul li a[href*='youtube']").each(function(){
		var videoYou = $(this).text();
		// get video id
		var youID = videoYou.substring(31, 42);
		$(this).replaceWith("<object width=\"320\" height=\"240\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+youID+"&hl=fr_FR&fs=1&\"></param><param name=\"wmode\" value=\"transparent\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+youID+"&hl=fr_FR&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"240\"></embed></object>");
	});
	
	// same with Dailymotion
	//http://www.dailymotion.com/video/x309hk_the-beatles-help_music
	$(".block .forum ul li a[href*='dailymotion']").each(function(){
		var videoDaily = $(this).text();
		// get video id
		var dailyID = videoDaily.substring(33, 39);
		$(this).replaceWith("<object width=\"320\" height=\"240\"><param name=\"movie\" value=\"http://www.dailymotion.com/swf/"+dailyID+"\"></param><param name=\"wmode\" value=\"transparent\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"http://www.dailymotion.com/swf/"+dailyID+"\" width=\"320\" height=\"240\" allowfullscreen=\"true\" allowscriptaccess=\"always\"></embed></object>");
	});
	
	// same with Dailymotion
	// http://vimeo.com/6823016
	$(".block .forum ul li a[href*='vimeo']").each(function(){
		var videoVimeo = $(this).text();
		// get video id
		var vimeoID = videoVimeo.substr(-7);
		$(this).replaceWith("<object width=\"320\" height=\"240\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id="+vimeoID+"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://vimeo.com/moogaloop.swf?clip_id="+vimeoID+"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"320\" height=\"240\"></embed></object>");
		});
	//************* END VIDEOS *****************//

	// New video album on Main Menu
	var nbrNewVid = $("#videos .block-content .new-media").length;
	if(nbrNewVid >= 1)
			$("#nav #b-videos a").append("<span class=\"news-elements\"></span>");
	
	// New Photos album on Main Menu
	var nbrNewP = $("#photos .block-content .new-media").length;
	if(nbrNewP >= 1)
			$("#nav #b-photos a").append("<span class=\"news-elements\"></span>");
	
	// Remove gallery style (proteam)
	$("#gallery-1").removeAttr("class");
	$("#gallery-1 dl").removeAttr("class");
	$("#gallery-1 dt").removeAttr("class");
	$("#gallery-1 dt a img").removeAttr("class");
	$("#gallery-1 a").removeAttr("title");
	
	$("#post-103 table td:eq(1)").css({width: "460px"});
	// end style gallery (proteam)
	
	// tipTip jQuery
	$("#content img, .img-media").tipTip({maxWidth: "auto", edgeOffset: 2, delay: 10});
	
	// Fancybox BUT
	// only if a href is a image (.jpg)
	$("#content  a[href*='.jpg'], #content a[href*='.gif'], #content a[href*='.png']").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'overlayColor'	: '#000',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn' 		: 600,
		'speedOut'		: 300
	});


});

