var sExpandedPreloader = "/sfxpictures/sfxGallery/loading2-transparent.gif";
var sThumbnailPreloader = "/SFXPictures/sfxGallery/loading2.gif";
var iCurrSectionId;
var iCurrSubSectionId;
var	iCurrThumbId;
var aMainSections = new Array();
var aChartsGallerySections = new Array();
var aChartsGalleryTitle = new Array();
var aGaugesGallerySections = new Array();
var aGaugesGalleryTitle = new Array();
var aMapsGallerySections = new Array();
var aMapsGalleryTitle = new Array();
var aReqChartsProdName = new Array();
var aReqGaugesProdName = new Array();
var aReqMapsProdName = new Array();
//++++++++++++++++++++++++++++++++++++++++++++++ Define Main Sections
aMainSections[aMainSections.length] = "Charts";
aMainSections[aMainSections.length] = "Gauges";
aMainSections[aMainSections.length] = "Maps";

//++++++++++++++++++++++++++++++++++++++++++++++ Define Sub Sections

//Bar-Gantt-Cube
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Bar-Gantt-Cube";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Side-By-Side Bars", "ThreeD Side-By-Side Bars", "TwoD Stacked Bars", "ThreeD Stacked Bars", "ThreeD Oblique Bars", "TwoD Horizontal Bars", "ThreeD Horizontal Bars", "TwoD Gantt", "ThreeD Gantt", "TwoD Inverted Axis", "ThreeD Inverted Axis", "TwoD Horizontal Zero Axis", "ThreeD Horizontal Zero Axis", "TwoD Negative Data Bars", "TwoD Cluster Cylinder", "ThreeD Cluster Cylinder", "TwoD Floating Cubes", "ThreeD Floating Cubes", "ThreeD Thin Columns", "ThreeD Cones");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Area
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Area";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Area", "ThreeD Area", "TwoD Normal Stacked Area", "ThreeD Normal Stacked Area", "TwoD 100 Percent StackedArea", "ThreeD 100 Percent StackedArea", "TwoD Clustered Area", "ThreeD Clustered Area", "TwoD Curve Area", "ThreeD Curve Area", "TwoD Area Zero Axis", "ThreeD Area Zero Axis", "TwoD Area Drop Lines", "ThreeD Area Drop Lines");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Line-Step-Curve 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Line-Step-Curve";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Multiple Series Line", "ThreeD Multiple Series Line", "ThreeD Strip", "TwoD Step", "ThreeD Step", "TwoD Log Scale", "ThreeD Log Scale", "TwoD Curves", "ThreeD Curves", "TwoD Strip Curve", "ThreeD Strip Curve", "TwoD XY Line-Zero Axis", "ThreeD XY Line-Zero Axis", "TwoD Multiple Line Styles");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Bubble 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Bubble";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Multicolor Bubble", "ThreeD Multicolor Bubble", "TwoD Monocolor Bubble", "ThreeD Monocolor Bubble");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Pie-Doughnut-Pyramid 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Pie-Doughnut-Pyramid";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Plain Pie", "ThreeD Pie", "TwoD Pie with Shadows", "TwoD Exploding Pie", "ThreeD Exploding Pie", "TwoD Pie Separate Slice", "ThreeD Pie Separate Slice", "TwoD Multiple Series Pie", "ThreeD Multiple Series Pie", "TwoD Doughnut", "ThreeD Doughnut", "TwoD Doughnut Pie Separate Slice", "TwoD Exploding Doughnut", "ThreeD Exploding Doughnut", "TwoD Multiple Series Doughnut", "ThreeD Multiple Series Doughnut", "TwoD Pyramid", "ThreeD Pyramid", "TwoD Multiple Series Pyramid", "ThreeD Multiple Series Pyramid");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Combination 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Combination";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Bar-Area Combination", "ThreeD Bar-Area Combination", "TwoD Bar-Line Combination", "ThreeD Bar-Line Combination" /*,"TwoD Line-Range Band Combination", "ThreeD Line-Range Band Combination"*/);
aReqChartsProdName[aReqChartsProdName.length] = ""; 
 
