
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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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 MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) {
		  	errors+='- '+nm+' must contain an e-mail address.\n'
			document.getElementById(args[i]).style.backgroundColor = '#F6E4E4'; 
			};
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') { 
	  			errors += '- '+nm+' is required.\n'; 
				document.getElementById(args[i]).style.backgroundColor = '#F6E4E4'; 
			}}
    } //if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function FGTextChange(obj) 
{	
	var text = document.getElementById(obj);
	
	if (obj.indexOf("email")!=-1)
	{
		if ((val=text.value)!="") {
			p=val.indexOf('@');
			d=val.split("@");
			if (p<1 || p==(val.length-1)) {
				text.style.backgroundColor = '#F6E4E4';
			}
			else {
				co=d[1].indexOf('.');
				if (co<1 || co==(val.length-1)) {
				text.style.backgroundColor = '#F6E4E4';
				}
				else {
					text.style.backgroundColor = '#DFF6F9'; 
				}
			}
		}
		else {
			text.style.backgroundColor = '#F6E4E4';
		}
	}
	else {	
		if ( text.value.length <= 1 ) {
			text.style.backgroundColor = '#F6E4E4';
		}
		else {
			text.style.backgroundColor = '#DFF6F9'; 
		}
	}
}

/* Open Gallery Framework */

