﻿/* <reference path="lib/jquery-1.3.2-vsdoc2.js" /> */
/*
 * French 01/02/10
 *
 */
var Carousel = {

    speed: 6000,
    item_width:0,
    left_value:0,
    min_img_height: 999,
    

    BuildAll: function() {
        
        Carousel.Initialize()

    },
    
    Initialize: function() {

        //rotation speed and timer
        var run = setInterval('Carousel.Rotate()', Carousel.speed );
        
        // grab the width and calculate left value
        Carousel.item_width = $('#slides li').outerWidth();
        Carousel.left_value = Carousel.item_width * (-1);
        
        //move the last item before first item, just in case user click prev button
	    //$('#slides li:first').before($('#slides li:last'));
	
	    //set the default item to the correct position 
	    $('#slides ul').css({'left' : Carousel.left_value});
	    
	    
	    $("#prev").click(this.Prev);
	    $("#next").click(this.Next);
	    
	    //if mouse hover, pause the auto rotation, otherwise rotate it  
        $('#carousel').hover(  
           
         function() {  
             clearInterval(run);  
         },   
         function() {  
             run = setInterval('Carousel.Rotate()', Carousel.speed);     
         }); 
     
     Carousel.SetDisplayImage();  
  
    },
    
    Prev: function() {

        //get the right position            
		var left_indent = parseInt($('#slides ul').css('left')) + Carousel.item_width;

		//slide the item            
		$('#slides ul').animate({'left' : left_indent}, 200, function(){    

            //move the last item and put it as first item            	
			$('#slides li:first').before($('#slides li:last'));           

			//set the default item to correct position
			$('#slides ul').css({'left' : Carousel.left_value});
		
		    Carousel.SetDisplayImage();
		
		});
		
		//cancel the link behavior            
		return false;
    
    },
    
    Next: function() {

        // get the right position
        var left_indent = parseInt($('#slides ul').css('left')) - Carousel.item_width;
        
        //slide the item
        $('#slides ul').animate({'left' : left_indent}, 200, function () {
            
            //move the first item and put it as the last item
            $('#slides li:last').after($('#slides li:first'));
            
            //set the default item to correct position
            $('#slides ul').css({'left' : Carousel.left_value});
            
            Carousel.SetDisplayImage();
            
        });

        //cancel the link behavior   
        return false;
        
    },
    
    Rotate: function() {
        $('#next').click();
    },
    
    SetDisplayImage: function() {
        var displayImage = $('#slides li:eq(3) img').attr('src');
        $('#carousel img:first').attr('src', displayImage);
        
        var displayHttp = $('#slides li:eq(3) a').attr('href');
        $('#carousel a:first').attr('href', displayHttp);
        
        var displayTitle = $('#slides li:eq(3) a').attr('title');
        $('#carousel a:first').add('<div class="title">' + displayTitle + '</div>');
        
        var displayAlt = $('#slides li:eq(3) a').attr('title');
        $('#carousel img:first').attr('alt', displayAlt);
        $('.imgTitle').text(displayAlt);
    }
    
    
};

$(document).ready(function() {
    Carousel.BuildAll();
});