 var margin_x = 0;
 var t;
 var max_x = 0;
 var slider = 0;
 var pos = 0;
 
$(document).ready(function() {
    var old_m = 0;
    if ($("a[rel^='prettyPhoto']").length>0) {
         $("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
    }
  
    $(".next_page").mouseover(function() {
         movniMe1();
    });
 
    $(".next_page").mouseout(function() {
         clearTimeout(t);
    });
 
   $(".previous_page").mouseover(function() {
        movniMe2();
   });

   $(".previous_page").click(function() {
         margin_x += 80;
   });
   
   $(".next_page").click(function() {
         margin_x -= 80;
   });

   $(".previous_page").mouseout(function() {
         clearTimeout(t);
   });
 
    $(document).ready(function() { 
        $('ul.sf-menu').superfish(); 
    }); 
/* 
   $("#menu li").hover(function() {
          //$("#m"+old_m).hide();        
          $("#m1").hide();        
          $("#m2").hide();        
          $("#m3").hide();        
          $("#m4").hide();        
          $("#m5").hide();        
          $("#m6").hide();        
          $(".sc_menu").css("margin-left","0px");
     
         margin_x = 0;
         var id = $(this).attr("rel");
          $("#m"+id).show();
          old_m = id;
           var m = $("#m"+id).width();
         max_x = (m-1000)*-1;
    });
*/ 
    var totWidth=0;
    var positions = new Array();

    $('#slides .slide').each(function(i) {
         /* Loop through all the slides and store their accumulative widths in totWidth */
         positions[i]= totWidth;
         totWidth += $(this).width();

         /* The positions array contains each slide's commulutative offset from the left part of the container */

         if (!$(this).width()) {
              alert("Please, fill in width & height for all your images!");
              return false;
         }
    });
 
    $('#slides').width(totWidth);

    /* Change the cotnainer div's width to the exact width of all the slides combined */
 
   $("#test").click(function() {
 
 
         $.each($(".slide"), function(i,n) {

              $("#test").append("My id is " + i + " : "+n+".<br/>");
             //return (this != "four"); // will stop running to skip "five"
        });
    
         //    $('li.menuItem').removeClass('act').addClass('inact');
       //    $("#xmenu ul li a").parent().addClass('act');

    })
 
    $('#xmenu ul li a').click(function(e) {
         /* On a thumbnail click */
         $('li.menuItem').removeClass('act').addClass('inact');
         $(this).parent().addClass('act');

         var pos = $(this).parent().prevAll('.menuItem').length;

         $('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
         /* Start the sliding animation */

         e.preventDefault();
         /* Prevent the default action of the link */
    });
    $('#xmenu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
    /* On page load, mark the first thumbnail as active */
 
    setTimeout('changeSlide()', 5000);

});


function changeSlide() {

    //alert(pos);
    pos++;
    if(pos>3)
      pos = 0;
    var cc = pos * 944;
    $('#slides').stop().animate({marginLeft:-cc+'px'},1500, function() {
         // Animation complete.
         //alert("done....");
         setTimeout('changeSlide()', 8000);
     });
}

function movniMe1(){
   // $("#result").html("margin_x = "+margin_x+" <> max_x "+max_x);
    if(margin_x < max_x)
    {
     clearTimeout(t);
     return;
    }

     margin_x = margin_x - 1;
     $(".sc_menu").css("margin-left",margin_x+"px");
    t = setTimeout ( "movniMe1()", 10 );
}

function movniMe2(){
  //  $("#result").html("margin_x = "+margin_x+" <> max_x "+max_x);

    if(margin_x >= 0)
    {
     clearTimeout(t);
     return;
    }
     
     margin_x = margin_x + 1;
     $(".sc_menu").css("margin-left",margin_x+"px");
    t = setTimeout ( "movniMe2()", 10 );
}
