$(document).ready(function(){
	
	
	function blinking(speed) {
		$('#tag a img.light').fadeOut(1000, function(){
			 $('#tag a img.light').fadeIn(1000);
			 blinking();
			 });
		
		}
	
	
	
		 blinking(100);
				
		
	
	
	
	
	
	$(function() {

	// initialize scrollable
	
	
	$(".slideshow .items").tabs(".items > div", {rotate: true,effect: 'fade', fadeOutSpeed: "slow"}).slideshow({clickable:false});

});
		
   $(".what-we-offer img.popup").overlay({
	 closeOnClick: true
   });
   
  $('#schedules-section #table-border tbody tr:nth-child(8n+2)').addClass('first')
  $('#schedules-section #table-border tr.first td:nth-child(5),#schedules-section #table-border tr.first:last').addClass('bg-none')
  
  
  $(".slidetabs").tabs("#slider li", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow",

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
  }).slideshow({autoplay: true}); // enable autoplay
  //$(".slidetabs").data("slideshow").play();
  
  //Add needed classe 
  
 /* $('#table-border table thead th').filter(':last').addClass('lastItem');
 
 if($('#schedules-section').length>0){
    $('#schedules-section #table-border tr td:nth-child(5),#schedules-section #table-border tr td:nth-child(6),#schedules-section #table-border tr td:nth-child(7),#schedules-section #table-border tr.first td:nth-child(8)').addClass('grey-background');
  }*/
  

	  
	
 
  
});	

$(window).load(function() {
	if($('#schedules-section').length>0){
		$('#schedules-section #table-border tr').each(function(index) {
			$(this).children('td').children('div').css('min-height',$(this).height()+'px');
		});
  	}
});	

$(window).load(function(){
	var balls = {
		ball1: $('#ball'),
		ball2: $('#ball1'),
		ball3: $('#ball2')
	}
	
	var ballStatus1 = false;
	var ballStatus2 = false;
	var ballStatus3 = false;
	
	var angle = 0;
	var angleRight = 0;
	
	var ScenAnimation = {
		ShowShadow: function(shadow, actionStatus){
			$('.'+ shadow).fadeIn(100, function(){
				if(!actionStatus){
					$('.'+ shadow).fadeOut(100);
				}
			});
		},
		
		BallAnimation: function(ball, rotateTo){
			setInterval(function(){
				if(rotateTo == 'right'){
					angle+=8;
			    	$("#"+ ball).rotate(angle);
			   	}
			   	else if(rotateTo == 'left'){
			   		angleRight-=8;
			    	$("#"+ ball).rotate(angleRight);
			   	}
			},50);
		},
		
		BallAnimationJumpA: function(){
			balls.ball1.delay(2000).animate({
				top: 700
			}, 1200, function(){
				ScenAnimation.ShowShadow('shadow-1', false);
				balls.ball1.animate({
					top: 300
				}, 500, function(){
					ScenAnimation.ShowShadow('shadow-1', false);
					balls.ball1.animate({
						top: 700
					}, 500, function(){
						ScenAnimation.ShowShadow('shadow-1', true);
						balls.ball1.animate({
							top: 500
						}, 400, function(){
							balls.ball1.animate({
								top: 700
							}, 300, function(){
								$(this).animate({
									'left': 1500
								}, 4000, function(){
									$(this).css({
										left: 1051,
										top: -51
									});
									if(!ballStatus1){
										setTimeout(ScenAnimation.BallAnimationJumpA, 2000);
										ballStatus1 = true;
									}
								});
								$('.shadow-1').animate({
									left: 1500
								}, 3900, function(){
									$(this).css({
										left: 1070,
										top: 734,
										'display': 'none'
									});
								});
							});
						});
					});
				});
			});
		},
		
		BallAnimationJumpB: function(){
			balls.ball2.delay(2000).animate({
				top: 645
			}, 1800, function(){
				ScenAnimation.ShowShadow('shadow-2', false);
				balls.ball2.animate({
					top: 535,
					left: 166
				}, 300, function(){
					$('.shadow-2').css('left', 136);
					ScenAnimation.ShowShadow('shadow-2', false);
					balls.ball2.animate({
						top: 645,
						left: 125
					}, 300, function(){
						balls.ball2.animate({
							top: 567,
							left: 71
						}, 200, function(){
							ScenAnimation.ShowShadow('shadow-2', true);
							$('.shadow-2').css('left', 45);
							balls.ball2.animate({
								top: 645,
								left: 35
							}, 100, function(){
								$(this).animate({
									left: -50
								}, 1000, function(){
									$(this).css({
										left: 205,
										top: -51
									});
									if(!ballStatus2){
										setTimeout(ScenAnimation.BallAnimationJumpB, 2000);
										ballStatus2 = true;
									}
								});
								$('.shadow-2').animate({
									left: -50
								}, 1000, function(){
									$(this).css({
										left: 215,
										top: 673,
										'display': 'none'
									});
								});
							});
						});
					});
				});
			});
		},
		
		BallAnimationJumpC: function(){
			balls.ball3.delay(2000).animate({
				top: 525
			}, 1800, function(){
				ScenAnimation.ShowShadow('shadow-3', false);
				balls.ball3.animate({
					top: 465,
					left: 220
				}, 300, function(){
					balls.ball3.animate({
						top: 525,
						left: 215
					}, 300, function(){
						$('.shadow-3').css('left', 222);
						ScenAnimation.ShowShadow('shadow-3', false);
						balls.ball3.animate({
							top: 500,
							left: 200
						}, 200, function(){
							balls.ball3.animate({
								top: 525,
								left: 180
							}, 100, function(){
								$('.shadow-3').css('left', 186);
								ScenAnimation.ShowShadow('shadow-3', true);
								$(this).animate({
									left: -50
								}, 3000, function(){
									$(this).css({
										left: 220,
										top: -51
									});
									if(!ballStatus3){
										setTimeout(ScenAnimation.BallAnimationJumpC, 2000);
										ballStatus3 = true;
									}
								});
								$('.shadow-3').animate({
									left: -50
								}, 3000, function(){
									$(this).css({
										left: 237,
										top: 545,
										'display': 'none'
									});
								});
							});
						});
					});
				});
			});
		}
	};
	
	if($.browser.msie){
		if(parseInt($.browser.version) > 8){
			ScenAnimation.BallAnimation('ball', 'right');
			ScenAnimation.BallAnimation('ball1', 'left');
			ScenAnimation.BallAnimation('ball2', 'left');
		}
	}
	else{
		ScenAnimation.BallAnimation('ball', 'right');
		ScenAnimation.BallAnimation('ball1', 'left');
		ScenAnimation.BallAnimation('ball2', 'left');
	}
	
	setTimeout(function(){
		ScenAnimation.BallAnimationJumpA()
	}, 2000);
	setTimeout(function(){
		ScenAnimation.BallAnimationJumpB()
	}, 500);
	setTimeout(function(){
		ScenAnimation.BallAnimationJumpC()
	}, 3000);
	
});
