	var newClick = null;
init_menu = function(g) {
	try
	{
	
    var colorofselected = null;
    var currNav = null, currSubnav = null;
	//alert(g.id);
	  var pgControlId = "" 
		pgControlId=  g.id.replace("gallery-","");
    document.getElementById('pgControl').value = pgControlId;

 // alert(pgControlId);
    $( document.getElementById('nav'+ pgControlId)).each(function() {
         var nav = this;
		 var imagesName =  "div" + pgControlId;
		 var imgFull = document.getElementById('pgcontrolid'+pgControlId).value;
		 var imgArray =  new Array();
		 imgArray= imgFull.split("{");
		
		 var imgArray2 =  new Array();
		
			 imgArray2 = imgArray[2].split("&");
		 imgArray2[imgArray2.length-1]  =  imgArray2[imgArray2.length-1].replace("} };","") 
  
         currSubnav = document.getElementById('navcou1' +pgControlId);
         var imgs = imgArray2[0];

		if(document.getElementById('tempwidth'+pgControlId).value <= "300")
		{
			if(parseInt(imgs.split(",")[2].length,0) > 10)
					document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2].substring(0,9) + "..";
			else
				document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
		}
		else
					document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];

                  //currSubnav.className
				 colorofselected =   currSubnav.className;
			     $(currSubnav).addClass('pager_active');
                 $(currSubnav).removeClass(colorofselected);
         
    $(document.getElementById('next'+pgControlId)).click(function() {
		var imgFull = document.getElementById('pgcontrolid'+pgControlId).value;
						var imgArray =  new Array();
						imgArray= imgFull.split("{");
		  				 var imgArray2 =  new Array();
						 imgArray2 = imgArray[2].split("&");
						
		 imgArray2[imgArray2.length-1]  =  imgArray2[imgArray2.length-1].replace("} };","") 
		 document.getElementById('pgControl').value = pgControlId;
		 var count1 = parseInt(currSubnav.title,0) +1;
		 for ( i=1;  i<= imgArray2.length;i=i+1)
			{
			      if(document.getElementById("navcou" + i + pgControlId))
					{
					if(document.getElementById("navcou" + i + pgControlId).className == "pager_active" )
                            count1 = i + 1;
					}
			}
			
            var count =  "navcou" +  count1 + pgControlId;
			var imgs = imgArray2[count1-1];
			
             if(imgs != null)
             {
               if(document.getElementById('tempwidth'+pgControlId).value <= "300")
				{
				  // alert(imgs.split(",")[2].length);
					if(parseInt(imgs.split(",")[2].length,0) > 10)
							document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2].substring(0,9) + "..";
					else
							document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
				}
				else
					document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
                if(imgs.length > 0)
                    {
                     if(document.getElementById(count) == document.getElementById('1'+pgControlId))
                              g.init_gallery(imgs , 'First');
                            else
                              g.init_gallery(imgs , 'NotFirst');
                    }

                if(currSubnav)
                 {
					var i =1;
							for ( i=1;  i<= imgArray2.length;i=i+1)
							{
								if(document.getElementById("navcou" + i + pgControlId))
                                $(document.getElementById("navcou" + i + pgControlId)).addClass(colorofselected);
								 $(document.getElementById("navcou" + i + pgControlId)).removeClass('pager_active');
							}
                 }

                this.onfocus = function() {
                this.hideFocus = true;
                }
			
                currSubnav  = document.getElementById(count);
                $(currSubnav).addClass('pager_active') ;
				$(currSubnav).removeClass(colorofselected) ;
            }
          
            return false;
                
            });
            
            
      $(document.getElementById('back'+pgControlId)).click(function() {
		
		  var imgFull = document.getElementById('pgcontrolid'+pgControlId).value;
						var imgArray =  new Array();
						imgArray= imgFull.split("{");
		  				 var imgArray2 =  new Array();
						 imgArray2 = imgArray[2].split("&");
						
		 imgArray2[imgArray2.length-1]  =  imgArray2[imgArray2.length-1].replace("} };","") 
		 document.getElementById('pgControl').value = pgControlId;
		 var count1 = parseInt(currSubnav.title,0) -1;
	
		 for ( i=1;  i<= imgArray2.length;i=i+1)
			{
			// alert(document.getElementById("navcou" + i + pgControlId).style.color);
			 if(document.getElementById("navcou" + i + pgControlId))
					{
					if(document.getElementById("navcou" + i + pgControlId).className == "pager_active" )
						{
                            count1 = i -1;
						}
					}
			}
		
		   document.getElementById('pgControl').value = pgControlId;
            var count = "navcou" +  count1 + pgControlId;; 
            var imgs = imgArray2[count1-1];
       if(imgs != null)
       {       
            if(imgs.length > 0)
				{
					 if(document.getElementById('tempwidth'+pgControlId).value <= "300")
						{
							if(parseInt(imgs.split(",")[2].length,0) > 10)
									document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2].substring(0,9) + "..";
							else
								document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
						}
						else
							document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
					if( document.getElementById(count) == document.getElementById('1'+pgControlId))
 						  g.init_gallery(imgs , 'First');
                    else
                          g.init_gallery(imgs , 'NotFirst');
                 }


            if(currSubnav) {
						var i =1;
							for ( i=1;  i<= imgArray2.length;i=i+1)
							{
								if(document.getElementById("navcou" + i + pgControlId))
                                $(document.getElementById("navcou" + i + pgControlId)).addClass(colorofselected);
								$(document.getElementById("navcou" + i + pgControlId)).removeClass('pager_active');
							}
            }

            this.onfocus = function() {
            this.hideFocus = true;
            }
            currSubnav  = document.getElementById(count);
            $(currSubnav).addClass('pager_active') ;
			$(currSubnav).removeClass(colorofselected);

         }
            return false;
                
            });
        
        $(nav).click(function() {
			var flag = false;
            $(nav).find('a').click(function() {
                if(this != currSubnav) {
                    try {
						var pgcontrolId1 = this.id.replace("navcou","");
						//alert(this.id);
						pgcontrolId1 = pgcontrolId1.replace(this.title,"");
						if(pgcontrolId1)
						{
						flag = true;
						var imgFull = document.getElementById('pgcontrolid'+pgcontrolId1).value;
						var imgArray =  new Array();
						imgArray= imgFull.split("{");
		  				 var imgArray2 =  new Array();
						 imgArray2 = imgArray[2].split("&");
						
						 imgArray2[imgArray2.length-1]  =  imgArray2[imgArray2.length-1].replace("} };","") 
						
                        var imgs = imgArray2[this.title-1];
						 document.getElementById('pgControl').value = pgcontrolId1;
						//alert(imgs);
                        if(document.getElementById('tempwidth'+pgcontrolId1).value <= "300")
						{
							if(parseInt(imgs.split(",")[2].length,0) > 10)
									document.getElementById('imageTitle'+pgcontrolId1).value = imgs.split(",")[2].substring(0,9) + "..";
							else
								document.getElementById('imageTitle'+pgcontrolId1).value = imgs.split(",")[2];
						}
						else
							document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
                        if(imgs.length > 0) {
                         if(this == document.getElementById('navcou1' +pgcontrolId1))
                            {
                              g.init_gallery(imgs , 'First');
                            }
                            else
                              g.init_gallery(imgs , 'NotFirst');
                        }

                        if(currSubnav) {
							//alert(imgArray.length);
							var i =1;
							for ( i=1;  i<= imgArray2.length;i=i+1)
							{
								if(document.getElementById("navcou" + i + pgcontrolId1))
                                $(document.getElementById("navcou" + i + pgcontrolId1)).addClass(colorofselected);
								$(document.getElementById("navcou" + i + pgcontrolId1)).removeClass('pager_active');
							}
                           $(currSubnav).addClass(this.className);
                        }
                      //  this.style.color= "white" ;
							 $(this).addClass('pager_active') ;
							 $(this).removeClass(colorofselected) ;
                        // get rid of annoying dotted border on focus
                        // for hyperlinks
                        this.onfocus = function() {
                            this.hideFocus = true;
                        }

                        currSubnav = this;
						newClick = null; 
                        return false;
						}
                    }
                    catch(e) {
                      // alert(e.message);
                        //alert('SYSTEM ERROR: The selected category (' + nav.title + ' | ' + this.title + ') contains to images!');
                    }
                }
            });

          
            if (flag == false)
            {
				//$(nav.subnav).click(function() {
					
					if(newClick) 
					{
						if(newClick != currSubnav)
						{
						var pgcontrolId1 = newClick.id.replace("navcou","");
						pgcontrolId1 = pgcontrolId1.replace(newClick.title,"");
						flag = true;
						if(pgcontrolId1)
						{
							var imgFull = document.getElementById('pgcontrolid'+pgcontrolId1).value;
							var imgArray =  new Array();
							imgArray= imgFull.split("{");
							 var imgArray2 =  new Array();
							 imgArray2 = imgArray[2].split("&");
							
							 imgArray2[imgArray2.length-1]  =  imgArray2[imgArray2.length-1].replace("} };","") 
							
							var imgs = imgArray2[newClick.title-1];
							 document.getElementById('pgControl').value = pgcontrolId1;
							//alert(imgs);
							if(document.getElementById('tempwidth'+pgcontrolId1).value <= "300")
								{
									if(parseInt(imgs.split(",")[2].length,0) > 10)
											document.getElementById('imageTitle'+pgcontrolId1).value = imgs.split(",")[2].substring(0,9) + "..";
									else
										document.getElementById('imageTitle'+pgcontrolId1).value = imgs.split(",")[2];
								}
								else
										document.getElementById('imageTitle'+pgControlId).value = imgs.split(",")[2];
								if(imgs.length > 0)
							   {
									 if(newClick == document.getElementById('navcou1' +pgcontrolId1))
										{
										  g.init_gallery(imgs , 'First');
										}
										else
										  g.init_gallery(imgs , 'NotFirst');
								}

								if(currSubnav)
								{
									$(currSubnav).addClass(colorofselected) ;
									$(currSubnav).removeClass('pager_active') ;
								}
							// newClick.style.color= "white" ;
                           $(newClick).addClass('pager_active');
						   $(newClick).removeClass(colorofselected) ;
							// get rid of annoying dotted border on focus
							// for hyperlinks
						
							currSubnav = newClick;
							newClick = null; 
							return false;
						}
						}
					}
				//});
				}

           
         //added by me
           currNav = nav;
        
            
            // end added
            return false;
        });
    });

		
	}
	catch (ex)
	{
		//alert(ex);
	}
}
 function newuser(obj)
 {
	 newClick = obj;
	 if(obj)
	 document.getElementById('pgControl').value =  obj.id.substring(6,newClick.id.length-1)
		// alert( document.getElementById('pgControl').value);
	 
 }
