function change_pic($active,$next){
  jQuery('#slideshow div.active ').next().stop().slideUp(200,function(){
     $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');
					jQuery('#slideshow div.active ').next().stop().slideDown(200);
              });
       });
  });     
}
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().next().length ? $active.next().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(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");
      
          //if (jQuery.browser.msie){jQuery('#slideshow DIV:first span.gallery').stop().show('slow');}
          //jQuery('#slideshow DIV:first span.gallery').slideUp('0',function(){jQuery(this).slideDown(200)});
		  jQuery('#slideshow DIV:first ').next().slideUp('0',function(){jQuery(this).slideDown(200)});
          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 
				 //jQuery('.inner_pic').unbind('click');
	
				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('.inner_pic').bind('click');
		 });
      });
