$(function() {

/* Homepage slider
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
    $('#slider ul').jcarousel({
        auto: 7,
		vertical: true,
        scroll: 1,
        visible:1,
        wrap: "both",
//		initCallback: mycarousel_initCallback,
        buttonPrevHTML: null,
        buttonNextHTML: null,
		initCallback: function(jc, state) { 

		if (state == 'init') { 

			// Insert a play/pause button between the prev/next buttons 
			$('a#prev').after('<a id="pause">Pause</a>');   
	
	
			/* Override the internal startAuto() method, which is called after 
			 * animations complete, to prevent next/prev buttons from reactivating 
			 * the timer while in the pause state. 
			 */ 
			jc.startAutoOrig = jc.startAuto; 
			jc.startAuto = function() { 
			  if (!jc.paused) { 
				jc.startAutoOrig(); 
			  } 
			} 
	
			jc.pause = function() { 
			  $('a#pause') 
				.removeClass('jcarousel-play-vertical') 
				.addClass('jcarousel-pause-vertical'); 
			  jc.paused = true; 
			  jc.stopAuto(); 
			}; 
	
			jc.play = function() { 
			  $('a#pause') 
				.removeClass('jcarousel-pause-vertical') 
				.addClass('jcarousel-play-vertical'); 
			  jc.paused = false; 
			  jc.startAuto(); 
			}; 
	
			// Click event for playback toggle button, conditionally calls play/pause 
			$('a#pause').click(function(){ 
			  if (jc.paused) { 
                jc.play(); 
				$('a#pause').html('Pause');
			  } else { 
                jc.pause(); 
				$('a#pause').html('Play');
		      }  
			}); 
		  } 
	
	
		  jc.play(); 
		jQuery('#next').bind('click', function() {
			jc.next();
			return false;
		});
	
		jQuery('#prev').bind('click', function() {
			jc.prev();
			return false;
		});
		} 
	});
/*
	function mycarousel_initCallback(carousel) {
		jQuery('#next').bind('click', function() {
			carousel.next();
			return false;
		});
	
		jQuery('#prev').bind('click', function() {
			carousel.prev();
			return false;
		});
	};	   
*/


/* Top Contact Panel
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	$('#contact').css(  'top',  -1*$('#contact').height()-41);
	$('#tabs .tab').each(function(){
		$(this).css('bottom', -1*$(this).height())
	});
	
	$('.section.last a').click(function(){
		$('a.close-btn').fadeOut(500);
		$('#contact').animate({top: -1*$('#contact').height() }, 500, 'linear');
		$('.demo-btn').addClass('active');
		$('#demo-tab').css('z-index',4).stop(true, true).animate({bottom: 0}, { duration:500, easing: 'linear' }).addClass('active');
		return false;
	})

	$('a.contact-btn').click(function(){
		$('#contact').animate({top:'0'}, {
			queue: false,
			duration: 500,
			easing: 'linear',
			complete: function(){
				$('.close-btn').fadeIn(200);
			}
		});
		$('#main .shell').addClass('secondary');
		if($('.company-btn').hasClass('active')) {
			$('.company-btn').removeClass('active');
			$('#company-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#company-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
		if($('.video-btn').hasClass('active')) {
			$('.video-btn').removeClass('active');
			$('#testimonials-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#testimonials-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
		if($('.demo-btn').hasClass('active')) {
			$('.demo-btn').removeClass('active');
			$('#demo-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#demo-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
	})
	$('a.btnRequest').click(function(){
		$('#contact').animate({top:'0'}, {
			queue: false,
			duration: 500,
			easing: 'linear',
			complete: function(){
				$('.close-btn').fadeIn(200);
			}
		});
		$('#main .shell').addClass('secondary');
		if($('.company-btn').hasClass('active')) {
			$('.company-btn').removeClass('active');
			$('#company-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#company-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
		if($('.video-btn').hasClass('active')) {
			$('.video-btn').removeClass('active');
			$('#testimonials-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#testimonials-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
		if($('.demo-btn').hasClass('active')) {
			$('.demo-btn').removeClass('active');
			$('#demo-tab').css('z-index', 5).stop(true, true).animate({bottom: -1*$('#demo-tab').height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		}
	})

	$('a.close-btn').click(function(){
		$(this).fadeOut(500);
		$('#contact').animate({top: -1*$('#contact').height() }, 500, 'linear');
		$('#main .shell').removeClass('secondary');
	})


/* Bottom Tabs and Panels
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	$('#tabs .tab .nav li').hover(function(){
		$(this).addClass('hover').find('.dd').stop(true,true).slideDown(300);
	}, function(){
		$(this).removeClass('hover').find('.dd').slideUp(300);
		
	})

	$('.tabs-nav a').click(function(){
		$('a.close-btn').fadeOut(500);
		$('#contact').animate({top: -1*$('#contact').height() }, 500, 'linear');

		if($(this).hasClass('active')) {
			$(this).removeClass('active');
			$('#main .shell').removeClass('secondary');
			var activeItem = $(this).attr('href');
			var currentItem = ('#'+$('#tabs .tab.active').attr('id'));
			$(currentItem).css('z-index', 5).stop(true, true).animate({bottom: -1*$(currentItem).height()}, { duration:500, easing: 'linear' }).removeClass('active');
			return false;
		} else {
			$('#main .shell').addClass('secondary');
			$('.tabs-nav a.active').removeClass('active');
			$(this).addClass('active');
			var activeItem = $(this).attr('href');
			var currentItem = ('#'+$('#tabs .tab.active').attr('id'));
			$(currentItem).css('z-index', 5).stop(true, true).animate({bottom: -1*$(currentItem).height()}, { duration:500, easing: 'linear' }).removeClass('active');
			$(activeItem).css('z-index',4).stop(true, true).animate({bottom: 0}, { duration:500, easing: 'linear' }).addClass('active');
			return false;
		}
	})
	
	$('.close-tab-btn').click(function(){
		$('#main .shell').removeClass('secondary');
		$('.tabs-nav a.active').removeClass('active');
		var currentItem = ('#'+$('#tabs .tab.active').attr('id'));
		$(currentItem).css('z-index', 5).animate({bottom: -1*$(currentItem).height()}, { duration:500, easing: 'linear', complete: function(){ $(currentItem).removeClass('active') }  });
		return false;
	})

});