//Scatter
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Scatter";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Scatter", "ThreeD Scatter", "TwoD Linear Regression", "ThreeD Linear Regression", "TwoD Zero Crossing", "ThreeD Zero Crossing");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Financial 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Financial";
aChartsGallerySections[aChartsGallerySections.length] = new Array("Hi-Low-Close", "Candlestick", "TwoD Line-Volume Area", /*"Open-Hi-Low-Close",*/ "Renko", "Kagi", "ThreeLine Break", "Point And Figure");
aReqChartsProdName[aReqChartsProdName.length] = "Chart FX Extensions Pack"; 

//Surface-Contour 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Surface-Contour";
aChartsGallerySections[aChartsGallerySections.length] = new Array("TwoD Surface", "ThreeD Surface", "Contour");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Radar-Polar 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Radar-Polar";
aChartsGallerySections[aChartsGallerySections.length] = new Array("Standard Radar", "Radar-No Lines", "Polar", "Polar-Filled", "Polar-No Shadow");
aReqChartsProdName[aReqChartsProdName.length] = ""; 

//Statistical 
aChartsGalleryTitle[aChartsGalleryTitle.length] = "Statistical";
aChartsGallerySections[aChartsGallerySections.length] = new Array("Histogram", "Box and Whiskers", "Frequency Polygon", "Cumulative Frequency", "Linear Regression", "Scatter with Error Bar", "Line with Error Bar", "Bar with Error Bar", "X-Chart", "R-Chart", "p-Chart");
aReqChartsProdName[aReqChartsProdName.length] = "Chart FX Extensions Pack"; 

//Radial Gauges
aGaugesGalleryTitle[aGaugesGalleryTitle.length] = "Radial Gauges";
aGaugesGallerySections[aGaugesGallerySections.length] = new Array("Circular 1","Circular 2","Circular 3","Circular 4","Circular 5","Circular 6","Circular 7","Circular 8","Circular 9","Circular 10","Semi Circular 1","Semi Circular 2","Semi Circular 3","Semi Circular 4","Radial Square 1","Radial Square 2","Radial Rectangular 1","Radial Rectangular 2","Floating","Multiple Scales with Digital Panel","Multiple Indicators","Combined Indicators","Concentric Scales","Multiple Scales","Internal Scales","Combination Radial Digital","Combination Radial Horizontal","Combination Radial Vertical");
aReqGaugesProdName[aReqGaugesProdName.length] = "Chart FX Gauges"; 

//Horizontal Gauges
aGaugesGalleryTitle[aGaugesGalleryTitle.length] = "Horizontal Gauges";
aGaugesGallerySections[aGaugesGallerySections.length] = new Array("Horizontal Filler 1","Horizontal Filler 2","Horizontal Filler 3","Horizontal Filler 4","Horizontal Filler 5","Horizontal Filler 6","Horizontal Filler 7","Horizontal Filler 8","Horizontal Square","Horizontal Repeater 1","Horizontal Repeater 2","Horizontal Marker 1","Horizontal Marker 2","Horizontal Marker 3","Horizontal Thermometer 1","Horizontal Thermometer 2","Horizontal Thermometer 3","Horizontal Multiple Markers","Horizontal Combination Filler Marker","Horizontal Multiple Fillers");
aReqGaugesProdName[aReqGaugesProdName.length] = "Chart FX Gauges"; 

//Vertical Gauges
aGaugesGalleryTitle[aGaugesGalleryTitle.length] = "Vertical Gauges";
aGaugesGallerySections[aGaugesGallerySections.length] = new Array("VerticalFiller1","Vertical Filler 2","Vertical Filler 3","Vertical Filler 4","Vertical Filler 5","Vertical Filler 6","Vertical Filler 7","Vertical Filler 8","Vertical Repeater 1","Vertical Repeater 2","Vertical Marker 1","Vertical Marker 2","Vertical Marker 3","Thermometer 1","Thermometer 2","Thermometer 3","Multiple Markers","Combination Filler Marker","Multiple Fillers"/*,"Combination Vertical Digital","Combination Vertical Radial"*/);
aReqGaugesProdName[aReqGaugesProdName.length] = "Chart FX Gauges"; 

