/*
	blumbyte (c) 2011
*/


$(document).ready(function() {
    $(".scrollingtext").hide();

    var elements = $(".scrollingtext");
    var elementCount = elements.size();
    var elementsToShow = 1;
    var alreadyChoosen = ",";
    var i = 0;
    while (i < elementsToShow) {
        var rand = Math.floor(Math.random() * elementCount);
        if (alreadyChoosen.indexOf("," + rand + ",") < 0) {
            alreadyChoosen += rand + ",";
            elements.eq(rand).show();
            ++i;
        }
    }


	// INICIAL HIDE
	$('#iconbox-A').hide();
	$('#iconbox-B').hide();
	$('#iconbox-C').hide();
	$('#iconbox-D').hide();
	$('#iconbox-E').hide();
	$('#iconbox-F').hide();
	$('#iconbox-G').hide();
	$('#iconbox-H').hide();
	$('#iconbox-I').hide();
	$('#iconbox-K').hide();
	$('#iconbox-L').hide();
	$('#iconbox-M').hide();
	$('#iconbox-N').hide();

	// ICONES SAISON
	var velocityIn = 20;
	var velocityOut = 20;
	$('#icon-eventhandler-A').mouseover(function() {
		$('#iconbox-A').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-A').mouseout(function() {
		$('#iconbox-A').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-B').mouseover(function() {
		$('#iconbox-B').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-B').mouseout(function() {
		$('#iconbox-B').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-C').mouseover(function() {
		$('#iconbox-C').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-C').mouseout(function() {
		$('#iconbox-C').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-D').mouseover(function() {
		$('#iconbox-D').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-D').mouseout(function() {
		$('#iconbox-D').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-E').mouseover(function() {
		$('#iconbox-E').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-E').mouseout(function() {
		$('#iconbox-E').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-F').mouseover(function() {
		$('#iconbox-F').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-F').mouseout(function() {
		$('#iconbox-F').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-G').mouseover(function() {
		$('#iconbox-G').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-G').mouseout(function() {
		$('#iconbox-G').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-H').mouseover(function() {
		$('#iconbox-H').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-H').mouseout(function() {
		$('#iconbox-H').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-I').mouseover(function() {
		$('#iconbox-I').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-I').mouseout(function() {
		$('#iconbox-I').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-K').mouseover(function() {
		$('#iconbox-K').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-K').mouseout(function() {
		$('#iconbox-K').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-L').mouseover(function() {
		$('#iconbox-L').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-L').mouseout(function() {
		$('#iconbox-L').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-M').mouseover(function() {
		$('#iconbox-M').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-M').mouseout(function() {
		$('#iconbox-M').fadeOut( velocityOut );
	});
	$('#icon-eventhandler-N').mouseover(function() {
		$('#iconbox-N').fadeIn( velocityIn );
	});
	$('#icon-eventhandler-N').mouseout(function() {
		$('#iconbox-N').fadeOut( velocityOut );
	});

	// NEWSIMAGE GRAND
	$('#slick-hide').click(function() {
		$('#slickbox').fadeOut(2000);
		return false;
	});
});


/*
	jQuery Scroller plugin
	Copyright (c) 2010 Max Vergelli

	For support and tutorials visit
	http://maxvergelli.wordpress.com/

	License: GNU Lesser General Public License (LGPL) 
	at http://opensource.org/licenses/lgpl-2.1.php

	This plugin is free software;  you can redistribute it  and/or  modify  it 
	under the terms of the GNU Lesser General Public License as  published  by 
	the Free Software Foundation;  either version 2.1 of the License,  or  (at 
	your option) any later version.
	This software is distributed in the hope  that  it  will  be  useful,  but 
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
	or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU Lesser  General  Public 
	License for more details.
	You should have received a copy of  the  GNU Lesser General Public License 
	along with this library;  if not,  write to the  Free Software Foundation, 
	Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

	THIS COMMENT AND COPYRIGHT NOTICE MUST BE RETAINED IN THE CODE AS IS FOR LEGAL USE

*/

