﻿$(document).ready(function() {
/*
	window_screen_width = $(window).width();
	if (window_screen_width < 1280) {
		$("#header_scroll_bcl").css("display","none");
		$("#header_scroll_bcr").css("display","none");
		$("#header_scroll").css("width","960px");

		$(".header_scroll_left, .header_scroll_right").css("margin-right", "0px");
		$(".header_scroll_right").css("margin-left", "870px");
	}
*/
	var car_ul_leng = $('#carousel_ul li').length;
	if (car_ul_leng <= 5) {
		for (i= 0; i< car_ul_leng; i++) {
			$('#carousel_ul').append($('#carousel_ul li:eq('+i+')').clone());
		}
	}

	//move he last list item before the first item. The purpose of this is if the user clicks to slide left he will be able to see the last item.
	$('#carousel_ul li:first').before($('#carousel_ul li:last'));
	$('#carousel_ul li:first').before($('#carousel_ul li:last'));

	//when user clicks the image for sliding right        
	$('#header_kvscroll .header_scroll_right').click(function(){
	
		//get the width of the items ( i like making the jquery part dynamic, so if you change the width in the css you won't have o change it here too ) '
		var item_width = $('#carousel_ul li').outerWidth();
		
		//calculae the new left indent of the unordered list
		var left_indent = parseInt($('#carousel_ul').css('left')) - item_width;

		//make the sliding effect using jquery's anumate function '
		$('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){
			
			//get the first list item and put it after the last list item (that's how the infinite effects is made) '
			$('#carousel_ul li:last').after($('#carousel_ul li:first')); 
			
			//and get the left indent to the default 0px
			$('#carousel_ul').css({'left' : '-480px'});
		});
	});

	//when user clicks the image for sliding left
	$('#header_kvscroll .header_scroll_left').click(function(){
		
		var item_width = $('#carousel_ul li').outerWidth();
		
		/* same as for sliding right except that it's current left indent + the item width (for the sliding right it's - item_width) */
		var left_indent = parseInt($('#carousel_ul').css('left')) + item_width;
		
		$('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){    
		
			/* when sliding to left we are moving the last item before the first list item */            
			$('#carousel_ul li:first').before($('#carousel_ul li:last')); 
			
			/* and again, when we make that change we are setting the left indent of our unordered list to the default -210px */
			$('#carousel_ul').css({'left' : '-480px'});
		});
	});

	setInterval(function() { $("#header_kvscroll .header_scroll_right").trigger("click") }, 4000);
/*
	$("#header_scroll_bcl, #header_scroll_bcr").click(function () {
		$("#header_scroll_bcl").css("display","none");
		$("#header_scroll_bcr").css("display","none");
		$("#header_scroll_img").css("width","1280px");
		
		$("#header_kvscroll").css("display","none");
	});
*/
});