//Digital Panels
aGaugesGalleryTitle[aGaugesGalleryTitle.length] = "Digital Panels";
aGaugesGallerySections[aGaugesGallerySections.length] = new Array("Rectangular","Seven Segments","Fourteen Segments","Leds","Multiple"/*,"Combination Digital Linear"*/,"Combination Digital Radial");
aReqGaugesProdName[aReqGaugesProdName.length] = "Chart FX Gauges"; 

//United States Maps
aMapsGalleryTitle[aMapsGalleryTitle.length] = "Chart FX Maps";
aMapsGallerySections[aMapsGallerySections.length] = new Array("US: States","World: Continental","Regional: Eastern Europe","Regional: Oceania","Regional: Central America","US: LA ZipCodes","US: FL Counties","Custom: Airplane Sample");
aReqMapsProdName[aReqMapsProdName.length] = "Chart FX Extensions Pack"; 


//World Maps
//aMapsGalleryTitle[aMapsGalleryTitle.length] = "World Maps";
//aMapsGallerySections[aMapsGallerySections.length] = new Array("Rectangular","Seven Segments","Fourteen Segments","Leds","Multiple","Combination Digital Linear","Combination Digital Radial");
//aReqMapsProdName[aReqMapsProdName.length]  = "Chart FX Extensions Pack"; 

//Region Maps
//aMapsGalleryTitle[aMapsGalleryTitle.length] = "Region Maps";
//aMapsGallerySections[aMapsGallerySections.length] = new Array("Rectangular","Seven Segments","Fourteen Segments","Leds","Multiple","Combination Digital Linear"/*,"Combination Digital Radial"*/);
//aReqMapsProdName[aReqMapsProdName.length]  = "Chart FX Extensions Pack"; 


function sizeContentDiv()
{
	var windowHeight = getWindowHeight();
	objDivLayoutNavigation = document.getElementById('divLayoutNavigation');
	var navigationHeight = objDivLayoutNavigation.offsetHeight;
	
	objDivLayoutHeader = document.getElementById('divLayoutHeader');
	var headerHeight = objDivLayoutHeader.offsetHeight;
	
	objDivLayoutFooter = document.getElementById('divLayoutFooter');
	var footerHeight = objDivLayoutFooter.offsetHeight;
	
	var comboHeight = navigationHeight + headerHeight + footerHeight;
	
	objDivLayoutMain = document.getElementById('divLayoutMain');
	if(parseInt(document.getElementById('divContent').offsetHeight)<(windowHeight-comboHeight))
		objDivLayoutMain.style.height = (windowHeight-comboHeight -10) + 'px';
}

function hoverSubNav(obj){
	obj.className = 'hoversubnav';
}

