function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};

var dPhone = getCookie('dermphone');

/* VIDEO/IMAGE GALLERY FUNCTIONS */
var imageFlowGallery = null;
var videoPlayerVids = Array();
var currentVideoID = "0";

function onTemplateLoaded(experienceId) {
	videoPlayerVids["vid"+experienceId] = brightcove.getExperience(experienceId).getModule(APIModules.VIDEO_PLAYER);
	videoPlayerVids["vid"+experienceId].addEventListener(BCMediaEvent.COMPLETE, closeVideo);
	videoPlayerVids["vid"+experienceId].addEventListener(BCMediaEvent.PLAY, startVideo);
}
function closeVideo() {}
function startVideo(event){
	if(currentVideoID!=event.media.id.toString()){
		try{videoPlayerVids["vid"+currentVideoID].pause(true);}catch(e){};
		currentVideoID = event.media.id.toString();	
	}
}
function initVidImgGallery(){
	//$("#videoGallery a#btnImageFlow").click(function(){
			setTimeout(function(){if(imageFlowGallery==null){imageFlowGallery=new ImageFlow();imageFlowGallery.init({ImageFlowID:'ImageFlowGallery'});};}, 50);
	//});
	$("#videoGallery a.btn").click( function() {try{videoPlayerVids["vid"+currentVideoID].pause(true);}catch(e){};});
}



/** BAZAAR VOICE CODE **/
function reviewsPop(href) {window.open(href, 'custReviews','width=980,height=500,left=100,top=100,toolbar=no,location=no,scrollbars=yes,status=yes,resizable=yes,fullscreen=no');}
function initBazaarVoice(){
	try{
var bvReviewURL = "/product/beauty/derm-exclusive/customer-reviews.do";
/* var bvRatingStarClass = "BVstar-4-5"; FOR TESTING PURPOSES */
	$(".bvRatingStarClass").addClass(bvRatingStarClass);
	$(".bvRatingMessage").html(bvRating + " of 5 (<a href="+bvReviewURL+">" + bvReviewCount + " reviews</a>)");
	$(".bvReviewSubmission").attr("href", bvReviewSubmissionUrl);
	$(".bvCustomerReviews").attr('href', bvReviewURL);
	$("span.bvRatingMessage > a, .bvCustomerReviews").click( function() {
			reviewsPop(this.href);
			return false;
	});
	}catch(e){}
}
    
		
/** DROP SHADOWS for IE **/
function addIEShadows(){
	var shadowRadius = 10;
	var boxMargin = 15;
	
	$('div.shadow').each(function(i){
			var w = $(this).width();
			var h = $(this).height();
			var mtop = parseInt($(this).css("margin-top"));
			var mleft = parseInt($(this).css("margin-left"))-shadowRadius;	
			var mbottom = h+shadowRadius+boxMargin;
			if($(this).hasClass("box-partial")){
				mtop =  mtop+boxMargin;
				$(this).css("margin-top", (mtop+boxMargin)+"px");
				mbottom =  mbottom-boxMargin;
			}
			var t = '<div class="ie-shadow" style="width:'+w+'px; height:'+h+'px; margin-bottom:-'+mbottom+'px; margin-top:'+(mtop-(shadowRadius+boxMargin))+'px; margin-left:'+mleft+'px;"></div>';
			$(this).before(t)	;											
	});
};

function zoomBigpic(tar){
	
			var theBox =  $(tar).parents(".box").eq(0);
			var theParent = $(tar).parents(".item").eq(0);
			$("div.item", theBox).css("z-index", "1").find("img.bigimg").hide();;
			$(theParent).css("z-index", "500").find("img.bigimg").css({left: "101px",
														top: "155px",
														height: "10px",
														width: "10px"}).show().animate({
													   left: "-89px",
														top: "-40px",
														height: "400px",
														width: "400px"
													   
													   }, 200, "linear");
};

function hideBigpic(tar){
		var theParent = $(tar)
        $(tar).animate({ 
            left: "101px",
														top: "155px",
														height: "10px",
														width: "10px"
          }, 140, "linear", function(){
							 $(this).hide();
							 $(this).parents(".item").eq(0).css("z-index", "1");
					 } 
         );
  
};

function initFAQ(){
	$("#faq .content ul li p").hide();
	$("#faq .content ul li h3").toggle(
	function(){
		$(this).parent().addClass("active").find('p').slideDown(200);
	}, function(){
		$(this).parent().removeClass("active").find('p').slideUp(200);																						
	});
}

function logLink(linkname) {
  var s=window.s;
  s.linkTrackVars='eVar11,eVar30,prop30';
  s.eVar11=linkname;
  s.eVar30=linkname;
  s.prop30=linkname;
  s.tl(this,'o',linkname);
}

/* DOCUMENT READY */

$(document).ready(function(){
		
	
	$('a.modal').fancybox({overlayColor: '#000', width:500, height:830, showCloseButton:false, centerOnScroll:true, padding:0, margin:10})
	$('a.modalVideo').fancybox({overlayColor: '#000',  width:570,padding:0, centerOnScroll:true,onCleanup: function(){try{videoPlayerVids["vid"+currentVideoID].pause(true);}catch(e){};}});
	$('a.zoom').fancybox({autoDimensions: false, overlayColor: '#fff', width:381, height:496, showCloseButton:true, centerOnScroll:true, padding:0, margin:10});
	$('.prodzoom .p1 a').click(function(){
			$(this).parent().hide().next().show();																
	});
	$('.prodzoom .p2 a').click(function(){
			$(this).parent().hide().prev().show();																
	});
	
	/*
	$('a.zoom').each(function0(){
		$(this).click(function(){zoomBigpic(this);		 return false; });
	});
	$("img.bigimg").click(function(){
			hideBigpic(this);return false;											 
	});
	*/
														
	initFAQ();
	initBazaarVoice();
	initVidImgGallery();
	initAllSlideShows();
	if ($.browser.msie) { 
	addIEShadows();
	}

	if (dPhone != '') {
		$('.pinkbig').text(dPhone);
	}
	

}); 
