// set seclink setting's default values
var using_imgbutton = 0;
var using_backtile = "";
var using_mnuspace = 5;
var using_mnuheight = 33;
var using_mnucapital = false;
var using_addlinkend= true;
s_custom_loc = s_whole_path + s_custom_loc;
function splitter() {
	return "<img src='" + s_whole_path +
		"/httpfiles/common/images/spacer.gif' width=" + using_mnuspace + " height=4 border=0>";
}
// 
// support image button also
// format:bldSectionLinks( {{name, link,},opt_string}}
// if imgbutton: nav_{name}.gif,nav_{name}_on.gif,nav_{name}_over.gif used!
function bldSectionLinks() 
{
	// check custom_nolinks
	if ( typeof(custom_nolinks)=="boolean" && custom_nolinks )
		return;

	// check env
	if (typeof(JavaArray)=="undefined" || typeof(JavaSubArray)=="undefined" || 
	    typeof(iCampID)=="undefined" || typeof(s_custom_loc)=="undefined"  ||
		typeof(s_whole_path)=="undefined" )
		return;
	// parsing parameters;
	var i, a, c, add_start=0, opt;
	var home_link="";
	a = bldSectionLinks.arguments;
	c = bldSectionLinks.arguments.length;
	if ( c>0 && c%2==1 ) parseOptString( a[c-1] );
	// overwrite community home link;
	if (c>1 && a[0].toLowerCase()=="home") {
		home_link = a[1];
		add_start = 2;
	}
	var s="", s_preload="";
	// link table
	s  = "<table class='mnuBackground' border=0 cellpadding=0 cellspacing=0 " +
		((using_backtile>"")? "background='" + using_backtile + "_1.jpg'" : "") + " width='100%'><tr><td>";
	s += "<table border=0 cellpadding=0 cellspacing=0><tr>";
	// always put the iSec as Home link
	var lnk;
	if ( home_link=="" ) {
		// always take iSec as community section, the major part,
		// all other sub_section as add-on links;
		for (i=0; i<JavaArray.length; i++)
			if (JavaArray[i][1]==5) { home_link=JavaArray[i][2]; break; }
	} 
	s += "<td>" + outOneLink("Home", home_link, (iSubSec==-1) ) + "</td>";
	if ( using_imgbutton )
		s_preload = "'" + s_custom_loc + "nav_home_over.gif'" ;
	
	// check if addon link exist?
	if (c>add_start && !using_addlinkend) {
		// added links show here
		s += bldAddLinks(a, add_start );
	}

	if ( JavaSubArray.length>0 ) 
	{
		// interprete community links
		for (i=0; i<JavaSubArray.length; i++) 
		{
			if ( using_imgbutton>=1 && using_imgbutton<=3 )
			switch ( parseInt(JavaSubArray[i][1]) ) {
				case 13: sgif='gallery'; break;
				case 14: sgif='notes'; break;
				case 16: sgif='boards'; break;
				case 23: sgif='newsletter'; break;
				case 24: sgif='video'; break;
				case 25: sgif='reply'; break;
				default: sgif='unkown'; break;
			}
			lnk = JavaSubArray[i][2];
			if ( using_imgbutton>=1 && using_imgbutton<=3 ) {
				s += "<td>" + outOneLink( sgif, lnk, (JavaSubArray[i][1]==iSubSec) ) + "</td>";
				s_preload += ",'" + s_custom_loc + "nav_" + sgif + "_over.gif'";
			} else
				s += "<td>" + outOneLink( JavaSubArray[i][0], lnk, (JavaSubArray[i][1]==iSubSec) ) + "</td>";
		} // end of for
		//
		if (c>add_start && using_addlinkend)
			s += bldAddLinks(a, add_start);
		s += "</tr></table></td></tr></table>";
	}
	if ( using_imgbutton>=1 && using_imgbutton<=3 )
		// preload images;
		eval( "MM_preloadImages(" + s_preload + ")" );
	document.write(s);
}