function hoverSubNavOut(obj)
{
	obj.className = 'gallerysubmenu';
}
function checkScroll()
{
	var currentYScroll =  parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ;
	var menuHeight = parseInt(document.getElementById("floater").offsetHeight);
	var contentHeight = parseInt(document.getElementById("tdContainer").offsetHeight);
	var mainNavHeight = document.getElementById("divLayoutNavigation").offsetHeight;
	if(mainNavHeight >= currentYScroll)
		mainNavHeight = mainNavHeight - currentYScroll;
	else
		mainNavHeight = 0;

	if(currentYScroll + menuHeight < contentHeight)
{
        if(currentYScroll <1)
        	document.getElementById("floater").style.top= '78px';
        else
    		document.getElementById("floater").style.top= (currentYScroll + 15 + mainNavHeight) + 'px';
}	
}
function showTdContainerHeight(){
	document.getElementById("txtTdContainer").value = document.getElementById("tdContainer").offsetHeight;
	document.getElementById("txtFloaterHeight").value = document.getElementById("floater").offsetHeight;
}
function LoadSectionFirst(sectionId,subSectionId)
{
	PreLoadThumbFirst(sectionId, subSectionId , 0);
}
function PreLoadThumbFirst(sectionId, subSectionId, thumbId)
{
	var objPreloadContainer = document.getElementById("divPreloadContainerFirst");
	//alert(imgId);
	var imgId = ReformatTitle(eval("a" + aMainSections[sectionId] + "GalleryTitle["+subSectionId+"]") + thumbId) ;
	var imgSrc = ReformatTitle(eval("a" + aMainSections[sectionId] + "GallerySections["+subSectionId+"]["+thumbId+"]"));
	
	imgSrc = "/SfxPictures/sfxgallery/thumbs/" + imgSrc + ".png";
	//alert(imgId + "..." + imgSrc);
	var newImg = "<img id=\"preLoadFirst\" src=\"" + imgSrc + "\" width=\"100\" height=\"100\" class=\"imgThumbnail\" onload=\"imageLoadedFirst('preLoadFirst','"+ imgId +"',"+ sectionId +","+subSectionId+","+thumbId+")\" />";
	if(document.getElementById("preLoadFirst")!=null)
	{
		objPreloadContainer.innerHTML = newImg;
	}
	else{
		objPreloadContainer.innerHTML += newImg;
	}
}
function GoToSection(sectionId,subSectionId)
{
	window.location = "#anchor-" + sectionId + "-" + subSectionId;
	LoadSectionFirst(sectionId, subSectionId);
}
function ShowImage(idImgSource, idImgDestination)
{
	var sourceImg = document.getElementById(idImgSource);
	var targetImg = document.getElementById(idImgDestination);
	targetImg.src = sourceImg.src;
}
function imageLoaded(idImgSource, idImgDestination, sectionId, subsectionId, thumbId)
{
	//alert(sectionId + "," + subsectionId + "," + thumbId);
	//alert("source= " + idImgSource +", destination = " + idImgDestination);
	//alert(document.getElementById(idImgDestination).src + " = " + sThumbnailPreloader);
	var sImgSrc = document.getElementById(idImgDestination).src ;
	if(sImgSrc.indexOf(sThumbnailPreloader)>-1)
		ShowImage(idImgSource, idImgDestination);
	if(thumbId< eval("a" + aMainSections[sectionId] + "GallerySections[" + subsectionId + "].length" )-1)
	{
		setTimeout("LoadThumb("+ sectionId+ ", "+ subsectionId+ ", "+ (thumbId+1) +")",10);
		//alert(thumbId + 1);
	} else {
	//	alert(eval("a" + aMainSections[sectionId] + "GalleryTitle.length" )-1);
			if(subsectionId< eval("a" + aMainSections[sectionId] + "GalleryTitle.length" )-1)
			{
				setTimeout("LoadThumb("+sectionId+", "+ (subsectionId +1) +" , 0)",20);	
			} 
			else{
				if(sectionId< aMainSections.length -1 )
				{
					LoadThumb(sectionId+1, 0 , 0);
				}
			}
	}
}
function imageLoadedFirst(idImgSource, idImgDestination, sectionId, subsectionId, thumbId)
{
	//alert(sectionId + "," + subsectionId + "," + thumbId);
	//alert("source= " + idImgSource +", destination = " + idImgDestination);
		var sImgSrc = document.getElementById(idImgDestination).src ;
	if(sImgSrc.indexOf(sThumbnailPreloader)>-1)
		ShowImage(idImgSource, idImgDestination);
	if(thumbId< eval("a" + aMainSections[sectionId] + "GallerySections[" + subsectionId + "].length" )-1)
	{
		setTimeout("PreLoadThumbFirst("+ sectionId+ ", "+ subsectionId+ ", "+ (thumbId+1) +")",10);
		//alert(thumbId + 1);
	} else {
	//	alert(eval("a" + aMainSections[sectionId] + "GalleryTitle.length" )-1);
			if(subsectionId< eval("a" + aMainSections[sectionId] + "GalleryTitle.length" )-1)
			{
				setTimeout("PreLoadThumbFirst("+sectionId+", "+ (subsectionId +1) +" , 0)",20);	
			} 

	}
}
function LoadThumb(sectionId, subsectionId, thumbId)
{
	preLoadGalleryThumb(eval("a" + aMainSections[sectionId] + "GallerySections["+ subsectionId +"][" + thumbId +"]"), ReformatTitle(eval("a" + aMainSections[sectionId] + "GalleryTitle[" + subsectionId +"]")) + thumbId, sectionId, subsectionId, thumbId);
}



var loadTimer;
function LoadSection(sectionId)
{
// 0 = Charts , 1 = Gauges, 2 = Maps
	if(sectionId < aMainSections.length && sectionId >= 0)
	{
		LoadSubSection(sectionId);
		
	}else
	{
		for(var i=0; i <aMainSections.length; i++)
		{
			LoadSubSection(i);
		}
	}

}