function openGallery() {

	var imageArg = openGallery.arguments;
	
	if ( imageArg[1].indexOf("set") != -1 ) {
		
		var data = imageArg[1].split("set");
		
		//document.getElementById("fuck").innerHTML = document.getElementById(imageArg[1]).childNodes.length;
		
		for (i=1;i<=3;i++)
		{
			
			if ( data[0]+"set"+i == imageArg[1] )
			{
				
				sub_menu = document.getElementById(imageArg[1]);
				sub_menu.style.display = "block";
											
				var p = sub_menu.childNodes.length;
				
				//for (u=0;u<=p;u++) 
				//{
					//document.getElementById("fuck").innerHTML += sub_menu.childNodes[u].id;
					
					//if ( sub_menu.childNodes[u].id != null ) {
				//document.getElementById("fuck").innerHTML = sub_menu.childNodes[1].id;
					//}
				//}
				
				
				//for (u=0;u<=p;u++) 
				//{
					if ( sub_menu.childNodes[1].id == "lead" ) 
					{
						var d = sub_menu.childNodes[1].getAttribute("name");
						
						imageId = d.split("_image_");
						var itemsz = sub_menu.getElementsByTagName("li");
						var imageL = d+"L";
						
						//document.getElementById("fuck").innerHTML = items.length;
		
						for (k=1;k<=itemsz.length;k++)
						{
							var galleryMenu = document.getElementById(imageId[0]+"_image_"+k+"L");
							var sideMenu = document.getElementById(imageId[0]+"_image_"+k);
									
							if ( imageL == imageId[0]+"_image_"+k+"L" )
							{
								galleryMenu.style.display = "block";
								sideMenu.style.backgroundImage = "url('images/gallery/on_glow.png')";
								sideMenu.style.backgroundPosition = "top left";
								sideMenu.style.backgroundRepeat = "no-repeat";
								sideMenu.style.margin = "-5px";
								sideMenu.style.padding = "5px";
							}
							else {
								if ( galleryMenu != null || sideMenu != null) {
									galleryMenu.style.display = "none";
									sideMenu.style.background = "none";
									sideMenu.style.margin = "0";
									sideMenu.style.padding = "0";
								}
							}
						}
					//}
				} 
				
				
			}
			else {
				if ( document.getElementById(data[0]+"set"+i) != null ) {
					document.getElementById(data[0]+"set"+i).style.display = "none";
				}
			}
		}
	}
	else {
	
		ViewGallery = ( imageArg[1].indexOf("gallery") != -1 ) ? "li" : "a" ;
		var items = document.getElementById(imageArg[1]).getElementsByTagName(ViewGallery);
		
		imageId = ( imageArg[1].indexOf("gallery") != -1 ) ? imageArg[0].split("image_") : imageArg[0].split("_") ;
		var imageL = imageArg[0]+"L";
		var galleryL = imageArg[0]+"L_gallery_display";
	
		/*
		var galleryItem = String(imageId[1] / 15);
		galleryItem = galleryItem.split(".");
		galleryView = ( galleryItem[1] != null ) ? parseInt(galleryItem[0]) + 1 : galleryItem[0] ; 
		
		x = ( galleryView == 1 ) ? parseInt(items.length) - 15 : (parseInt(items.length) * galleryView) - 15;
		l = ( galleryView == 1 ) ? parseInt(items.length) : parseInt(items.length) * galleryView;
		
		*/
		
		//.style.background = "url('images/gallery/on_glow.png')";
		//document.getElementById(imageArg[0]).style.backgroundImage = "url('images/gallery/on_glow.png')";
		//document.getElementById(imageArg[0]).style.backgroundPosition = "top";
		//document.getElementById(imageArg[0]).style.padding = "10px";
		
		if ( imageArg[1].indexOf("gallery") != -1 ) {
		
			//document.getElementById(imageArg[0]).style.backgroundImage = "url('images/gallery/on_glow.png')";
			//document.getElementById(imageArg[0]).style.backgroundPosition = "top";
			//document.getElementById(imageArg[0]).style.margin = "-5px";
			//document.getElementById(imageArg[0]).style.padding = "5px";
			
			var galleryItem = String(imageId[1] / 5);
			galleryItem = galleryItem.split(".");
			galleryView = ( galleryItem[1] != null ) ? parseInt(galleryItem[0]) + 1 : galleryItem[0] ; 
			
			x = ( galleryView == 1 ) ? parseInt(items.length) - 5 : (parseInt(items.length) * galleryView) - 5;
			l = ( galleryView == 1 ) ? parseInt(items.length) : parseInt(items.length) * galleryView;
			
			for (i=0;i<=10;i++)
			{
				var sideMenu = document.getElementById(imageId[0]+"image_"+i);
				
				
				if ( imageArg[0] == imageId[0]+"image_"+i)
				{
					//document.getElementById("fuck").innerHTML += imageArg[1].indexOf("artistic");						
					if ( imageArg[1].indexOf("artistic") != -1 ) {
						sideMenu.style.backgroundImage = "url('images/gallery/on_glow_artistic.png')";
					}
					else {
						sideMenu.style.backgroundImage = "url('images/gallery/on_glow.png')";
					}
					sideMenu.style.backgroundPosition = "top left";
					sideMenu.style.backgroundRepeat = "no-repeat";
					
					if ( i == 1 ) {
						//sideMenu.style.position = "absolute";
						//sideMenu.style.paddingBottom = "61px";
					}
			
				}
				else {
					if ( sideMenu != null ) {
						sideMenu.style.background = "none";
					}
				}
			}
		}
		
		if ( imageArg[1] == "sub-menu" ) {
			
			document.getElementById("menu_0L").style.display = "none";
			
			for (i=1;i<=5;i++)
			{
				var sideMenu = document.getElementById(imageId[0]+"_"+i);
				
				if ( imageArg[0] == imageId[0]+"_"+i)
				{
					sideMenu.style.backgroundPosition = "0 -34px";
				}
				else {
					if ( sideMenu != null ) {
						sideMenu.style.backgroundPosition = "0 0";
					}
				}
			}
		}
		
		
		
		if ( imageArg[1].indexOf("L") != -1 ) {
			
			for (i=1;i<=20;i++)
			{
				var sideMenu = document.getElementById(imageId[0]+"_"+i);
				//document.getElementById(imageArg[0]).parentNode.parentNode.style.
				
				
				
				if ( imageArg[0] == imageId[0]+"_"+i)
				{
					sideMenu.style.color = "#FFFFFF";
					//sideMenu.parentNode.parentNode.style.display = "block";
//					sideMenu.parentNode.parentNode.style.color = "#FFFFFF";
					//document.getElementById("fuck").innerHTML += ;
				}
				else {
					if ( sideMenu != null ) {
						sideMenu.style.color = "#518db8";
						if ( sideMenu.parentNode.parentNode.getElementsByTagName("ul").length == 0 ) {
							//sideMenu.parentNode.parentNode.style.display = "inherit";
						}
						
						
					}
				}
			}
		}
		
		for (i=1;i<=items.length;i++)
		{
			galCom = ( imageArg[1].indexOf("gallery") != -1 ) ? imageId[0]+"image_"+i+"L" : imageId[0]+"_"+i+"L" ;
			var galleryMenu = document.getElementById(galCom);
			var actualGal = document.getElementById(imageId[0]+"_"+i+"L_gallery_display");
			
			//document.getElementById("fuck").innerHTML += imageId[0];
					
			if ( imageL == galCom || galleryL == imageId[0]+"_"+i+"L_gallery_display" )
			{
				galleryMenu.style.display = "block";
				if ( actualGal != null ) {
					actualGal.style.display = "block";
				}
			}
			else {
				if ( galleryMenu != null || actualGal != null ) {
					galleryMenu.style.display = "none";
					if ( actualGal != null ) {
					actualGal.style.display = "none";
					}
				}
			}
		}
	}
	
}