(function ($) {
	$.fn.PlayScroller = function(){
		this.children().stop();
		this.children().trigger('marquee',['resume']);
	};
	$.fn.PauseScroller = function(){
		this.children().stop();
	};
	$.fn.ResetScroller = function(options){
		this.children().stop();
		this.children().unbind('marquee');
		options = $.extend(this.data(), options);
		this.SetScroller(options);
	};
	$.fn.RemoveScroller = function(){
		this.children().stop();
		this.children().css({ top:0, left:0 });
		this.children().unbind('marquee');
	};
	$.fn.SetScroller = function (options) {
		var _ = { me: this };
		options = $.extend({ 
								velocity: 50,
								direction: 'horizontal',
								startfrom: 'right',
								loop: 'infinite',
								movetype: 'linear',
								onmouseover: 'pause',
								onmouseout: 'play',
								onstartup: 'play',
								cursor: 'pointer'
							}, 
							options);
		var velocity = typeof options.velocity == 'number' ? parseInt(options.velocity) : 50;
		var direction = options.direction.toLowerCase();
		var startfrom = options.startfrom.toLowerCase();
		var loop = typeof options.loop == 'number' && options.loop > 0 ? parseInt(options.loop) : -1; 
		var movetype = options.movetype.toLowerCase(); //TODO: 'linear' or 'pingpong'
		var onmouseover = options.onmouseover.toLowerCase();
		var onmouseout = options.onmouseout.toLowerCase();
		var onstartup = options.onstartup.toLowerCase();
		var cursor = options.cursor.toLowerCase();
		_.me.data(options);
		main();
		function main() {
			_.me.css('cursor',cursor);
			if(direction=='horizontal'){
				if(startfrom!='right' && startfrom!='left'){ startfrom='right'; };
				scrollHorizontal();
			}else{
				if(startfrom!='bottom' && startfrom!='top'){ startfrom='bottom'; };
				scrollVertical();
			};
			if(onmouseover=='play'){
				_.me.mouseover(function(){
					$(this).children().stop();
					$(this).children().trigger('marquee',['resume']);
				});
			}else{
				_.me.mouseover(function(){
					$(this).children().stop();
				});
			};
			if(onmouseout=='play'){
				_.me.mouseout(function(){
					$(this).children().stop();
					$(this).children().trigger('marquee',['resume']);
				});
			}else{
				_.me.mouseout(function(){
					$(this).children().stop();
				});
			};
			if(onstartup!='play'){
				_.me.children().stop();
			};
		};


		
		function scrollHorizontal(){
			_.me.children().bind('marquee', function(event,c) {
				var ob = $(this);
				var sw = parseInt(ob.parent().width());
				var tw = parseInt(ob.width());
				var tl = parseInt(ob.position().left);
				var v  = velocity>0 && velocity<100 ? (100-velocity)*100 : 5000;
				var dr = parseInt(v*tw/100)+v;				
				if(movetype=='pingpong'){
					switch(startfrom){
					case 'right':
						if(typeof c == 'undefined'){ob.css({ left: sw-tw });};
						sw = tl -  (tw + sw);
						break;
					default:
						if(typeof c == 'undefined'){ob.css({ left: 0 });};
						sw += tl - tw;
					};
				}else{
					switch(startfrom){
					case 'right':
						if(typeof c == 'undefined'){	
						    ob.css({ left: 25  });  // pour positionnement, était sw 
							sw = -tw;  // sw = -tw;
						}else{
							sw = tl - (tw + sw);
						};
						break;
					default:
						if(typeof c == 'undefined'){						
							ob.css({ left: -tw });
						}else{
							sw += tl + tw;
						};
					};
				};
				if(loop<0 || loop>0){
					if(loop>0){loop--;};
					ob.animate(	{left:sw},
							{	duration:dr,
								easing:'linear',
								complete:function(){ob.trigger('marquee');},
								step:function(){
									switch(movetype){
									case 'pingpong':
										if(startfrom == 'right'){
											if(parseInt(ob.position().left) <= 0){
												startfrom='left';
												ob.stop();
												ob.trigger('marquee');
											};
										}else{
											if(parseInt(ob.position().left)+parseInt(ob.width()) >= parseInt(ob.parent().width())){
												startfrom='right';
												ob.stop();
												ob.trigger('marquee');
											};
										};
										break;
									default:
										if(startfrom == 'right'){
											if(parseInt(ob.position().left) < -parseInt(ob.width())){
												ob.stop();
												ob.trigger('marquee');
											};
										}else{
											if(parseInt(ob.position().left) > parseInt(ob.parent().width())){
												ob.stop();
												ob.trigger('marquee');
											};
										};
									};
								}
							});					
				};
			}).trigger('marquee');
		};

		return this;
	};
})(jQuery);

$(document).ready(function() {

	//create scroller for each element with "horizontal_scroller" class...
	$('.horizontal_scroller').SetScroller({	velocity: 85,
											direction: 	 'horizontal',
											startfrom: 	 'right',
											loop:		 '10',
											movetype: 	 'linear',
											onmouseover: 'play',
											onmouseout:  'pause',
											onstartup: 	 'pause',
											cursor: 	 'progress'
										});
	/*
		All possible values for options...
		
		velocity:	from 1 to 99			[default is 50]						
		direction:	'horizontal' or 'vertical' 					[default is 'horizontal']
		startfrom:	'left' or 'right' for horizontal direction 	[default is 'right']
						'top' or 'bottom' for vertical direction	[default is 'bottom']
		loop:			from 1 to n+, or set 'infinite'				[default is 'infinite']
		movetype:		'linear' or 'pingpong'						[default is 'linear']
		onmouseover:	'play' or 'pause'							[default is 'pause']
		onmouseout:		'play' or 'pause'							[default is 'play']
		onstartup: 		'play' or 'pause'							[default is 'play']
		cursor: 		'pointer' or any other CSS style			[default is 'pointer']
	*/

	//how to overwrite options after setup and without deleting the other settings...
	$('#no_mouse_events').ResetScroller({	onmouseover: 'play', onmouseout: 'play'   });
	$('#scrollercontrol').ResetScroller({	velocity: 85, startfrom: 'left'   });

	//if you need to remove the scrolling animation, uncomment the following line...
	//$('#scrollercontrol').RemoveScroller();

	//how to play or stop scrolling animation outside the scroller... 
	$('#play_scrollercontrol').mouseover(function(){   $('#scrollercontrol').PlayScroller();   });
	$('#stop_scrollercontrol').mouseover(function(){   $('#scrollercontrol').PauseScroller();  });		

	//create a vertical scroller...	
	$('.vertical_scroller').SetScroller({	velocity: 80, direction: 'vertical'  });		
	
});
//-->