// parsing option string:
// opt_string: imgbutton/txtbutton, addlinkbegin;
function parseOptString( opt )
{
	var opts = opt.toLowerCase();
	if ( opts.indexOf("txtbutton")>=0 || opts.indexOf("button0")>=0 )
		using_imgbutton = 0;
	if ( opts.indexOf("imgbutton")>=0 || opts.indexOf("button1")>=0 )
		using_imgbutton = 1;
	if ( opts.indexOf("im2button")>=0 || opts.indexOf("button2")>=0 )
		using_imgbutton = 2;
	if ( opts.indexOf("im3button")>=0 || opts.indexOf("button3")>=0 )
		using_imgbutton = 3;		
	var i = opts.indexOf("tile");
	if ( i>=0 ) {
		// tile<n>_1, tile<n>_2, tile<n>_3: three pix for munButton!
		i = getNumber( opts.substring(i+4, i+5),0 );
		if (i>0) using_backtile = "tile" + i; else using_backtile = "tile";
		using_backtile = s_custom_loc + using_backtile;
	}
	if ( opts.indexOf("mnubutton")>=0 || opts.indexOf("button4")>=0 ) {
		using_imgbutton = 4;
		i = opts.indexOf("space");
		if ( i>=0 ) using_mnuspace = getNumber( opts.substring(i+5, i+6), 5 );
		i = opts.indexOf("height");
		if ( i>0 ) using_mnuheight = getNumber( opts.substring(i+6, i+8), 33 );
		if ( opts.indexOf("capital")>=0 ) using_mnucapital=true;
	}
	if ( opts.indexOf("addlinkbegin")>=0 )
		using_addlinkend = false;
	return;
}
function bldAddLinks( ar, s_index )
{
	var s = "";
	var i = s_index;
	while ( i+1<ar.length ) {
		// interpreting other section's links here;
		var is_current=false;
		switch ( iSubSec ) {
			case 1: // Contact Us
				if (ar[i].toLowerCase()=="contact us" || ar[i].toLowerCase()=="contactus") is_current=true;
				break;
			case 2: // News
				if (ar[i].toLowerCase()=="news") is_current=true;
				break;
		}
		s += "<td>" + 
			outTypedOneLink( using_imgbutton, ar[i], ar[i+1], is_current ) +
			"</td>";
		i += 2;
	}
	return s;
}
function outOneLink( name, link, is_current )
{
	return outTypedOneLink( using_imgbutton, name, link, is_current);
}
//
// output a link by current environment
function outTypedOneLink( button_type, name, link, is_current )
{
	var s="", prot="";
	// page elements need, links on page don't!
	if ( s_whole_path>"" )
		prot = s_whole_path.replace("https://", "http://");
	// all the links in format of /xxx; or http(s)://...
	if ( link.indexOf("/")==0 ) {
	    link += ( link.indexOf("?")==-1 )? "?form_camp_id=" + iCampID : "";	
		link = prot + link;
	}	
	switch ( button_type ) {
		case 0: // simple text button
			s = splitter() + "<a href='" + link + "' class='" +
			  ((!is_current)? "secLink": "secLinkSelected") + "'>" + 
			  name + "</a>" +	splitter();
			break;
		case 1: // button with one image
			s = "<a href=\"" + link + "\"><img border=0 src=\"" +
				s_custom_loc + "nav_" + name + ".gif\"></a>";
			break;
		case 2: // button with 2 images: normal & selected;
		    if ( is_current )		    
				s = "<a href=\"" + link + "\"><img border=0 src=\"" +
					s_custom_loc + "nav_" + name + "_on.gif\"></a>";
		    else
				s = "<a href=\"" + link + "\"><img border=0 src=\"" +
					s_custom_loc + "nav_" + name + ".gif\"></a>";
			break;
		case 3: // animated image button: normal, selected & hover
			if ( is_current ) 
				s = "<a href=\"" + link + "\"><img border=0 src=\"" +
					s_custom_loc + "nav_" + name + "_on.gif\"></a>";
			else
				s = "<a href=\"" + link + "\" onMouseOut=\"MM_swapImgRestore()\" " +
					"onMouseOver=\"MM_swapImage('" + name + "', '', '" + 
					s_custom_loc + "nav_" + name + "_over.gif',1)\">" + 
					"<img border=0 src=\"" +
					s_custom_loc + "nav_" + name + ".gif\" id=\"" + name + "\"></a>";
			break;
		case 4: // mnubutton type, one of text buttons
			s = "<td>";
			s += "<table border=0 cellspacing=0 cellpadding=0><tr><td>";
			s += splitter() + "</td><td><table border=0 height=" + using_mnuheight + " " + 
				"cellspacing=0 cellpadding=0><tr>";
			name = (using_mnucapital)?  name.toUpperCase() : name;
			s += "<td " + 
				((using_backtile=="")? "" : 
				  "background='" + using_backtile + ((is_current)?"_2.jpg":"_1.jpg") + "' " ) +
				"class=" +
				((is_current)? "'mnuButtonOnBorder'" : "'mnuButtonOffBorder'" ) + " " +
				"align=center valign=middle>" +
				"<table border=0 cellspacing=" + Math.floor(using_mnuheight*0.2) + 
				" cellpadding=0 height=" + using_mnuheight + "><tr>" +
				"<td " + 
				((using_backtile=="")? "" : 
				  "background='" + using_backtile + ((is_current)?"_3.jpg" : "_2.jpg") + "' " ) +   
				"class=" +
				((is_current)? "'mnuButtonOn'" : "'mnuButtonOff'" ) + ">" +
				splitter() +
				"<a href='" + link + "' class=" +
				((is_current)? "'mnuButtonOnText'" : "'mnuButtonOffText'") + ">" +
				name +
				"</a>" + splitter() + 
				"</td></tr></table></td></tr></table></td></tr></table>" +
				"</td>";			
			break;
		default: break;
	}
	return s;
}
//
// login/logout, contact us, and bunk1.com
function bldSectionConstLinks() 
{
	// check custom_nolinks
	if ( typeof(custom_nolinks)=="boolean" && custom_nolinks )
		return;

	var s="";
	// login/logout;
	if (getCookie("user")!=null) {
		// login already, show logout link;
		s = "\"Logout\",";
		lnk = "/portal/index.aspx?action=l&form_camp_id=" + iCampID + "&form_origin=/template/gallery.aspx";
	} else {
		lnk = "/template/login.asp?form_camp_id=" + iCampID;
		s = "\"Login\"," ;
	}
	s += "\"" + s_whole_path.replace("https://", "http://") + lnk + "\",";
	// contact us
	lnk = "/template/contact_form.asp?form_camp_id=" + iCampID;
	lnk = "javascript:popUp('" + s_whole_path.replace("https://", "http://") + lnk + "','left=10,top=10,width=700,height=520');"; 
	s += "\"Help\",\"" + lnk + "\"";
	eval( "bldSectionAnyLinks(" + s + ")" );
}
// 
function bldSectionAnyLinks()
{
	// parsing parameters;
	// AnyLinks need full path link;
	var a,c,i;
	a = bldSectionAnyLinks.arguments;
	c = bldSectionAnyLinks.arguments.length;
	if ( c%2 != 0 ) return;
	//rick@05/25/05: added class='mnuBackground'
	var s="<table border=0 cellpadding=0 cellspacing=0 class='mnuBackground'><tr>";
	for (i=0; i<c; i++,i++) {
		s += "<td>" + splitter() + 
			"<a href=\"" + a[i+1]  + "\" class=\"constLink\">" + a[i] + "</a>" + "</td>";
	}
	s += "<td>" + splitter() + "</td>";
	s += "</tr></table>";
	document.write( s );
}
// 
function getImageName( img ) {
	var s="";
	if ( img.indexOf("/")==0 )
		s = s_whole_path + img;
	else {
		if ( img.indexOf("http")==-1 )
			s = s_custom_loc + img;
	}
	
	var s1 = "https://www.bunk1.comhttps://www.bunk1.com/"
	var s1a = "https://www.bunk1.com/"
	var s2 = "http://www.bunk1.comhttp://www.bunk1.com/"
	var s2a = "http://www.bunk1.com/"	
	s = s.replace(s1,s1a)
	s = s.replace(s2,s2a)
	
	if (s=="")
		s = img;	
	return s;
}
// output image
function outImage( img ) {
	document.write( "<img border=0 src=\"" + getImageName(img) + "\">");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n]) && d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function popUp()
{
	var a, url="", opts="";
	a = popUp.arguments;
	if ( a.length>=1 ) { 
		url = a[0];
		if (a.length==2) opts = a[1];
	}
	if ( opts.indexOf("width=")==-1 && opts.indexOf("height=")==-1 ) 
		opts = "width=500,height=520,status=no,scrollbars=no,menubar=no,resizable=yes";
	else
		opts += ",status=no,scrollbars=yes,menubar=no,resizable=yes";
	window.open(url, "", opts);
}
function getNumber( str, default_val ) {
  var n = parseInt(str);
  if (n==NaN)
    return default_val;
  else
    return n;
}
