marqueeVars.timePassed = 0;
marqueeVars.autoPlay = true;
var newHTML = '<div class="marquee_stage_large"><div class="marquee_container_1"></div><div class="marquee_nav"></div><div class="btn prev"></div><div class="btn next"></div></div>';
$('.marquee').html('').append(newHTML);

for( i=0; i<marqueeVars.totalPanels; i++ ){
	$('.marquee_nav').append('<div></div>');
}

$('.marquee').hover(function(){
	marqueeVars.autoPlay = false;
},function(){
	marqueeVars.autoPlay = true;
	marqueeVars.timePassed = Math.floor(marqueeVars.timeToChange / 2);
	
});

$('.marquee .btn').on('click', function(){
	
	if( !marqueeVars.inTransition )
		
		if( $(this).hasClass('prev') ){
			marqueeVars.currentPanel -= 1;
			if( marqueeVars.currentPanel < 1 ){
				marqueeVars.currentPanel = marqueeVars.totalPanels;
			}
		} else {
			marqueeVars.currentPanel += 1;
			if( marqueeVars.currentPanel > marqueeVars.totalPanels ){
				marqueeVars.currentPanel = 1;
			}
			
		}
		
		$('.marquee_nav div:nth-child('+marqueeVars.currentPanel+')').trigger('click');
		
	}
});

$('.marquee_nav div').on('click', function(){
	
	if( !marqueeVars.inTransition ){
		
		marqueeVars.inTransition = true;
		
		var navClicked = $(this).index();
		marqueeVars.currentPanel = navClicked + 1;
		
		$('.marquee_nav div').removeClass('selected');
		$(this).addClass('selected');
		
		$('.marquee_stage_large').append('<div class="marquee_container_2"></div>');
		$('.marquee_container_2').html(marqueeVars.panelContent[navClicked]).css({left:'-1100px'}).animate({left:'0px'},marqueeVars.duration).delay(3000);

		$('.marquee_container_2').animate({left:'1100px'},marqueeVars.duration,function(){
			$('.marquee_container_1').remove();
			$(this).addClass('marquee_container_1').removeClass('marquee_container_2');
			marqueeVars.inTransition = false;
			
		});
	}
	
});

$('.marquee_nav div:first').trigger('click');
