function change_pic($active,$next){
 //schimba poza mare din centru + show/hide/textul aferent pozei 	
 var index=jQuery("#slideshow div").index($active); 
 var index2=jQuery("#slideshow div").index($next); 
 var Lefty = jQuery('#featured_box_r span.gallery:eq('+index+')');
 jQuery(Lefty).stop().animate({
	left: -jQuery(Lefty).outerWidth()
    },0,function(){ //just remove the "0"
     $active.css({opacity: 1.0})
       .addClass('last-active')
       .stop().animate({opacity: 0.0}, 200, function() {
            $next.css({opacity: 0.0})
            .addClass('active')
            .stop().animate({opacity: 1.0}, 200, function() {
                  $active.removeClass('active last-active');
              var Lefty2 = jQuery('#featured_box_r span.gallery:eq('+index2+')');
			  jQuery(Lefty2).stop().animate({
					left: 0
				},0);
			  });
       });
  });     
  
}
function arrow_right(obj) {//click pe sageata dreapta 
	clearInterval(setId);
	//obj.unbind('click');
	var inner_pic_active=jQuery('div.inner_pic.active');
	var index=jQuery("#inner_list div.inner_pic").index(inner_pic_active);
	var next_index=index<3 ?(index+1):0;
	
	jQuery('div.inner_pic ').removeClass('active').stop().fadeTo("fast",0.4);
	jQuery('div.inner_pic:eq('+next_index+')').addClass('active').stop().fadeTo("slow",1.0);
	
	var $active =jQuery('#slideshow DIV.active');
	var $next = jQuery('#pic'+next_index);
	change_pic($active,$next);
	//obj.bind('click',function(){arrow_right(jQuery(this))});
	setId=setInterval( "slideSwitch()", 5000 );
 }
function arrow_left(obj) {//click pe sageata left 
	clearInterval(setId);
	var inner_pic_active=jQuery('div.inner_pic.active');
	var index=jQuery("#inner_list div.inner_pic").index(inner_pic_active);
	var next_index=index>0 ?(index-1):3;
	
	jQuery('div.inner_pic ').removeClass('active').stop().fadeTo("fast",0.4);
	jQuery('div.inner_pic:eq('+next_index+')').addClass('active').stop().fadeTo("slow",1.0);
	
	var $active =jQuery('#slideshow DIV.active');
	var $next = jQuery('#pic'+next_index);
	
	change_pic($active,$next);
	//obj.bind('click',function(){arrow_right(jQuery(this))});
	setId=setInterval( "slideSwitch()", 5000 );
 }
 function slideSwitch() {
    var $active_small = jQuery('#inner_list div.active');
    if ( $active_small.length == 0 ) $active_small = jQuery('#inner_list .inner_pic:first');
    var $active =jQuery('#slideshow DIV.active');
    if ( $active.length == 0 ) $active = jQuery('#slideshow DIV:first');
    var $next =  $active.next().length ? $active.next() : jQuery('#pic0');
    var $next_small =  $active_small.next().length ? $active_small.next(): jQuery('#inner_list .inner_pic:first');
    $active_small.fadeTo("slow", 0.4).removeClass('active');
    $next_small.addClass('active').fadeTo("slow", 1.0);
 	change_pic($active,$next); 
}
jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};
jQuery(document).ready(function() {
         setId=setInterval( "slideSwitch()", 5000 );
          
          jQuery("#inner_list .inner_pic:last").css("margin-bottom","0px");
          jQuery(".inner_pic").stop().fadeTo("slow", 0.4);
          jQuery('#slideshow DIV').css({opacity: 0.0});
		  jQuery('#slideshow DIV:first').css({opacity: 1.0}).addClass("active");
		  var Lefty2=jQuery('#featured_box_r span:first ');
		  jQuery('#featured_box_r span:first ').animate({
					left: parseInt(jQuery(Lefty2).css('left'),10) == -jQuery(Lefty2).outerWidth() ? 0 : -jQuery(Lefty2).outerWidth()
				});
		  jQuery('#inner_list DIV:first').addClass("active").fadeTo("fast",1.0);
          jQuery(".inner_pic ").hover(function(){
               if (!jQuery(this).hasClass("active")){ 
                jQuery(this).stop(true,true).fadeTo("fast", 1.0);  // This sets the opacity to 100% on hover
                jQuery(this).addClass('activeh');
               } 
              },function(){
                if (!jQuery(this).hasClass("active")){
                  jQuery(this).fadeTo("fast", 0.4); // This sets the opacity back to 40% on mouseout
                }
              jQuery(this).removeClass('activeh'); 
           });
          
         jQuery('.inner_pic ').click(function() {//click pe small pic 
			if (!jQuery(this).hasClass("active")){
			 clearInterval(setId);
			 jQuery('div.inner_pic ').removeClass('active').stop().fadeTo("fast",0.4);
			 jQuery(this).addClass('active').stop().fadeTo("slow",1.0);
			 var index=jQuery("#inner_list div.inner_pic").index(this);
			 var $active =jQuery('#slideshow DIV.active');
			  
			 var $next = jQuery('#pic'+index);
			 change_pic($active,$next);
			 setId=setInterval( "slideSwitch()", 5000 );
			}
		 });
		jQuery('#featured_arrow_left').bind('click',function(){arrow_left(jQuery(this))});
		jQuery('#featured_arrow_right').bind('click',function(){arrow_right(jQuery(this))});
      });
