var categoryId= 0;
var subCategoryId= 0;
var categoryCount= 0;
var uploadImageId = 0;
var selCategory = 0;
var selSubCategory = 0;
var current = 1;
function loadCategory(selcategoryId)
{
	$('#addSubCategoryForm').hide();
	$('#listCategory').load(hostname+"modules/loadCategory.php",{'categoryId': 0, 'action' : 'weblist'},function(msg){
	$('#showGallery').show();		
	$('#showGallery').load(hostname+"modules/loadGalleryImages.php",{'action': 'showAllImages'});
		
	});
}
function loadSubCategory(selcategoryId)
{
	current = 1;
	$('#dispPageNavMin').html(current);
        $('.pagenav').css('visibility','hidden');
	$('#galleryUploadForm').hide();
	$('#categoryList'+categoryId).removeClass('mainmenuactive');
	categoryId = selcategoryId;
	$('#categoryList'+categoryId).addClass('mainmenuactive');
	$('#listSubCategory').load(hostname+"modules/loadCategory.php",{'categoryId': categoryId, 'action' : 'weblist'},function(msg){
		if(msg.length>0)	
		{
			$('#content').show();
			var cc = msg.split("<a id=subCategoryList");
			cc = cc[1].split(" ");
			subCategoryId = cc[0];
			$('#subCategoryList'+subCategoryId).addClass('mainmenuactive');
			showGallery(0);
			$('#subCategoryContent').show();
			$('#contentTitle').html($('#subCategoryList'+subCategoryId).html());
			$('#contentMessage').load(hostname+"modules/loadCategory.php",{'categoryId': subCategoryId, 'action' : 'description'});
		}
		else
		{
			$('#content').hide();
		}
	});
}
function showSubCategory(selcategoryId,imgId, subCatId)
{
	subCategoryId = subCatId;
	        $('.pagenav').css('visibility','hidden');
	$('#galleryUploadForm').hide();
	categoryId = selcategoryId;
	$('#categoryList'+categoryId).addClass('mainmenuactive');
	$('#listSubCategory').load(hostname+"modules/loadCategory.php",{'categoryId': categoryId, 'action' : 'weblist'},function(msg){
		if(msg.length>0)	
		{
			$('#content').show();
			$('#subCategoryList'+subCategoryId).addClass('mainmenuactive');
			showGallery(imgId);
			$('#subCategoryContent').show();
			$('#contentTitle').html($('#subCategoryList'+subCategoryId).html());
			$('#contentMessage').load(hostname+"modules/loadCategory.php",{'categoryId': subCategoryId, 'action' : 'description'});
		}
		else
		{
			$('#content').hide();
		}
	});
}

function showImage(imgId, subCatId, catId)
{
	showSubCategory(catId, imgId, subCatId);
}

function showGallery(imgId)
{

               $('.pagenav').css('visibility','hidden');
	$('#showGallery').load(hostname+"modules/loadGalleryImages.php",{'action': 'showImage', 'imgId':'0' ,'currentImgId':imgId, 'subCategoryId' : subCategoryId},function(msg){
		if(imgId!=0)
		{
			var currentMessage = msg.split("CURRENT=");
			currentMessageID = currentMessage[1].split('</span>')
			current =currentMessageID[0];	
			chkpage();
		}
		else
		{
			chkpage();
		}
	 });
	$('#showGallery').show();
}

function selectSubCat(selSubCategoryId)
{
	current = 1;
	$('#dispPageNavMin').html(current);
	$('#subCategoryList'+subCategoryId).removeClass('mainmenuactive');
	subCategoryId  = selSubCategoryId;
	$('#subCategoryList'+subCategoryId).addClass('mainmenuactive');
	showGallery(uploadImageId);
	$('#subCategoryContent').show();	          
	$('#contentTitle').html($('#subCategoryList'+subCategoryId).html());	
	$('#contentMessage').load(hostname+"modules/loadCategory.php",{'categoryId': subCategoryId, 'action' : 'description'});
}




/*image pagination*/
/*function chkpage()
{
	var size = $(".imageSlide").size();
	if(size > 1)
	{          
	      $('.pagenav').css('visibility','visible');
	     
	      $('#dispPageNavMax').html(size)
	} 
	if(current >= size){        
		$(".imageNext").css('visibility','hidden');

		$(".dumimageNext").css('visibility','visible');
	}
	else{
		$(".imageNext").css('visibility','visible');
		$(".dumimageNext").css('visibility','hidden');

	}
	if(current <= 1){        
		$(".imagePrev").css('visibility','hidden');
		$(".dumimagePrev").css('visibility','visible');
	}
	else{
		$(".imagePrev").css('visibility','visible');
		$(".dumimagePrev").css('visibility','hidden');

	}
}*/

function chkpage()
{
	var size = $(".imageSlide").size();
	if(size > 1)
	{          
	      $('.pagenav').css('visibility', 'visible')
	      $('#dispPageNavMax').html(size)
	} 
	if(current >= size){        
		$(".imageNext").show();
		
	}
	else{
		$(".imageNext").show();
		
	}
	if(current <= 1){        
		$(".imagePrev").show();
		
	}
	else{
		$(".imagePrev").show();
		
	}
}

function imageslide(param)
{
	var size = $(".imageSlide").size();
	if(param == "next")
	{
	      $(".imageSlide").each(function(i,item)
	      {
		        if(i+1 == current)
		        {
		                  $("."+current).fadeOut('slow',function()
		                  {
		                            className = $(this).attr('class');
		                            className = className.split(" ");
					    if(Number(className[1]) == size)
					    {
						      tt = 1;                   
		                                      $("."+tt).fadeIn('slow');
		                                      current = tt;
		                                      $('#dispPageNavMin').html(current);
		                                      chkpage();
					    }                  
		                            else if(Number(className[1])+1 <= size)
		                            {
		                                      tt = Number(className[1])+1;                   
		                                      $("."+tt).fadeIn('slow');
		                                      current = tt;
		                                      $('#dispPageNavMin').html(current);
		                                      chkpage();
		                            }
		                  });
		        }
	      })
	}
	if(param == "prev")
	{
	      $(".imageSlide").each(function(i,item)
	      {
		        if(i+1 == current)
		        {
		                  $("."+current).fadeOut('slow',function()
		                  {
		                            className = $(this).attr('class');
		                            className = className.split(" ");
					    if(Number(className[1]) <=1)
					    {
						    
						      tt = size;                   
		                                      $("."+tt).fadeIn('slow');
		                                      current = tt;
		                                      $('#dispPageNavMin').html(current);
		                                      chkpage();
					    }                    
		                            else if(Number(className[1])-1 <= size)
		                            {
		                                     tt = Number(className[1])-1;                   
		                                     $("."+tt).fadeIn('slow');
		                                     current = tt;
		                                     $('#dispPageNavMin').html(current);
		                                     chkpage();
		                            }
		                  });
		        }
	      })
	}
             
}
$(document).ready(function()
{
        $(".imagePrev").click(function()
	{
	        imageslide('prev')
        })
        $(".imageNext").click(function()
	{
	        imageslide('next')
        })
        
});
      /*imagepagination*/
function pageno(a)
{
	alert('welcome');
}

