$(document).ready(function(){			  
	
	$('.carousel li a').addClass('affiliateLogo');
	
	$('li.mainNavItem a').mouseenter(function(){
		var p = $(this).position();
		$(this).append($(this).parent().find('.dropDown').show());
	});
			
	$('li.mainNavItem a').mouseleave(function(){
		$(this).parent().find('.dropDown').hide();
	});
			
	var page = "";
	$('li.mainNavItem a').click(function(e){
		e.preventDefault();
		e.stopPropagation();
		
		document.location.href = $(this).attr('href');
		//$(this).parent().find('.dropDown').hide();
	});
			
	$('.copyContainer .supplier').each(function(){
		var copyHeight = $(this).find('.list ul').height();				
		var containerHeight = $(this).height();
		
		var padding = ((containerHeight/2) - (copyHeight/2));
		
		$(this).find('ul').css({'padding-top':padding});
	});


			
	$('.galleryContainer img').width(150);
	$('.selectedImage img').width(900);
	/*
	$('.thumbnails li').click(function(){
		$('.selectedImage img').attr('src',$(this).find('img').attr('src'));
		$('.totalImages span.imageCount').text( $(this).attr('rel') );
		$('.totalImages span.imageDescription').text( $(this).find('img').attr('alt') );
	});	
	*/
	
	
	if($('.galleryContainer').length > 0){
		$('.galleryContainer a').lightBox();
	}
	

	
	var width = 0;
	var initialWidth = 0;
	
	$('.carousel .affiliateLogo').each(function(){
		width += $(this).width();
	});
	
	$('.carousel').width(width);
	initialWidth = width;
	
	var animationPaused = 0;
	
	$(".carousel").hover(function(){
		$(this).pauseAnimation();
		animationPaused = 1;
	}, function(){
		$(this).resumeAnimation();
		animationPaused = 0;
	});
	
	function ticker(){
		
		if(animationPaused == 1)
			return true;
	
		$(".carousel").startAnimation({
			left: "-=" + initialWidth
		}, 15000, "linear", function() {
			$(".carousel").css({"left":"0"});
			$(".removable").remove();
			$(".carousel").width(initialWidth);
			i=0;
			ticker();
		});
	}
	
	ticker();
	  
	  var i=0;
	  var tid = setInterval(mycode, 200);
	  function mycode() {
	  
	  	if(animationPaused == 1)
			return true;
	  
		var position = $('.carousel:eq(0)').position();
		var currItemWidth = $('.affiliateLogo:eq('+ i +')').width();
		var currentItem = '';
		
		if( i < $('.affiliateLogo').length ){
			if(-position.left > (i*currItemWidth) + currItemWidth ){
				//console.log( ">" + i + "----" + ( -position.left ) );
				
				currentItem = $('.affiliateLogo:eq('+ i +')').parent().clone();
				currentItem.find('a').addClass('removable');
				
				$('ul#carousel').append(currentItem);
				width = $('.carousel').width();
				width += currentItem.find('a').width();
				$('.carousel').width(width);
				i++;
			}
		}
		
		
	  }			  
});
