(function() {
$(document).ready(function()  
{ 

$('ul#resultproducts li.produit').css('margin-right', '20px');

$('ul#resultproducts li.produit:nth-child(3n+3)').css('margin-right','0px');




$('#articleblog').rssfeed('http://otaku.fr/blog/?feed=rss2', {
    limit: 2
  });


/*
$('#group_5').customStyle();
$('#group_6').customStyle();
*/
 
var a = new Array(0,1,2,3,4);
shuffle(a);
var selecteur0 = "#sky".concat(a[1]);
var selecteur1 = "#sky".concat(a[2]);
var selecteur2 = "#sky".concat(a[3]);
var selecteur3 = "#sky".concat(a[4]);
var selecteur4 = "#sky".concat(a[0]);





	$(selecteur0).addClass('green');
	$(selecteur1).addClass('purple');
	$(selecteur2).addClass('yellow');
	$(selecteur3).addClass('orange');
	$(selecteur4).addClass('pink');

$('a.previous').hide();
        $('a.next').hide();



    
    
    

$('#articleblog').mouseenter(function(e) {
        $('#imgBlog').children('a').children('img').animate({ height: '60', left: '0', top: '0', width: '166'}, 100);
        $('#imgBlog').children('a').children('span').fadeIn(200);
    }).mouseleave(function(e) {
        $('#imgBlog').children('a').children('img').animate({ height: '80', left: '-20', top: '-20', width: '210'}, 100);
        $('#imgBlog').children('a').children('span').fadeOut(200);
    });
    
    
    
$('.pika-image').mouseenter(function(e) {
        $('.pika-imgnav').children('a.previous').fadeIn(500);
        $('.pika-imgnav').children('a.next').fadeIn(500);
    }).mouseleave(function(e) {
        $('.pika-imgnav').children('a.previous').fadeOut(500);
        $('.pika-imgnav').children('a.next').fadeOut(500);
    });
    
    
$(".produit").hover(function(e){
	$(this).children('.imageMask').children('.nometprix').hoverFlow(e.type,{ top: 50, opacity: 0 }, {queue:'false',duration: '500',easing: 'easeOutElastic'});
               	
	}, function(e) {
	$(this).children('.imageMask').children('.nometprix').hoverFlow(e.type,{ top: 0, opacity: 1 }, {queue:'false',duration: '500',easing: 'easeOutElastic'});
});	
    
    
    $("#allTweet").tweet({
            username: "OtakuGameWear",
            join_text: "auto",
            count: 5,
            loading_text: "loading tweets..."
        }).ajaxStop(function(){
$('#twitterContent #allTweet').vTicker({
speed: 500,
pause: 3000,
showItems: 2,
animation: 'fade',
mousePause: true,
height: 0,
direction: 'up'

});
});



$.ajax({
        url: 'https://graph.facebook.com/42919831859',
        dataType: 'jsonp',
        success: function(data) {
            $('#facebooklikes').html(data.likes);
       }
       
       });
                  
                  
$("#pikame").PikaChoose();

					$("#pikame").jcarousel({scroll:4,					
						initCallback: function(carousel) 
						{
					        $(carousel.list).find('img').click(function() {
					        	//console.log($(this).parents('.jcarousel-item').attr('jcarouselindex'));
					            carousel.scroll(parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex')));
					        });
					    }
				    });


$("#myTable").tablesorter({
	sortList: [[3,0]]
});

$('#coda-slider-1').codaSlider();


/*
$('img#bigpic').addpowerzoom({
		defaultpower: 2,
		powerrange: [2,4],
		largeimage: null,
		magnifiersize: [200,200] //<--no comma following last option!
	})
*/

try{Typekit.load();}catch(e){}

/*
$("#allTweet").tweet({
            username: "OtakuGameWear",
            join_text: "auto",
            count: 5,
            loading_text: "loading tweets..."
        }).ajaxStop(function(){
$('#twitterContent #allTweet').vTicker({
speed: 500,
pause: 3000,
showItems: 2,
animation: 'fade',
mousePause: true,
height: 0,
direction: 'up'

});
});
*/

/*
$('#twitterContent #allTweet').vTicker({
speed: 500,
pause: 3000,
showItems: 3,
animation: 'fade',
mousePause: true,
height: 0,
direction: 'up'
});
*/

  /*********** Newsletter ***********/
  $("#searchform_q").focus(function(){
   $('#searchform_q').css('color', '#a9a9a9');
  });
  
  
  
     $("#searchform_submit").click(function() {
	if($('#searchform_q').val() ==''){
      			$('#searchform_q').val('Invalide');
      			$('#searchform_q').css('color', '#f46b25');
      			return false;
      		} else if (!$('#searchform_q').val().match(/([a-z0-9]+([-_]?[a-z0-9]+)*.)*[a-z0-9]+([-_]?[a-z0-9]+)*@([a-z0-9]+([-_]?[a-z0-9]+)*.)+[a-z]{2,4}/gi)){
      		      		$('#searchform_q').val('Invalide');
      		$('#searchform_q').css('color', '#f46b25');
      		return false;
      		}	
    });
    
    
   /*
 $('#myForm').ajaxForm(function() { 
    if (valid == true){
                $('#inputNews').val('merci');
                $('#inputNews').css('color', 'green');
                }
            });
*/
    
   /*********** fin Newsletter ***********/ 
    
    
    
	/*********** gestion de la gallery ***********/
$("a#1").click(function() { show(0); return false; });
	$("a#2").click(function() { show(1); return false; });
	$("a#3").click(function() { show(2); return false; });
	$("a#4").click(function() { show(3); return false; });
	$("a#5").click(function() { show(4); return false; });
	$("a#6").click(function() { show(5); return false; });
	var images = $("#gallery img");
	var thumbs = $("#thumbs img");
	var thumblinks = $("#thumbs a");
	var index = thumbs.length-1;
	var thumbsHeight = 100;
	thumblinks.slice(thumblinks.length-3,thumblinks.length).clone().attr('id', function() { var id = $(this).id; return 'b' + this.id}).prependTo("#thumbs");
	$("a#b4").click(function() { show(3); return false; });
	$("a#b5").click(function() { show(4); return false; });
	$("a#b6").click(function() { show(5); return false; });
	for (i=0; i<thumbs.length; i++) {
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}
	show(index);
	/* bloque ou active la manivelle // setInterval(sift, 8000); */
	function sift() {
		if ( index < thumbs.length && index > 0) {index -= 1 ; }
		else { index = thumbs.length-1 }
		show ( index );
	}
	function show(num) {
		images.fadeOut(400);
		$(".image-"+num).stop().fadeIn(400);
		var scrollPos = ( (num-1) * thumbsHeight ) + 100;
		$("#thumbs").stop().animate({scrollTop: scrollPos}, 400);
	}
    
    
    /*********** fin gestion de la gallery ***********/ 
    

        
        
    moveBgAround();    //appel de la fonction faisant bouger le fond du logo

      
}); // fin des actions aux chargement du dom "$(document).ready(function()"


/*********** fonction faisant bouger le fond du logo ***********/
function moveBgAround() {
	//give a random value from 0 to 400 for the X axis and the Y axis
	var x = Math.floor(Math.random()*1800);
	var y = 0;

	//random generated time it takes to move
	var time = Math.floor(Math.random()*1001) + 3000;

	//make the background image move!
	$('.scrollBg').animate({
		backgroundPosition: '(' + (x * -1) + 'px ' + (y * -1) + 'px)'
	}, time, "swing", function() {
		moveBgAround();
	});	
}
/*********** fin fonction faisant bouger le fond du logo ***********/


// Enhancements
	var slideshow_start_mode  = false; 
    var autostart_slideshow = true;  
    var rewind_slideshow = true;  
    var display_slideshow_control_panel = true;  
	 
    var slide_transition_time = 1000;  
    var slide_viewing_time = 5000;  
       
        
    
	// Enhancements
	function start_slideshow() {  
	   slideshow_start_mode = true;  
	   interval = setInterval(show_next_slide, slide_viewing_time );  
	}  
	 
	function show_next_slide(){  
	   $('#rightControl').click();  
	}  
	 
	function pause_slideshow() {  
	   slideshow_start_mode = false;  
		   clearInterval(interval);  
	} 	
	



/*********** parti slider de la page galerie ***********/
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 730;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
    var interval;  

	
  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition,numberOfSlides);



  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
		// If auto rewind is off pause the slideshow 
		// when on the last slide
		if(currentPosition == numberOfSlides && rewind_slideshow == false )
		{  
             currentPosition--;  
             pause_slideshow();  
        } 
	
	// Hide / show controls
    manageControls(currentPosition);
	
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    },slide_transition_time);
	
  });

	// If auto start is on kick off the slideshow
	if(autostart_slideshow == true){  
		start_slideshow();  
	}

    // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }

		// Hide right arrow if position is last slide
		// and if auto rewind is not on
		if(position==numberOfSlides-1 && rewind_slideshow == false)
		{
			$('#rightControl').hide();
		} else {
			$('#rightControl').show();
		}
		
		// Go back to the first slide if we're on the last slide
		// and if auto rewind is on
		if(position == numberOfSlides && rewind_slideshow == true){
			currentPosition = 0;
			 $('#leftControl').hide();
		}
  }	
  
  
  
  
