function ajaxGetImageDotHtml(urlen, placeholderID, obj){
	$jq(obj).parent().parent().find(".active").removeClass("active");
	$jq(obj).parent().addClass("active");
	var urlen = "/default" + urlen.slice(urlen.lastIndexOf('.'),urlen.length);
	$jq.post(urlen, function(data) {		
		$jq("#overplaceholder" + placeholderID).html(data);
		if(nzTranslate.HomeCreator != undefined){
			createHomeCreatorButton("#overplaceholder" + placeholderID);
		}
		if(nzTranslate.SeeMoreDetail != undefined){
			createDetailButton("#overplaceholder" + placeholderID);
		}
	});
	
}

// Add See More Details Button
function createDetailButton(objID){
	$jq(".OverProductsContainer", $jq(objID)).find(".CampaignLine:last").after('<div class="button detail">' + nzTranslate.SeeMoreDetail + '</div>');
	$jq(".detail").click(function(){
		location.href = $jq(this).parent().parent().prev().attr("href");
	});
}

// Add Home Creator Button
function createHomeCreatorButton(objID){
	$jq(".OverProductsContainer", $jq(objID)).find(".CampaignLine:last").after('<div class="button home">' + nzTranslate.HomeCreator + '</div>');
	$jq(".home").click(function(){
		location.href = $jq(this).parent().parent().prev().attr("href") + "&hc=true";
	});
}

var placeholderID, numPlaceholderZIndex;
$jq(document).ready(function(){
	
	$jq(".ImageDotContainer").each(function(){
		$jq(".imageDot:eq(0)",$jq(this)).addClass("active");
		$jq(".imageDot",$jq(this)).each(function(n){
			$jq(this).append(n+1);
		});
	});
	
	$jq(".OverImageDotContainer").each(function(){
		$jq(".imageDot:eq(0)",$jq(this)).addClass("active");
		$jq(".imageDot a",$jq(this)).each(function(n){
			$jq(this).append(n+1);
		});
	});
	
	$jq(this).find(".ImageDotLink").click(
		function(){
			$jq(this).parent().parent().find("a").removeClass("Active");
			$jq(this).addClass("Active");
		}
	);
		
	$jq(".NormalPlaceholder").hover(
		//On Mouse Over - Show Placeholder
		function(){
			//Get placeholder ID from ID attribute
			placeholderID = $jq(this).attr('id');
			placeholderID = placeholderID.replace("normalplaceholder","");
			
			$jq("#masterDiv" + placeholderID).parent().show();
			$jq("#masterDiv" + placeholderID).show();
			$jq("#overplaceholder" + placeholderID).show();
			
			numPlaceholderZIndex = $jq(this).css('zIndex');
			$jq(this).css('zIndex',1000);
		},
		//On Mouse Out - Hide Placeholder
		function(){
			//Get placeholder ID from ID attribute
			placeholderID = $jq(this).attr('id');
			placeholderID = placeholderID.replace("normalplaceholder","");
			//If the first dot is not active, reset dots so first dot is active and content matches first dot.
			if(!$jq(".OverImageDotContainer .imageDot:eq(0)", $jq(this)).hasClass("active") && $jq(".OverImageDotContainer .imageDot a", $jq(this)).length>0){
				var strOnClick = $jq(".OverImageDotContainer .imageDot a:eq(0)", $jq(this)).attr("onclick").toString();
				var strUrl = "/default" + strOnClick.slice(strOnClick.lastIndexOf('.'),strOnClick.indexOf(',')-1);
				ajaxGetImageDotHtml(strUrl, placeholderID);
				$jq(".OverImageDotContainer .imageDot", $jq(this)).each(function(){
					if($jq(this).hasClass("active")){
						$jq(this).removeClass("active")
					}
				});
				$jq(".OverImageDotContainer .imageDot:eq(0)", $jq(this)).addClass("active");
			}
			
			$jq("#masterDiv" + placeholderID).parent().hide();
			$jq("#masterDiv" + placeholderID).hide(); 
			$jq("#overplaceholder" + placeholderID).hide();
			
			$jq(this).css('zIndex',numPlaceholderZIndex);
		}
	);
	
	

	//Fix zIndex values for IE
	var zIndex = 980;
	$jq(".NormalPlaceholder").each(function(){
		$jq(this).css('z-index',zIndex);
		zIndex--;
	});
	
});
