var cloud_array=new Array(
'personal&nbsp;care',
'bath&nbsp;and&nbsp;body',
'body&nbsp;lotion',
'soaps',
'moisturizer',
'body&nbsp;cleansers',
'body&nbsp;wash',
'hair&nbsp;removal',
'exfoliators',
'hand&nbsp;cream',
'deodorant',
'bubble&nbsp;bath',
'shower&nbsp;gel',
'shaving&nbsp;cream',
'bath&nbsp;salts',
'bath&nbsp;oil',
'body&nbsp;oils',
'foot&nbsp;cream',
'body&nbsp;scrubs',
'beauty&nbsp;tools',
'hair&nbsp;straightener',
'blow&nbsp;dryer',
'make&nbsp;up&nbsp;brushes',
'skincare&nbsp;tools',
'eyelash&nbsp;curler',
'mirrors',
'hair&nbsp;brush',
'ceramic&nbsp;flat&nbsp;irons',
'curling&nbsp;iron',
'blush&nbsp;brush',
'tweezers',
'pedicure&nbsp;set',
'manicure&nbsp;set',
'toothbrush',
'toothbrush&nbsp;set',
'teeth&nbsp;whitening',
'ladies&nbsp;shaver',
'brush&nbsp;set',
'fragrance',
'perfume',
'perfume&nbsp;set',
'scented&nbsp;oils',
'body&nbsp;spray',
'fragrance&nbsp;sale',
'scented&nbsp;creams',
'gifts&nbsp;for&nbsp;her',
'gift&nbsp;ideas',
'value&nbsp;sets',
'gifts',
'gift&nbsp;sets',
'bath&nbsp;sets',
'hair&nbsp;care',
'shampoo',
'conditioner',
'hair&nbsp;treatment',
'hairstyling&nbsp;products',
'scalp&nbsp;treatment',
'make&nbsp;up',
'cosmetics',
'make&nbsp;up&nbsp;deals',
'lipstick',
'eye&nbsp;shadow',
'make&nbsp;up&nbsp;remover',
'lip&nbsp;balms',
'blush',
'bronzer',
'concealer',
'foundation',
'mascara',
'eyeliner',
'eye&nbsp;make&nbsp;up&nbsp;remover',
'cream&nbsp;foundation',
'liquid&nbsp;foundation',
'powder&nbsp;foundation',
'make&nbsp;up&nbsp;bag',
'make&nbsp;up&nbsp;set',
'eye&nbsp;shadow&nbsp;set',
'lip&nbsp;gloss',
'natural',
'organic',
'natural&nbsp;soap',
'organic&nbsp;make&nbsp;up',
'organic&nbsp;shampoo',
'natural&nbsp;shampoo',
'organic&nbsp;perfume',
'skincare',
'face&nbsp;cleanser',
'face&nbsp;cream',
'acne&nbsp;treatment',
'wrinkle&nbsp;cream',
'face&nbsp;masks',
'face&nbsp;scrubs',
'eye&nbsp;treatment',
'toners',
'pore&nbsp;treatment',
'eye&nbsp;cream',
'lip&nbsp;treatment',
'shine&nbsp;control',
'aging&nbsp;cream',
'night&nbsp;treatments',
'blemish&nbsp;control',
'top&nbsp;rated&nbsp;cleansers',
'anti-aging&nbsp;serum',
'anti-aging&nbsp;cream',
'facial&nbsp;cream',
'wrinkle&nbsp;serum'
);


$(document).ready(function(){
/*
	$(window).scroll(function() {
		$('.scrlbtn').stop().animate({top: $(document).scrollTop()+125},'slow','easeOutBack');
	});
*/
	var listing_slide_width = 676;
	//var n = $('.listing_slide').length*listing_slide_width;
	//$('.products').css('width', n+'px');
	$('.listing').hover(function()
	{
	$(this).addClass('listing_roll');
	},function()
	{
	$(this).removeClass('listing_roll');
	})
/* 	$('.scroll-pane').jScrollPane({showArrows:true}); */
	$('body').pngFix();
	populateCloud();
	setTimeout(startCloudRotation,3000);
	initGallery();
	initFeaturedArticles();
	initProducts();
});

function initProducts(){
	var listing_slide_width = 676;

	count = 0;
	total_slides = $('.listing_slide').length;
	$('.product_rightarrow').click(function(){
		count++;
		if(count==total_slides){count=0};
		$('.products').stop().animate({left: -1*(count*listing_slide_width)+'px'},600,'easeOutExpo')	
	});
	$('.product_leftarrow').click(function(){
		count--;
		if(count==-1){count=total_slides-1};
		$('.products').stop().animate({left: -1*(count*listing_slide_width)+'px'},600,'easeOutExpo')	
	
	});
	
	$('.show_next').click(function(){
		count++;
		if(count==total_slides){count=0};
		$('.show_next').removeClass('active');
		$(this).addClass('active');
		$('.products').stop().animate({left: -1*(count*listing_slide_width)+'px'},600,'easeOutExpo')	
	});
}

