﻿$("document").ready(function () {

    $('.slideshow').cycle({
        fx: 'fade',
        timeout: 4000,
        pause: 1
    });

    jQuery('#movieroller').jcarousel({
        vertical: true,
        scroll: 2,
        auto: 7,
        wrap: 'circular',
        animation: 'slow',
        initCallback: movieroller_initCallback
    });


    function movieroller_initCallback(carousel) {
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });
    };



    jQuery('#businessroller').jcarousel({
        vertical: true,
        scroll: 1,
        auto: 7,
        wrap: 'circular',
        animation: 'slow',
        initCallback: movieroller_initCallback
    });


    touchScroll('tabletscroll');

    jQuery('.slideshow img').click(function () {
        document.location.href = jQuery(this).attr('rel');
    }).css('cursor', 'pointer');


});

//Make overflowed divs scrollable with single finger on tables
function isTouchDevice(){
	try{
		document.createEvent("TouchEvent");
		return true;
	}catch(e){
		return false;
	}
}
function touchScroll(id) {

	if(isTouchDevice()){ //if touch events exist...
		var el=document.getElementById(id);
		var scrollStartPos=0;
		document.getElementById(id).addEventListener("touchstart", function(event) {
			scrollStartPos=this.scrollTop+event.touches[0].pageY;
		},false);

		document.getElementById(id).addEventListener("touchmove", function(event) {
			this.scrollTop=scrollStartPos-event.touches[0].pageY;
			event.preventDefault();
		},false);
	}
}


