$(document).ready(function() {
	setTimeout(function(){
		vscrollable = $('.vscroll').jScrollPane();
		api = vscrollable.data('jsp');		
	}, 50);

	$('#vscrollup').click(function(){
		api.scrollByY(-129, true);
	});
	$('#vscrolldown').click(function(){
		api.scrollByY(129, true);
	});	
	$('.mplay').live('click',function(){
		$("#loader_home").fadeIn();
		newsID = $(this).attr('id');
		$.ajax({
		   type: "POST",
		   url: "http://www.rtsentreprise.ch/wp-content/themes/rtsentreprise/ajax_getEmbed.php",
		   data: "newsID="+newsID,
		   success: function(msg){
				$('#mplayer').html(msg);
				$('#mplayer').append("<div class='desc_video' style='display: block;'>");
				$('#mview').hide();
				$('.media_player .mplay_more').clone().appendTo('#mplayer .desc_video');
				$('#mplayer').children('.mplay_more').addClass("bide");
				$('#mplayer').show();
				$("#loader_home").fadeOut(500);
				
		   }
		 });
	});
	$(".media_player .desc").show(); //Show Banner
	$(".media_player .block").animate({ opacity: 1 }, 1 ); //Set Opacity
	$(".thumbs ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
	$(".thumbs ul li").click(function(){
	    //Set Variables
	    var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
	    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	    var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
	    var imgDescHeight = $(".media_player").find('.block').height(); //Find the height of the "block"
	
	    if ($(this).is(".active")) {  //If the list item is active/selected, then...
	        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
	    } else { //If not active then...
	        //Animate the Description
	        $(".media_player .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 1 , function() { //Pull the block down (negative bottom margin of its own height)
	            $(".media_player .block").html(imgDesc).animate({ opacity: 1,  marginBottom: "0" }, 1 ); //swap the html of the block, then pull the block container back up and set opacity
	            $(".media_player img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
	        });
	    }
	    //Show active list-item
	    $(".thumbs ul li").removeClass('active'); //Remove class of 'active' on all list-items
	    $(this).addClass('active');  //Add class of 'active' on the selected list
	    
		$('#mplayer').empty();
		$('#mplayer').hide();	
		$('#mview').show();
		
	    return false;
	}) .hover(function(){ //Hover effects on list-item
	    $(this).addClass('hover'); //Add class "hover" on hover
	    }, function() {
	    $(this).removeClass('hover'); //Remove class "hover" on hover out
	});	
	$("a.collapse").click(function(){
	    $(".media_player .block").slideToggle(); //Toggle the description (slide up and down)
	    $("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
	});	
	$('.radio_caption_link').live('click', function(){
		$('.radio_caption_activ').removeClass('radio_caption_activ');
		itemIndex = $(this).parent().children().index($(this)); ;
		$('.radio_caption').eq(itemIndex).addClass('radio_caption_activ');
		$('.radio_caption_activ').contents().show();
		$('.radio_caption').eq(itemIndex).children(".caption_box").children("p").css("display","block");
	});
	$('.tv_caption_link').live('click', function(){
		$('.tv_caption_activ').removeClass('tv_caption_activ');
		itemIndex = $(this).parent().children().index($(this));
		$('.tv_caption').eq(itemIndex).addClass('tv_caption_activ');
		$('.tv_caption_activ').contents().show();
		$('.tv_caption').eq(itemIndex).children(".caption_box").children("p").css("display","block");
	});
	
	$(".left").hover(
	  function () {
	    $(this).children(".radio_caption_activ").children(".caption_box").children("p").slideDown();
	  }, 
	  function () {
	    $(this).children(".radio_caption_activ").children(".caption_box").children("p").slideUp();
	  }
	);
	
	$(".right").hover(
	  function () {
	    $(this).children(".tv_caption_activ").children(".caption_box").children("p").slideDown();
	  }, 
	  function () {
	    $(this).children(".tv_caption_activ").children(".caption_box").children("p").slideUp();
	  }
	);	
});
