$(document).ready(function(){

	//$("div.jsc_scrolldiv").smoothDivScroll({});
	/*
	if ( dw_scrollObj.isSupported() ) {
		var wndo = new dw_scrollObj('scroll_controls', 'jsc_scrolls');
		wndo.setUpScrollControls('scroll_controls',false,'h');
	}
	$('#scroll_controls').show();
	*/
	/*$("div.jsc_scrolldiv").smoothDivScroll({
		//autoScroll: "onstart",
		//autoScrollDirection: "backandforth",
		//autoScrollStep: 1,
		//autoScrollInterval: 15,
		//startAtElementId: "startAtMe",
		visibleHotSpots: "always"
	});*/
    
	var scrollSpeed = 200; // pixels per second

	$('.clients .jsc_scroll_left').mouseover(function(){
		scrollClients('left',scrollSpeed);
	}).mouseout(function(){
		$('.clients .jsc_scrolls').stop();
	}).mousedown(function(){
		scrollClients('left',scrollSpeed*3);
	}).mouseup(function(){
		scrollClients('left',scrollSpeed);
	});

	$('.clients .jsc_scroll_right').mouseover(function(){
		scrollClients('right',scrollSpeed);
	}).mouseout(function(){
		$('.clients .jsc_scrolls').stop();
	}).mousedown(function(){
		scrollClients('right',scrollSpeed*3);
	}).mouseup(function(){
		scrollClients('right',scrollSpeed);
	});

        $(".shine_image").mouseover(function () {
            //alert('mousein');
            $(".image_bg", this).hide();
            $(".image_colored", this).show();
        });
        $(".shine_image").mouseout(function () {
            //alert('mouseout');
            $(".image_bg", this).show();
            $(".image_colored", this).hide();
        });
});

function scrollClients(direction,curScrollSpeed){
	$('.clients .jsc_scrolls').stop();
	var scrollPH = $('.clients .jsc_scrolldiv');
	var scrollDiv = $('.clients .jsc_scrolls');
	var scrollDiv_width = scrollDiv.width();
	var scrollPH_width = scrollPH.width();
	var currentPosition = scrollDiv.position().left;
	if (direction=='left'){
		var finalPosition = 20;
	} else {
		var finalPosition = -(scrollDiv_width-scrollPH_width+30);
	}
	var pixelsToGo = Math.abs(finalPosition-currentPosition);
	var goTime = Math.round((pixelsToGo/curScrollSpeed)*1000);

	//console.debug({scrollDiv_width:scrollDiv_width});
	//console.debug({scrollPH_width:scrollPH_width});
	//console.debug({currentPosition:currentPosition});
	//console.debug({finalPosition:finalPosition});
	//console.debug({pixelsToGo:pixelsToGo});
	//console.debug({goTime:goTime});

	$('.clients .jsc_scrolls').animate(
		{left:+(finalPosition)+'px'},
		{
		  duration: goTime,
		  easing:'linear'
		}
	);
}

var aniDuration = 3000;
function animate_bg(el){
		//console.debug(el);
		$(el).animate({backgroundPosition: '(50% 0px)'},aniDuration,'linear',function(){
			$(el).animate({backgroundPosition: '(50% -64px)'},aniDuration,'linear',function(){
				animate_bg(el);
			});
		});
}
