var $reas= jQuery.noConflict();
$reas(document).ready(function()
	{
		var image_loading = $reas('<div>').attr('class','image_loading');
			
		$reas('.s_center').append(image_loading);

		$reas('.s_center').load('includes/slider.php', function(){
			 $reas('.image_loading').remove();
			 $reas('#slide1').addClass("slide_nr_active");
			  var currentPosition = 0;
			  var slideWidth = 930;
			  var slides = $reas('.slide');
			  var numberOfSlides = slides.length;
			  // Remove scrollbar in JS
			  $reas('#slidesContainer').css('overflow', 'hidden');
			
			  slides.wrapAll('<div class="slideInner" id="slideInner"></div>')
				.css({
				  'float' : 'left',
				  'width' : slideWidth
				});
			
			  $reas('#slideInner').css('width', slideWidth * numberOfSlides);

			// POSITION CHANGE TIMER
			function moveAtTime()
				{
					if(currentPosition<numberOfSlides){ currentPosition=currentPosition+1; }
					if(currentPosition==numberOfSlides){ currentPosition=0; }
					
					$reas('.slide_nr').removeClass("slide_nr_active");
					var sldTmp = currentPosition+1;
					$reas('#slide'+sldTmp).addClass("slide_nr_active");
					$reas('#slideInner').animate({
						  'marginLeft' : (slideWidth*(-currentPosition))
						});	
					$reas(document).stopTime("hide");
					$reas(document).everyTime(30000, "hide", function() { moveAtTime(); });
				}
			//$reas(document).everyTime(30000, "hide", function() { moveAtTime(); });

			// POSITION CLICK CHANGE
			$reas('.slide_nr').bind('click', function()
				{
					$reas(document).stopTime("hide");
					$reas(document).everyTime(40000, "hide", function() { moveAtTime(); });
					
					$reas('.slide_nr').removeClass("slide_nr_active");
					$reas('#'+$reas(this).attr('id')).addClass("slide_nr_active");

					currentPosition = $reas(this).attr('id').replace('slide','');
					currentPosition--;
					$reas('#slideInner').animate({
					  'marginLeft' : (slideWidth*(-currentPosition))
					},500 );
				});
				
			// HOVER
			$reas(".slide_nr").mouseenter(function() 
				{	
					$reas(this).addClass("slide_nr_hover");
				}).mouseleave(function()
				{ 
					$reas(this).removeClass("slide_nr_hover");
				});	
				
			$reas(".clip_in_slide").mouseenter(function() 
				{	
					$reas(this).addClass("cis_act");
				}).mouseleave(function()
				{ 
					$reas(this).removeClass("cis_act");
				});	
				
			// YOUTUBE WIDEO LB	
			$reas("a[rel=lightbox_youtube_sli]").click(function() {
				$reas.fancybox({
						'padding'		: 0,
						'autoScale'		: false,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'		: 640,
						'height'		: 480,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
							 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});
			
				return false;
			});
			// IMAGE LB
				$reas("a[rel=lightbox_img_sli]").fancybox({
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'titlePosition' 	: 'over',
					'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					}
				});
		});
	});
