﻿$(function() {


    //we need the div Id for images
    var imagesDiv = $('#ctl00_ContentPlaceHolder1_loadedimages');
    // we need the div id for titles
    var titlesDiv = $('#ctl00_ContentPlaceHolder1_titlesloaded');

    var currentSelection = 0;

    //start timer funtion to increment currentSelection

    var timeout;

    $('#nextSt').click(function() {

        if (currentSelection == 3)
            currentSelection = 0;
        else
            currentSelection++;
        var p = currentSelection * 541 * -1;
        $('#ctl00_ContentPlaceHolder1_loadedimages').hide("slow").animate(
						{ marginLeft: p },
						"slow"
		);
        $('#ctl00_ContentPlaceHolder1_titlesloaded').hide("slow").animate(
		    { marginLeft: p },
						"slow"
		);
        $('#ctl00_ContentPlaceHolder1_loadedimages').show("slow");
        $('#ctl00_ContentPlaceHolder1_titlesloaded').show("slow");
        clearTimeout(timeout);
    });

    $('#prevSt').click(function() {



        var p;
        if (currentSelection == 0)
            p = 0;
        else {
            currentSelection--;
        }
        p = currentSelection * 540;

        $('#ctl00_ContentPlaceHolder1_loadedimages').animate(
						{ marginLeft: p },
						"slow"
		);
        $('#ctl00_ContentPlaceHolder1_titlesloaded').animate(
		    { marginLeft: p },
						"slow"
		);
        clearTimeout(timeout);

    });

    function GoNext() {

        if (currentSelection == 3)
            currentSelection = 0;
        else
            currentSelection++;
        var p = currentSelection * 540 * -1;
        var pi = p-2; 
        p = p - (15 * currentSelection) ;

        $('#controls').hide("slow");
        $('#ctl00_ContentPlaceHolder1_loadedimages').fadeOut("slow").animate(
						{ marginLeft: pi },
						"slow"
		);
        $('#titlebackground').hide("slow");
        $('#ctl00_ContentPlaceHolder1_titlesloaded').fadeOut("slow").animate(
		    { marginLeft: p },
						"slow"
		);

        $('#ctl00_ContentPlaceHolder1_loadedimages').fadeIn("slow");
        $('#ctl00_ContentPlaceHolder1_titlesloaded').fadeIn("slow", function() { $('#controls').fadeIn("slow"); });
        $('#titlebackground').fadeIn("slow");

        timeout = setTimeout(function() {
            GoNext();
        }, 10000);
    }



    timeout = setTimeout(function() {
        GoNext();
    }, 5000);

}); 