﻿var interval;
var currentImage;
var nextImage;
var caption;
var pauseFlag;

$(document).ready(function() {
    show();
    $('.caption').css({ opacity: 0.8 });
    $('#images').hover(function() {
        $('.pause').css({ opacity: 0.8 }).animate({ left: '10px', bottom: '13px' }, 200);
        clearInterval(interval);
        pauseFlag = true;
    },
    function() {
        interval = setInterval("images()", 3000);
        $('.pause').animate({ left: '-70px', bottom: '-70px' }, 200);
        pauseFlag = false;
    });
});



function show() {
   $('#images a.current').animate({ left: '0px' }, 2500, jQuery.easing.easeIn, function() {
        addCaption($('#images a.current').find('img').attr('rel'));
        });

        //interval = setInterval("start()", 7000);
        start();
}

function start() {
    clearInterval(interval);
    interval = setInterval("images()", 7000);
}

function images() {
    switchImg();    

    slideIn();
    removeCaption();
    
}

function switchImg() {
    
    if ($('#images a.current'))
        currentImage = $('#images a.current');
    else
        currentImage = $('#images a:first');

    if (currentImage.next().length) {

        if (!currentImage.next()) {
            nextImage = $('#images a:first');
        }
        else
            nextImage = currentImage.next();
    }
    else {
        nextImage = $('#images a:first');
    }

    caption = nextImage.find('img').attr('rel');
}

function slideIn() {
    nextImage.addClass('current').animate({ left: '0px' }, 2500, jQuery.easing.easeIn, function() {
        addCaption(caption);
        clearInterval(interval);
   
    });
}

function slideOut() {
    currentImage.removeClass('current').animate({ left: '520px' }, 2500, jQuery.easing.easeIn, function() {
        if (pauseFlag == true) {
            return;
        }
        else {
            interval = setInterval("images()", 7000);   
        }
    });
}

function removeCaption() {
    //$('.caption').animate({ left: '-505px' }, 200);
    $('.caption').slideToggle();
    slideOut();  
}

function addCaption(text) {
    //$('.caption').css({ opacity: 0.8 }).animate({ left: '0px' }, 100, 'linear');
    $('.caption').slideToggle();
    $('#images .description').html(text);
}




//var interval;
//var currentImage;
//var nextImage;
//var caption;
//var pauseFlag;

//$(document).ready(function() {
//    show();
//    $('.caption').css({ opacity: 0.8 });
//    $('#images').hover(function() {
//        $('.pause').css({ opacity: 0.8 }).animate({ left: '10px', bottom: '13px' }, 200);
//        clearInterval(interval);
//        pauseFlag = true;
//    },
//    function() {
//        interval = setInterval("images()", 3000);
//        $('.pause').animate({ left: '-70px', bottom: '-70px' }, 200);
//        pauseFlag = false;
//    });
//});



//function show() {
//    $('#images a.current').animate({ left: '0px' }, 2500, jQuery.easing.easeIn, function() {
//        addCaption($('#images a.current').find('img').attr('rel'));
//    });
//    interval = setInterval("start()", 3000);
//}

//function start() {
//    clearInterval(interval);
//    interval = setInterval("images()", 3000);
//}

//function images() {
//    switchImg();

//    slideIn();
//    removeCaption();
//    slideOut();
//}

//function switchImg() {
//    if ($('#images a.current'))
//        currentImage = $('#images a.current');
//    else
//        currentImage = $('#images a:first');

//    if (currentImage.next().length) {
//        if (!currentImage.next())
//            nextImage = $('#images a:first');
//        else
//            nextImage = currentImage.next();
//    }
//    else {
//        nextImage = $('#images a:first');
//    }

//    caption = nextImage.find('img').attr('rel');
//}

//function slideIn() {
//    nextImage.addClass('current').animate({ left: '0px' }, 2500, jQuery.easing.easeIn, function() {
//        addCaption(caption);
//        clearInterval(interval);

//    });
//}

//function slideOut() {
//    currentImage.removeClass('current').animate({ left: '520px' }, 2500, jQuery.easing.easeIn, function() {
//        if (pauseFlag == true) {
//            return;
//        }
//        else {
//            interval = setInterval("images()", 3000);
//        }
//    });
//}

//function removeCaption() {
//    //$('.caption').animate({ left: '-505px' }, 200);
//    $('.caption').slideToggle();
//}

//function addCaption(text) {
//    //$('.caption').css({ opacity: 0.8 }).animate({ left: '0px' }, 100, 'linear');
//    $('.caption').slideToggle();
//    $('#images .description').html(text);
//}







//old version... slowdown caused problems;

//$(document).ready(function() {
//    show();
//});

//var interval;
//var currentImage;
//var nextImage;
//var caption;


//function show() {
//    $('#images a.current').animate({ left: '0px' }, 2000, 'linear', function() {
//        addCaption($('#images a.current').find('img').attr('rel'));
//    });

//    interval = setInterval('images()', 3000);
//    $('#images').hover(function() {
//        $('.pause').css({ opacity: 0.8 }).animate({ left: '10px', bottom: '13px' }, 200);
//        clearInterval(interval);
//    },
//    function() {
//        interval = setInterval("images()", 3000);
//        $('.pause').animate({ left: '-70px', bottom: '-70px' }, 200);
//    });
//}

//function images() {
//    switchImg();

//    slideIn();
//    removeCaption();
//    slideOut();
//}

//function switchImg() {
//    if ($('#images a.current'))
//        currentImage = $('#images a.current');
//    else
//        currentImage = $('#images a:first');

//    if (currentImage.next().length) {
//        if (!currentImage.next())
//            nextImage = $('#images a:first');
//        else
//            nextImage = currentImage.next();
//    }
//    else {
//        nextImage = $('#images a:first');
//    }

//    caption = nextImage.find('img').attr('rel');
//}

//function slideIn() {
//    nextImage.addClass('current').animate({ left: '0px' }, 2000, 'linear', function() {
//        addCaption(caption);
//    });
//}

//function slideOut() {
//    currentImage.removeClass('current').animate({ left: '520px' }, 2000);
//}

//function removeCaption() {
//    $('.caption').animate({ left: '-505px' }, 200);
//}

//function addCaption(text) {
//    $('.caption').css({ opacity: 0.8 }).animate({ left: '0px' }, 100, 'linear'); //, function() {
//    //        $('.caption').css({ opacity: 0.8 }).animate({ left: '-100px' }, 150, 'linear', function() {
//    //            $('.caption').css({ opacity: 0.8 }).animate({ left: '0px' }, 185, 'linear', function() {
//    //                $('.caption').css({ opacity: 0.8 }).animate({ left: '-50px' }, 200, 'linear', function() {
//    //                    $('.caption').css({ opacity: 0.8 }).animate({ left: '-20px' }, 210, 'linear', function() {
//    //                        $('.caption').css({ opacity: 0.8 }).animate({ left: '0px' }, 220, 'linear');
//    //                    });
//    //                });
//    //            });
//    //        });
//    //    });

//    $('#images .description').html(text);
//}

