var totalImages;
var basePath ;
function fetchImages(nid,type,basePth){
	var curentImageNo = 1;
	basePath = ""; //basePth;
	$(".imagesSlideshowContainer").ajaxStart(function(){
		$(this).html("<div style='text-align:center; padding-top:200px;'><img src='"+basePath+"sites/all/themes/skotspot/images/ajaxloading.gif' /></div>");
	});
	$(".imagesSlideshowContainer").empty();
	$(".imagesSlideshowLeftArrow").empty();
	$(".imagesSlideshowRightArrow").empty();
	$(".showHightlightCircle").empty();
	$(".imagesTitles").empty();
	var getPageWidth = $(window).width();
	var getPageHeight = $(window).height();
	$(".page-content-blocker").css({'width':getPageWidth,'height':getPageHeight});
	$(".page-content-blocker").fadeTo("fast",0.8);
	$(".page-content-blocker").fadeIn("slow");
	$(".imageSliderShow_container_wrapper").fadeIn("slow");
	$.get(basePath+"/getImagesList.php",  { "image_nid": nid, "image_type":type },
   	function(data){
		totalImages = data.totalImages;
		if(totalImages>1){
			var showHightlightCircle = "";
			for(var i=1;i<=totalImages;i++){
				if(i==curentImageNo){
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt_crnt.jpg' /> ";
				}else{
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt.jpg' /> ";
				}
			}
			$(".showHightlightCircle").html(showHightlightCircle);
		}
		$(".imagesSlideshowContainer").fadeIn("slow",function(){
			$(this).html(data.imagesList)
		});
		$(".imagesTitles").html(data.imagesTitle);
		if(totalImages > curentImageNo){
			curentImageNo++;
			var nextImageLink = "<a href='javascript:void();' onclick=javscript:getNextSlideShow("+nid+","+curentImageNo+");><img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_right_arrow.jpg' /></a>";
			$(".imagesSlideshowRightArrow").html(nextImageLink);
		}
		else{
			$(".imagesSlideshowRightArrow").empty();
		}
   }, "json");
}

function getNextSlideShow(nid,curtImgeNo){
	$(".imagesSlideshowContainer").ajaxStart(function(){
		$(this).html("<div style='text-align:center; padding-top:200px;'><img src='"+basePath+"sites/all/themes/skotspot/images/ajaxloading.gif' /></div>");
	});
	$.get(basePath+"getImagesList.php",  { "image_nid": nid, "currntImgNo":curtImgeNo },
   	function(data){
		totalImages = data.totalImages;
		if(totalImages>1){
			var showHightlightCircle = "";
			for(var i=1;i<=totalImages;i++){
				if(i==curtImgeNo){
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt_crnt.jpg' /> ";
				}else{
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt.jpg' /> ";
				}
			}
			$(".showHightlightCircle").html(showHightlightCircle);
		}
		$(".imagesSlideshowContainer").fadeIn("slow",function(){
			$(this).html(data.imagesList)
		});
		$(".imagesTitles").html(data.imagesTitle);
		if(totalImages > curtImgeNo){
			var tempNextImageNo = curtImgeNo+1;//var tempNextImageNo = curentImageNo;
			var nextImageLink = "<a href='javascript:void();' onclick=javscript:getNextSlideShow("+nid+","+tempNextImageNo+");><img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_right_arrow.jpg' /></a>";
			$(".imagesSlideshowRightArrow").html(nextImageLink);
		}
		else{
			$(".imagesSlideshowRightArrow").empty();
		}
		if(curtImgeNo>1){
			var tempPrevImageNo = curtImgeNo-1;
			var nextImageLink = "<a href='javascript:void();' onclick=javscript:getPrevSlideShow("+nid+","+tempPrevImageNo+");><img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_left_arrow.jpg' /></a>";
			$(".imagesSlideshowLeftArrow").html(nextImageLink);
		}else{
			$(".imagesSlideshowLeftArrow").empty();
		}
   }, "json");
}
function getPrevSlideShow(nid,curtImgeNo){
	$(".imagesSlideshowContainer").ajaxStart(function(){
		$(this).html("<div style='text-align:center; padding-top:70px;'><img src='"+basePath+"sites/all/themes/skotspot/images/ajaxloading.gif' /></div>");
	});
	$.get(basePath+"getImagesList.php",  { "image_nid": nid, "currntImgNo":curtImgeNo },
   	function(data){
		totalImages = data.totalImages;
		if(totalImages>1){
			var showHightlightCircle = "";
			for(var i=1;i<=totalImages;i++){
				if(i==curtImgeNo){
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt_crnt.jpg' /> ";
				}else{
					showHightlightCircle += "<img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_circle_hlt.jpg' /> ";
				}
			}
			$(".showHightlightCircle").html(showHightlightCircle);
		}
		$(".imagesSlideshowContainer").fadeIn("slow",function(){
			$(this).html(data.imagesList)
		});
		$(".imagesTitles").html(data.imagesTitle);
		if(totalImages > curtImgeNo){
			var tempNextImageNo = curtImgeNo+1;
			var nextImageLink = "<a href='javascript:void();' onclick=javscript:getNextSlideShow("+nid+","+tempNextImageNo+");><img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_right_arrow.jpg' /></a>";
			$(".imagesSlideshowRightArrow").html(nextImageLink);
		}
		else{
			$(".imagesSlideshowRightArrow").empty();
		}
		if(curtImgeNo>1){
			var tempPrevImageNo = curtImgeNo-1;
			var nextImageLink = "<a href='javascript:void();' onclick=javscript:getPrevSlideShow("+nid+","+tempPrevImageNo+");><img src='"+basePath+"sites/all/themes/skotspot/images/slideshow_left_arrow.jpg' /></a>";
			$(".imagesSlideshowLeftArrow").html(nextImageLink);
		}else{
			$(".imagesSlideshowLeftArrow").empty();
		}
   }, "json");
}