/*
  var zIndexNumber = 1000;
       // Put your target element(s) in the selector below!
       $("div").each(function() {
               $(this).css('zIndex', zIndexNumber);
               zIndexNumber -= 10;
       });
*/
  
  
  
  
    });
    try {
      Typekit.load()
      
      
      
     // {
        //active: function() {
          // As soon as the fonts are active, fade in the example
          // Don't fade in browsers that don't do proper opacity, like IE
          /*
if (jQuery.support.opacity) {
            	$('*[style*='ff-enzo-web-1, ff-enzo-web-2']').css('visibility', 'visible').hide().fadeIn();
          } else {
            $('*[style*='ff-enzo-web-1, ff-enzo-web-2']').css('visibility', 'visible');
          }
        },
*/
        //inactive: function() {
          // If the fonts are inactive, just show the example
          // You can apply fallback styles using the wf-inactive class in your CSS
          /*
$('*[style*='ff-enzo-web-1, ff-enzo-web-2']').css('visibility', 'visible');
        }
      }
*/
      
      
      
    } catch(e) {}
  })();
/*********** fin parti slider de la page galerie ***********/ 

function shuffle(a)
{
   var j = 0;
   var valI = '';
   var valJ = valI;
   var l = a.length - 1;
   while(l > -1)
   {
		j = Math.floor(Math.random() * l);
		valI = a[l];
		valJ = a[j];
		a[l] = valJ;
		a[j] = valI;
		l = l - 1;
	}
	return a;
 }