function LoadSubSection(sectionId)
{
	for(var i=0; i<eval("a" + aMainSections[sectionId] + "GalleryTitle.length"); i++)
	{
		document.getElementById("divContainer-" + sectionId + "-" + i).className = 'showObj';
	}
}
 
function ShowExpandedGallery(sectionId, subSectionId, thumbId)
{
	var imgExpanded = document.getElementById("imgExpandedChart");
	imgExpanded.src = sExpandedPreloader;
	openViewer('divDraggableViewer');	
	iCurrSectionId = sectionId;
	iCurrSubSectionId = subSectionId;
	iCurrThumbId = thumbId;
	
	var objPreloadContainer = document.getElementById("divPreloadExpanded");
	//alert(imgId);
	var imgId = ReformatTitle(eval("a" + aMainSections[sectionId] + "GalleryTitle["+subSectionId+"]") + thumbId) ;
	var imgSrc = ReformatTitle(eval("a" + aMainSections[sectionId] + "GallerySections["+subSectionId+"]["+thumbId+"]"));
	
	imgSrc = "/SfxPictures/sfxgallery/full/" + imgSrc + ".png";
	//alert(imgId + "..." + imgSrc);
	var newImg = "<img id=\"preLoadExpanded\" src=\"" + imgSrc + "\" width=\"100\" class=\"imgThumbnail\" height=\"100\" onload=\"ShowImage('preLoadExpanded','imgExpandedChart')\" />";
	if(document.getElementById("preLoadExpanded")!=null)
	{
		objPreloadContainer.innerHTML = newImg;
	}
	else{
		objPreloadContainer.innerHTML += newImg;
	}

}
function PreLoadThumbs()
{
	for(var sectionId=0; sectionId< aMainSections.length; sectionId++)
	{
		for(var subsectionId = 0; subsectionId < eval("a" + aMainSections[sectionId] + "GalleryTitle.length"); subsectionId++)
		{
			for(var thumbId = 0; thumbId < 	eval("a" + aMainSections[sectionId] + "GallerySections["+ subsectionId +"].length"); thumbId++)
			{
				preLoadGalleryThumb(eval("a" + aMainSections[sectionId] + "GallerySections["+ subsectionId +"][" + thumbId +"]"), ReformatTitle(eval("a" + aMainSections[sectionId] + "GalleryTitle[" + subsectionId +"]")) + thumbId);
				//alert(ReformatTitle(eval("a" + aMainSections[sectionId] + "GalleryTitle[" + subsectionId +"]")) + thumbId);
			}
		}
	}
	


}
function preLoadGalleryThumb(imageTitle, imageId, sectionId, subsectionId, thumbId) 
{
	var imgSource = ReformatTitle(imageTitle);
	imgSource = "/SfxPictures/sfxgallery/thumbs/" + imgSource + ".png";
	preLoadGalleryImage(imgSource, imageId, sectionId, subsectionId, thumbId);
	
}
function preLoadGalleryImage(imgSrc, imgId, sectionId, subsectionId, thumbId)
{
	var objPreloadContainer = document.getElementById("divPreloadContainer");
	//alert(imgId);
	var newImg = "<img id=\"preLoad-" + imgId + "\" src=\"" + imgSrc + "\" width=\"100\" class=\"imgThumbnail\" height=\"100\" onload=\"imageLoaded('preLoad-" + imgId + "','"+ imgId +"',"+ sectionId +","+ subsectionId +","+ thumbId+")\" />";
	objPreloadContainer.innerHTML = newImg;
	//alert(sectionId +","+ subsectionId +","+ thumbId);
	//document.getElementById("txtHTML").value +=newImg;
}

function ReformatTitle(imgTitle)
{	
	var imgSrc;
	imgSrc =imgTitle;
	
	while (imgSrc.indexOf(" ") > -1)
 	{
		imgSrc = imgSrc.replace(" ","");
	}
	while (imgSrc.indexOf("-") > -1)
	{
		imgSrc = imgSrc.replace("-","");
	}
	while (imgSrc.indexOf(":") > -1)
	{
		imgSrc = imgSrc.replace(":","");
	}
	return imgSrc;
}