/* Slider Pagination Start */

$(document).ready(function(){

	$(".custom_paging_bottom").click(function(){
		$(".hideGalleryImages").fadeTo("fast",0.7);
		$(".hideGalleryImages").fadeIn("slow");
		$(".hideGalleryImages").ajaxStart(function(){
			$(this).html("<div style='text-align:center; padding-top:143px;'><img src='/skotspot_new/sites/all/themes/skotspot/images/ajaxloading.gif' /></div>");
		});
		var a = $(".custom_paging_bottom .item-list .pager li.pager-next > a").attr('href');
		if(a){
			$.get(a, '',
			function(data){
				$(".hideGalleryImages").fadeOut("slow");
				$("div.right_section_content").find(".custom_paging_top").html($(data).find("div.right_section_content").find(".custom_paging_top").html());
				$("div.right_section_content").find(".custom_paging_bottom").html($(data).find("div.right_section_content").find(".custom_paging_bottom").html());
				var currentContent = $("div.right_section_content").find(".print_design_thumbnail_container_innergroup").html();
				$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").html(currentContent + $(data).find(".print_design_thumbnail_container_innergroup").html());
				$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").animate({
					marginTop : "-340px"
				}, 2000, function(){
					for(var k=8; k>=1; k--){
						$(".print_design_thumbnail_container_innergroup > .print_thumnails_images_container:nth-child("+k+")").remove();
						}
						$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").css({"margin-top":"0px"});
					});
				}, "html");
			}
		return false;
	});
	
	
	$(".custom_paging_top").click(function(){
		$(".hideGalleryImages").fadeTo("fast",0.7);
		$(".hideGalleryImages").fadeIn("slow");
		$(".hideGalleryImages").ajaxStart(function(){
			$(this).html("<div style='text-align:center; padding-top:143px;'><img src='/skotspot_new/sites/all/themes/skotspot/images/ajaxloading.gif' /></div>");
		});
		var a = $(".custom_paging_top .item-list .pager li.pager-previous > a").attr('href');
		if(a){
			$.get(a, '',
			function(data){
				$(".hideGalleryImages").fadeOut("slow");
				$("div.right_section_content").find(".custom_paging_top").html($(data).find("div.right_section_content").find(".custom_paging_top").html());
				$("div.right_section_content").find(".custom_paging_bottom").html($(data).find("div.right_section_content").find(".custom_paging_bottom").html());
				var currentContent = $("div.right_section_content").find(".print_design_thumbnail_container_innergroup").html();
				$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").html($(data).find(".print_design_thumbnail_container_innergroup").html() + currentContent);
				$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").css({"margin-top":"-340px"});
				$("div.right_section_content").find(".print_design_thumbnail_container_innergroup").animate({
					marginTop : "0px"
				}, 2000, function(){
					for(var k=16; k>=9; k--){
						$(".print_design_thumbnail_container_innergroup > .print_thumnails_images_container:nth-child("+k+")").remove();
					}
				});
			}, "html");
		}
		return false;
	});
	
});

/* Slider Pagination End */