function startGallery () {
	var args = startGallery.arguments;
	
	var imageID = args[0];
	var galleryID = args[1];
	
	var imageLi = document.getElementById(galleryID).getElementsByTagName("li");
	var aHrefLi = document.getElementById(galleryID+"Menu").getElementsByTagName("li");
	
	//document.getElementById("wrs").innerHTML = aHrefLi[1].attributes[0].value; // linkLi.length;
//	document.getElementById("wrs").innerHTML = aHrefLi[0].childNodes[0].id;
		
	for (i=0;i<=imageLi.length;i++) {
		var imageName = imageID + "L";
		var aHref = galleryID + "_image_";

		if ( imageName == imageLi[i].id ) {
			document.getElementById(imageLi[i].id).style.display = "block";
			document.getElementById(aHrefLi[i].childNodes[0].id).className = "sticky"
		}
		else {
			if ( imageLi[i].id != null ) {
				document.getElementById(imageLi[i].id).style.display = "none";
				document.getElementById(aHrefLi[i].childNodes[0].id).className = ""
			}
		}
	}
}

function switchMenu () {
	var args = switchMenu.arguments;
	
	var pageID = args[0];
	var menuID = args[1];
	
	var linkLi = document.getElementById(menuID).getElementsByTagName("li");
	
	var imageID = menuID.split("Menu");
	
	/* Press to move forward or back */
	
	var show10 = 10;
	var startLI = ( pageID == 1 ) ? 0 : ( pageID - 1 ) * 10;
	var endLI = startLI + 10;
	//document.getElementById("wrs").innerHTML = endLI;
	//document.getElementById("wrs").innerHTML = imageID[0] + "_image_" + ( startLI + 1 );
	
	for (i=0;i<=linkLi.length;i++) {
		//document.getElementById("wrs").innerHTML = startLI; // linkLi.length;
		if ( i >= startLI && i < endLI  ) { 
			linkLi[i].style.display = "block";
			document.getElementById(imageID[0] + "_image_" + ( startLI + 1 )).className = "sticky";
			document.getElementById(imageID[0] + "_image_" + ( startLI + 1 ) + "L").style.display = "block";
		}
		else {
			if ( linkLi[i].style.display != null ) {
				linkLi[i].style.display = "none";
				//document.getElementById(imageID[0] + "_image_" + i + "L").style.display = "none";
				document.getElementById(imageID[0] + "_image_" + (i + 1) + "L").style.display = "none";
			}
		}
	}
}