var timer = 0;
var width = 946;
var width_multiplyer = 0;

$(document).ready(function(){
						   	
	//alert('hello');
	
	var stop_at = $('ul#home_banner_array li').size(); // method // action // no perameters
	
	//alert(stop_at);
	
	function myAnimation(direction) { // function // method
	
		if(direction == 'left'){
			
			if(width_multiplyer <= 0){
				
				width_multiplyer = stop_at-1;
				
			}
			else {
				width_multiplyer--;
			}
			var animate_left = '-'+(width*width_multiplyer);
			
		}
		else if(direction == 'right'){
			
			if(width_multiplyer >= (stop_at-1)) { // > < == >= <= !=
				width_multiplyer = 0;
			} //if
			else {
				width_multiplyer++;	
			}
			var animate_left = '-'+(width*width_multiplyer);
			
		}
		else{
			
			if(width_multiplyer >= (stop_at-1)) { // > < == >= <= !=
				width_multiplyer = 0;
			} //if
			else {
				width_multiplyer++;	
			}
			var animate_left = '-'+(width*width_multiplyer);
			
		}
		
		$('ul#home_banner_array').animate({left: animate_left}, 1000);
			
	} // function
	
	
	
	
	timer = setInterval(myAnimation, 6000, 'auto'); // 2 perameters
	
	//clearInterval(timer);
	
	$('a#arrow_left').click(function(){
		clearInterval(timer);
		myAnimation('left');
	});
	
	$('a#arrow_right').click(function(){
		clearInterval(timer);							 
		myAnimation('right');
	});
	
	
	
	
	
	
	
	// YOUTUBE ///////////////////////////////
	
	$("a.youTube").each(function($i){
								 
		
				
		$(this).click(function(){
							   
			var url = $(this).attr('href'); 
			var vidId = url.split('v=')[1].split('&')[0];
			//alert(vidId);
			open_vid(vidId);	
			return false;
			
		}); //click
		
	});

	function open_vid(vidId) {
		
			//alert('video');
			//alert(url);
			
			//alert(vidId);
			var vidSrc = "http://www.youtube.com/v/" + vidId + "&hl=en&fs=1&autoplay=1&rel=0";
			//alert(vidSrc);
			$.fancybox(
			'<object width="480" height="355"><param name="movie" value="'+vidSrc+'" bgcolor="#000000"></param><param name="allowFullScreen" value="true"></param><param name="bgcolor" value="#000000"><param name="allowscriptaccess" value="always"></param><embed src="'+vidSrc+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="355"></embed></object>',
			{
				'autoDimensions'	: false,
				'width'         		: 480,
				'height'        		: 355,
				'padding'        		: 10,
				'margin'        		: 0,
				'scrolling'        		: 'no',
				'transitionIn'		    : 'none',
				'showCloseButton'		: true,
				'transitionOut'		    : 'none'
			});
			//return false;
	}	
	
	
	
	$('.fancybox').fancybox();

	$("#esd_contact").fancybox({
		'width'				: 420,
		'height'			: 500,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

			
			
	//$('.wrap_entry .copy_img_portrait').parent().find('p').css('margin-left','265px');		
			
}); // ready



