$(function() {
    $('.ttItem').click(function() {

        var itm = $(this).attr('prod');

        $('#ttViewer').css({
            top: $(window).scrollTop() + 20 +"px",
            left: ( ( $(window).width() / 2 ) - 400) + 'px',
            backgroundImage: "url('/toyotatouch/prd/"+ itm + "-large.jpg')"
        });

        $('#ttViewer').fadeIn(500);

    });    

    $('#ttViewer').click(function(){
        $(this).fadeOut(500);
    });
});


var ttouch = {
    preload: [
        '/toyotatouch/touch1.jpg',
        '/toyotatouch/touch2.jpg',
        '/toyotatouch/touch3.jpg',
        '/toyotatouch/touch4.jpg',
        '/toyotatouch/touch5.jpg'
    ],


    init: function() {

        $.preload(ttouch.preload, {
            onFinish: function() {
                ttouch.cycleItems();
            }
        });

    },

    item: 0,

    cycleItems: function() {

        if ( typeof(ttouch.preload[ttouch.item]) == 'undefined' )
            ttouch.item = 0;

        var imgUrl = ttouch.preload[ttouch.item];

        $('#ttHomeItem').css({
            backgroundImage: "url('" + imgUrl + "')",
            display: 'none'
        });

        $('#ttHomeItem').fadeIn(500,function() {
            setTimeout( function() {

                $('#ttHomeItem').fadeOut(500,function() {
                    ttouch.item++;
                    ttouch.cycleItems();
                });

            }, 1500);
        });
        

    }

};
