
  var mainpromo;
  var promowaiting;
  var speed = 15000;
  var speed2 = 18000;
  var running = false;
      $(document).ready(function() {
		
		$('#promoboxes').fadeIn('slow');
		$('#productPromo li:first-child').fadeIn('slow');
		 starttimer = window.setInterval("changeImage();", speed);
		 starttimerproduct = window.setInterval("changeProdImage();", speed2);
		 
		 $('#next').mouseover(function(event) {
			
			event.preventDefault()
				if(running == false){changeImage();};
		});
		$('#next').click(function(event) {
			
			event.preventDefault()
				if(running == false){changeImage();};
		}); 
		$('#promoboxes').hover(function(event) {
			event.preventDefault()
			window.clearInterval(starttimer);	 
				
		}, function(event) {
			event.preventDefault()
			starttimer = window.setInterval("changeImage();", speed);
		});
		 
		$('#info').hover(function(event) {
			event.preventDefault()
			window.clearInterval(starttimer);
			$('#mainImages .promo  .promocopy').fadeIn('slow');
			$(this).addClass('infonew');
		}, function(event) {
			event.preventDefault()
			starttimer = window.setInterval("changeImage();", speed);
			$('#mainImages .promo  .promocopy').fadeOut('slow');
			$(this).removeClass('infonew');
		});
		$('#info').click(function(event) {
			
			event.preventDefault()
			window.location = $('#mainImages .promoLink a').attr('href');
		});
		/*if($('#promoboxes li:last-child').index() < 2){
			 
			$('#next').css('display', 'none');
		}*/
      });


function changeImage(){
	if(running == false){
		
		running = true;
		window.clearInterval(starttimer);
		promowaiting = $('#promoboxes li:last-child').html().replace('block','none');
		mainpromo = $('#mainImages li').html().replace('none','block');
		//this replaceces .detach() because of 1.3.2 limitations
		if($('#promoboxes li').length +1  > $('#tempholder li').length) {
		$("#tempholder").prepend('<li style="display:none;">' + promowaiting + '</li>');
		//$("#tempholder").prepend('<li style="display:none;">' + mainpromo + '</li>');
		}
		//
		$('#mainImages .promo  .promocopy').css('display', 'none');
		$('#promoboxes li:last-child').fadeOut('slow', function() {
			//changed from .detach()
			$(this).remove();
			
				
				$('#promoboxes li').animate({top: '+=151'}, 1000, 'linear', function() {
					$('#mainImages .promo').fadeOut('slow');
					$('#mainImages li').hide( 'transfer', {to: "#dummy", className: 'ui-effects-transfer' }, 500,  function() {
						$("#promoboxes").prepend('<li style="display:none;">' + mainpromo + '</li>');
						
						$("#mainImages li").replaceWith('<li>' + promowaiting + '</li>');
						
						$('#promoboxes li').css('top', 0);
					
						$('#promoboxes li:first').fadeIn('slow', function() {
							running = false;
						});
					});
					
				
			  });
			  
				
		});
		 starttimer = window.setInterval("changeImage();", speed);
		
	};
}

function changeProdImage(){
	$('#productPromo li:first-child').fadeOut('slow', function() {
		var a = $('#productPromo li:first-child').html();
		//changed from .detach()
			$('#productPromo li:first-child').remove();
			$('#productPromo').append('<li style="display:none;">' + a + '</li>');
			
			$('#productPromo li:first-child').fadeIn('slow');
			
		//
		
	
	});
}
