﻿$(document).ready(function() {
    //options( 1 - ON , 0 - OFF)
    var auto_slide = 1;
    var hover_pause = 1;
    var key_slide = 1;
    //speed of auto slide
    var auto_slide_seconds = 1;

    $('#right_scroll').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slide("right")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });

    $('#left_scroll').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slide("left")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });

    $('#right_scroll1').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slide1("right")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });

    $('#left_scroll1').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slide1("left")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });

    // Contract
    $('#right_scrollCONTRACT').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slideCONTRACT("right")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });

    $('#left_scrollCONTRACT').hover(function() {
        //and when mouseout start it again
        timer = setInterval('slideCONTRACT("left")', auto_slide_seconds);
    }, function() {
        //stop the interval
        clearInterval(timer);
    });


});

//FUNCTIONS BELOW

//slide function  
function slide(where) {

    //get the item width
    var item_width = $('#carousel_ul li').outerWidth() + 4;

    /* using an if statement and the where variable check 
    we will check where the user wants to slide (left or right)*/
    if (where == 'left') {
        //...calculating the new left indent of the unordered list (ul) for left sliding
        var left_indent = parseInt($('#carousel_ul').css('left')) + item_width;
    } else {
        //...calculating the new left indent of the unordered list (ul) for right sliding
        var left_indent = parseInt($('#carousel_ul').css('left')) - item_width;

    }

    //make the sliding effect using jQuery's animate function... '
    $('#carousel_ul:not(:animated)').animate({ 'left': left_indent }, 1000, function() {

        /* when the animation finishes use the if statement again, and make an illusion
        of infinity by changing place of last or first item */
        if (where == 'left') {
            //...and if it slided to left we put the last item before the first item
            $('#carousel_ul li:first').before($('#carousel_ul li:last'));

            // Start DIT code

	    $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_accessories_carouselposition').val(null);
            // get the newly made HTML in memory - key piece of code
            var enc = $().crypt({ method: "b64enc", source: $('#carousel_ul').html() });
            // store in the hidden field
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_accessories_carouselposition').val(enc);



            //document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value = null;
            // get the newly made HTML in memory - key piece of code
            //var enc = $().crypt({ method: "b64enc", source: $('#carousel_ul').html() });
            // store in the hidden field
            //document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value = enc;
            //alert('its stored: ' + document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value);
            // End DIT code

        } else {
            //...and if it slided to right we put the first item after the last item
            $('#carousel_ul li:last').after($('#carousel_ul li:first'));


	    $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_accessories_carouselposition').val(null);
            // get the newly made HTML in memory - key piece of code
            var enc = $().crypt({ method: "b64enc", source: $('#carousel_ul').html() });
            // store in the hidden field
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_accessories_carouselposition').val(enc);


            //Start DIT code
            //document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value = null;
            //var enc = $().crypt({ method: "b64enc", source: $('#carousel_ul').html() });
            //document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value = enc;
            //alert('its stored: ' + document.getElementById('plcRoot_Layout_zoneContent_PagePlaceholder_PagePlaceholder_Layout_zoneLeft_dit_product_accessories_carouselposition').value);
            // End DIT code

        }

        //...and then just get back the default left indent
        $('#carousel_ul').css({ 'left': '-74px' });
    });
}

//slideXXX function  
function slide1(where) {

    //get the item width
    var item_width = $('#carousel_ul1 li').outerWidth() + 4;

    /* using an if statement and the where variable check 
    we will check where the user wants to slide (left or right)*/
    if (where == 'left') {
        //...calculating the new left indent of the unordered list (ul) for left sliding
        var left_indent = parseInt($('#carousel_ul1').css('left')) + item_width;
    } else {
        //...calculating the new left indent of the unordered list (ul) for right sliding
        var left_indent = parseInt($('#carousel_ul1').css('left')) - item_width;

    }

    //make the sliding effect using jQuery's animate function... '
    $('#carousel_ul1:not(:animated)').animate({ 'left': left_indent }, 1000, function() {

        /* when the animation finishes use the if statement again, and make an illusion
        of infinity by changing place of last or first item */
        if (where == 'left') {
            //...and if it slided to left we put the last item before the first item
            $('#carousel_ul1 li:first').before($('#carousel_ul1 li:last'));

	    // Start DIT code
	    $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_associatedranges_carouselpositionBeds').val(null);
            var encBeds = $().crypt({ method: "b64enc", source: $('#carousel_ul1').html() });
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_associatedranges_carouselpositionBeds').val(encBeds);
	    // End DIT code


        } else {
            //...and if it slided to right we put the first item after the last item
            $('#carousel_ul1 li:last').after($('#carousel_ul1 li:first'));

	    // Start DIT code
	    $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_associatedranges_carouselpositionBeds').val(null);
            var encBeds = $().crypt({ method: "b64enc", source: $('#carousel_ul1').html() });
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneLeft_dit_product_associatedranges_carouselpositionBeds').val(encBeds);
	    // End DIT code

        }

        //...and then just get back the default left indent
        $('#carousel_ul1').css({ 'left': '-104px' });
    });
}


// Contract
//slideXXX function
function slideCONTRACT(where) {

    //get the item width
    var item_width = $('#carousel_ulCONTRACT li').outerWidth() + 4;

    /* using an if statement and the where variable check 
    we will check where the user wants to slide (left or right)*/
    if (where == 'left') {
        //...calculating the new left indent of the unordered list (ul) for left sliding
        var left_indent = parseInt($('#carousel_ulCONTRACT').css('left')) + item_width;
    } else {
        //...calculating the new left indent of the unordered list (ul) for right sliding
        var left_indent = parseInt($('#carousel_ulCONTRACT').css('left')) - item_width;

    }

    //make the sliding effect using jQuery's animate function... '
    $('#carousel_ulCONTRACT:not(:animated)').animate({ 'left': left_indent }, 1000, function() {

        /* when the animation finishes use the if statement again, and make an illusion
        of infinity by changing place of last or first item */
        if (where == 'left') {
            //...and if it slided to left we put the last item before the first item
            $('#carousel_ulCONTRACT li:first').before($('#carousel_ulCONTRACT li:last'));

            //DIT CODE
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneCenterleft_CaseStydies_dit_casestudy_carousel_carouselposition').val(null);
            var enc = $().crypt({ method: "b64enc", source: $('#carousel_ulCONTRACT').html() });
            //alert(enc);
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneCenterleft_CaseStydies_dit_casestudy_carousel_carouselposition').val(enc);

        } else {
            //...and if it slided to right we put the first item after the last item
            $('#carousel_ulCONTRACT li:last').after($('#carousel_ulCONTRACT li:first'));

            //DIT CODE
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneCenterleft_CaseStydies_dit_casestudy_carousel_carouselposition').val(null);
            var enc = $().crypt({ method: "b64enc", source: $('#carousel_ulCONTRACT').html() });
            //alert(enc);
            $('#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneCenterleft_CaseStydies_dit_casestudy_carousel_carouselposition').val(enc);

        }

        //...and then just get back the default left indent
        $('#carousel_ulCONTRACT').css({ 'left': '-144px' });
    });
}
