﻿/// <reference path="jquery.intellisense.js"/>  
	  
$(document).ready(function(){
  $('#flashcontent').click(function(){
    $(this).blur();
  });
  
  //-- photo scroller --//
  var auto = setInterval(autoscroll, 4000);
  
  $('.photocontainer .prev').click(function(){
    clearInterval(auto);
  
    if ($('.photocontainer .photos ul:animated').length == 0){
      var left = parseInt($('.photocontainer .photos ul').css('margin-left'),10);
      var width = $('.photocontainer .photos ul li').length * $('.photocontainer .photos ul li:first').width();
      var three = parseInt($('.photocontainer .photos ul li:first').width(),10)*3;
      var move = left + three <= 0 ? left + three : -width + three;
      
      //alert(left + three);
      //alert(move);
      
      if (left <= 0){
        $('.photocontainer .photos ul').animate({
          marginLeft:move
        },1000, 'easeOutQuad', function(){
          auto = setInterval(autoscroll, 4000);
        });
      }
    }
  });
  $('.photocontainer .next').click(function(){
    clearInterval(auto);
  
    if ($('.photocontainer .photos ul:animated').length == 0){
      var left = parseInt($('.photocontainer .photos ul').css('margin-left'),10);
      var width = $('.photocontainer .photos ul li').length * $('.photocontainer .photos ul li:first').width();
      var three = parseInt($('.photocontainer .photos ul li:first').width(),10)*3;
      var move = Math.abs(left - three) <= (width - three) ? left - three : 0;
      
      //alert(Math.abs(left - three));
      //alert(width - three);
      //alert(move);
      
      if (left > -width){
        $('.photocontainer .photos ul').animate({
          marginLeft:move
        },1000, 'easeOutQuad', function(){
          auto = setInterval(autoscroll, 4000);
        });
      }
    }
  });
  
  function autoscroll(){
    var left = parseInt($('.photocontainer .photos ul').css('margin-left'),10);
    var width = $('.photocontainer .photos ul li').length * $('.photocontainer .photos ul li:first').width();
    var three = parseInt($('.photocontainer .photos ul li:first').width(),10)*3;
    var move = Math.abs(left - three) <= (width - three) ? left - three : 0;
    
    //alert(Math.abs(left - three));
    //alert(width - three);
    //alert(move);
    
    if (left > -width){
      $('.photocontainer .photos ul').animate({
        marginLeft:move
      },1000, 'easeOutQuad');
    }
  }

});