function populateCloud(){
for (i=0;i<=25;i++){
random_num = Math.floor(Math.random()*(cloud_array.length-1));
link = getLink(random_num);
random_size = 10;
$('.cloud').append('<li class="cloud_element"><a href="'+link+'" style="font-size:'+random_size+'px;">'+cloud_array[random_num]+'</a></li>');
}
}

function startCloudRotation(){
random_num = Math.floor(Math.random()*(cloud_array.length-1));
link_url = getLink(random_num);
random_size = 10;
$('.cloud').prepend('<li class="cloud_element" style="display:none"><a href="'+link_url+'" style="font-size:'+random_size+'px;">'+cloud_array[random_num]+'</a></li>');
$('.cloud').find('.cloud_element').last().fadeOut(1000,function(){($(this).remove())});
$('.cloud').find('.cloud_element').first().animate({'width':'toggle'},1000);
setTimeout(startCloudRotation,10000);
}

			
function getRandomSize(){
	random=Math.floor(Math.random()*15);
	if (random<2){
		size='23';
	}
	else if(random>1&&random<4){
		size='17';
	}
	else{
		size='10'
	}
return size;
}

function getLink(array_num){
	if(array_num<=18){
		link = 'http://www.personalcare.com/bath-and-body'
	}
	else if(array_num<=37){
		link = 'http://www.personalcare.com/beauty-tools'
	}
	else if(array_num<=44){
		link = 'http://www.personalcare.com/fragrance'
	}
	else if(array_num<=50){
		link = 'http://www.personalcare.com/gifts-for-her'
	}
	else if(array_num<=56){
		link = 'http://www.personalcare.com/hair-care'
	}
	else if(array_num<=77){
		link = 'http://www.personalcare.com/make-up'
	}
	else if(array_num<=84){
		link = 'http://www.personalcare.com/natural-and-organic'
	}
	else if(array_num<=105){
		link = 'http://www.personalcare.com/skincare'
	}
	return link;
}



function initGallery(){
	var currentSlide=0;
	var totalSlides= $('.slide').length;
/* 	$('.g_con_inner').css('width', (totalSlides*742)+'px'); */
	$('.gallery').hover(
		function(){
			$('.l_ar').stop().animate({'left': '0px'},500)
			$('.r_ar').stop().animate({'right': '0px'},500)
		},function(){
			$('.l_ar').stop().animate({'left': '-31px'},500)
			$('.r_ar').stop().animate({'right': '-31px'},500)
	})
	$('.r_ar').click(function(){
		currentSlide++;
		if (currentSlide==totalSlides){
		currentSlide=0;
		}
		$('.g_con_inner').stop().animate({'left': '-'+(742*currentSlide)+'px'},500,'easeOutExpo')
		
	});
	$('.l_ar').click(function(){
		currentSlide--;
		if (currentSlide==-1){
		currentSlide=totalSlides-1;
		}
		$('.g_con_inner').stop().animate({'left': '-'+(742*currentSlide)+'px'},500,'easeOutExpo')
	});
}

function initFeaturedArticles(){
	var arrows_enabled=true;
	$('.featured_article').css('opacity',0);
	$('.featured_article').last().css('opacity',1);
	
	
	$('.featured_article').find('.text').css('opacity' , 0)
	$('.featured_article').last().find('.text').css('opacity' , 1)
	
	
	
	$('.right_arrow').click(function(){
		if (arrows_enabled==true){
			arrows_enabled=false;
			$('.featured_article').eq($('.featured_article').length-2).css('opacity',1);
			$('.featured_article').eq($('.featured_article').length-2).find('.text').animate({'opacity' : 1},500);
			$('.featured_article').last().animate({'opacity' : 0},500,function(){
				$(this).prependTo('.featured_article_container');
				$('.featured_article').first().find('.text').css('opacity' , 0);
				$('.featured_article').first().css('opacity' , 1);
				arrows_enabled=true;
			})
		}
	})
	
	$('.left_arrow').click(function(){
		if (arrows_enabled==true){
			arrows_enabled=false;
			$('.featured_article').first().css('opacity',0);
			$('.featured_article').last().find('.text').animate({'opacity': 0},500)
			$('.featured_article').first().appendTo('.featured_article_container');
			$('.featured_article').last().find('.text').animate({'opacity': 1},500);
			$('.featured_article').last().animate({'opacity' : 1},500,function(){
				arrows_enabled=true;
			})
		}
	})
}
