// ezzato Javascript funcions
// version: 1.0
// feb 2007

// ---------------------------------------------------------------------------------------
//  start values / actions
// ---------------------------------------------------------------------------------------

t_nxt=0;
ar_language = new Array();
ar_language[0] = "pt";

pageCheck();


ar_gallery_0 = new Array();
ar_gallery_0[0] = ["1.jpg","Granja avoseira:","- 01 galpão crescimento.<br>- 03 galpões de produção.<br>- Entrada Principal : câmara fria , guarita , silos , fumigador , área de banho , Controle de entrada e saída através de estradas limpas e sujas. "];
ar_gallery_0[1] = ["2.jpg","Incubatório Matrizeiro:","- 03 Incubadoras SS4-150 (capacidade de 21600 ovos).<br>- 03 Incubadoras SS6-150 (para 32400 ovos).<br>- 01 Nascedouro SL216-150 .<br>- 01 Nascedouro SL144-150."];
ar_gallery_0[2] = ["3.jpg","Granja Matrizeira:","- 236 Alqueires de área.<br>- 08 Galpões de Crescimento.<br>- 22 Galpões de Produção "];
ar_gallery_0[3] = ["4.jpg","Incubatório Comercial:","- Paredes internas e externas e telhado em iso-painel.<br>- Todas as salas tem controle independente de temperatura.<br>- 18 Incubadoras Buckeye Modelo SS-648.<br>- 18 Incubadoras Buckeye Modelo SS-432.<br>- 15 Nascedouras Buckeye Modelo SL 216"];
ar_gallery_0[4] = ["5.jpg","Incubatório Comercial:","- Paredes internas e externas e telhado em iso-painel.<br>- Todas as salas tem controle independente de temperatura.<br>- 18 Incubadoras Buckeye Modelo SS-648.<br>- 18 Incubadoras Buckeye Modelo SS-432.<br>- 15 Nascedouras Buckeye Modelo SL 216"];


// ---------------------------------------------------------------------------------------
//  default funcions
// ---------------------------------------------------------------------------------------

function popup(fileName,windowName,windowScrolling,windowWidth,windowHeight) {
	//
	window.open (fileName,windowName,"toolbar=no,left=50,location=no,directories=no,status=no,menubar=no,scrollbars="+windowScrolling+",resizable=no,copyhistory=no,width="+windowWidth+",height="+windowHeight+"");
	//
}

function trace(param) {
	alert(param);
}


function createTittle(tittle_text,tittle_color,bg_color, tittle_width, tittle_height) {


	var givenName = "flashTit"+t_nxt;
	document.writeln('<script>detectFlash( "../flash/tittle.swf",  "'+tittle_width+'", "'+tittle_height+'", "'+bg_color+'", "high", "opaque", "'+givenName+'", "objectName='+givenName+'&myTittle='+tittle_text+'&myColor='+tittle_color+'");</script>');
	t_nxt++;
	
	
}

// ---------------------------------------------------------------------------------------
//  specific funcions
// ---------------------------------------------------------------------------------------

function pageCheck() {
	
		var end = 0;
		var myArray = new Array();
		var myString = String(document.location);
		

		for(i=0;i<myString.length;i++) {
		
			if(myString.slice(i, (i+1)) == "/") {

				myArray.push(myString.slice(end,i));
				end = i+1;
							 
			}
			if (i == myString.length-1) {
				myArray.push(myString.slice(end,i+1));
			}

		}

		myArray.reverse();
		
		//
		for (i=0;i<ar_language.length;i++) {
			if (myArray[1] == ("htms_"+ar_language[i])) {
			//

				currentLanguage = i;
				break;
			//
			}
			//
		}
		//
		

		var docName = myArray[0].split("?",2);		
		myDocumentName = docName[0];

		if (myDocumentName  == "default.asp" || myDocumentName == "")  {
			
			currentArea = 0;
			currentSubArea = 0;
			
		} else {
					
			
			var myFile = myDocumentName.split(".",2);	
			var myString = myFile[0].split("_",4);
			
			if(myString[0] == "page" ) {
			
				currentArea = (myString[1]);
				
				if (myString[2] != undefined) {
					
					currentSubArea = Number(myString[2])
					
				} else {
					
					currentSubArea = 0;
					
				}
			} else {
					
				currentArea = undefined;
				currentSubArea = undefined;
			}
		}
		
		

	
		
}
function assembleMenu() {
	//
		document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">'
		  + '      <tr>'
		  + '        <td width="78" height="15"></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '        <td></td>'
		  + '      </tr>');
		document.writeln('<tr>');
		document.writeln('<td></td>');
		
		for (i=0;i<9;i++) {
			
			if (currentArea == (i)) {

				if (i==0) {
					
					document.write('<td><a href="default.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'topmenu_'+(i)+'\',\'\',\'../images/topmenu_'+(i)+'_f2.gif\',1);"><img name="topmenu_'+(i)+'" src="../images/topmenu_'+(i)+'_f2.gif" border="0" id="topmenu_'+(i)+'" alt="" /></a></td>');
						
				} else {		
				
					document.write('<td><a href="page_'+(i)+'.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'topmenu_'+(i)+'\',\'\',\'../images/topmenu_'+(i)+'_f2.gif\',1);"><img name="topmenu_'+(i)+'" src="../images/topmenu_'+(i)+'_f2.gif" border="0" id="topmenu_'+(i)+'" alt="" /></a></td>');
					
				}
				
			
				
			} else {
				
				if (i==0) {
				
					document.writeln('<td><a href="default.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'topmenu_'+(i)+'\',\'\',\'../images/topmenu_'+(i)+'_f2.gif\',1);"><img name="topmenu_'+(i)+'" src="../images/topmenu_'+(i)+'.gif" border="0" id="topmenu_'+(i)+'" alt="" /></a></td>');
				
				} else {
					
					document.writeln('<td><a href="page_'+(i)+'.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'topmenu_'+(i)+'\',\'\',\'../images/topmenu_'+(i)+'_f2.gif\',1);"><img name="topmenu_'+(i)+'" src="../images/topmenu_'+(i)+'.gif" border="0" id="topmenu_'+(i)+'" alt="" /></a></td>');
						
				}
				
			}
			
			if (i<8) {
				document.writeln('<td><img src="../images/topmenu_spacer.gif" border="0"/></td>');
			}
		}
		
		document.writeln('</tr>');
		document.writeln('</table>');
		
	//
}


function assembleSubMenu(area,fv_menu,checkSub) {

	if (checkSub == undefined) 
	{
		//checkSub = 0;
	}

	detectFlash( '../flash/submenu.swf',  '100%', '20', '8EC0E5', 'high', 'transparent', 'flash_submenu', 'fv_currentSubArea='+checkSub+'&fv_menu='+fv_menu+'&fv_area='+area);
	
	
}

function assemblePageTop(tittle,bgColor,bgImage,frontImage) {
	//
	detectFlash( '../flash/pagetop.swf',  '768', '114', 'ffffff', 'high', 'opaque', 'flash_pagetop', 'fv_tittle='+tittle+'&fv_bgColor='+bgColor+'&fv_bgImage='+bgImage+'&fv_frontImage='+frontImage);
	//
}
//

function showImageGallery(id) {
	//
	document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>');
	
	var myGallery = eval("ar_gallery_"+id);
	//
	for (i=0;i<myGallery.length;i++) {
		//
		document.writeln('<td width="36"><a href="javascript: "onMouseOver=\'document.image_src.src="../images/gallery/'+id+'/'+myGallery[i][0]+'";var_currentImageGallery="../images/gallery/'+id+'/'+myGallery[i][0]+'";var_currentImageGallery_tittle="'+myGallery[i][1]+'";var_currentImageGallery_text="'+myGallery[i][2]+'";showImageGalleryText("'+myGallery[i][1]+'","'+myGallery[i][2]+'");\' onclick="popupCurrentImageGallery();"><img src="../images/gallery/'+id+'/'+(i+1)+'.jpg" width=36 height=36 border=0></a></td>');
		//
		if (i<myGallery.length-1) {
			//
			document.writeln('<td></td>');
			//
		} 
		//
	}
	document.writeln('</tr></table>');
	
	
	//
	document.write('<table width="222" border="0" cellpadding="0" cellspacing="0">'
 	 + '  <tr>'
	  + '    <td height="10"></td>'
	  + '  </tr>'
	  + '  <tr>'
	  + '    <td><form name="imageChange">'
	  + '      <a href="javascript:" onClick="popupCurrentImageGallery();"><img src="../images/gallery/0/1.jpg" width=222 height=160  name=\'image_src\' border=0></a><br>'
	  + '      <div id="showContent"></div>'
	  + '    </form></td>'
	  + '  </tr>'
	  + '  <tr>'
	  + '    <td><div id="imageGallery_text"></div></td>'
	  + '  </tr>'
	  + '  <tr>'
	  + '    <td align="right" class="content_text">&nbsp;</td>'
	  + '  </tr>'
	  + '</table>'
	  + ''
	  + '');
	
	showImageGalleryText(myGallery[0][1], myGallery[0][2])
	
	//
}

function popupCurrentImageGallery() {
	//
	popupImageGallery(var_currentImageGallery,var_currentImageGallery_tittle,var_currentImageGallery_text);
	//
}

function popupImageGallery(myImage,myTittle,myText) {
	
	pop_gallery=window.open("","Imagem","width=440 height=440");
	pop_gallery.document.open();
	pop_gallery.document.write("<html><head><title>Imagem " + myTittle + "</title></head>");
	pop_gallery.document.write("<link href='../extras/style.css' rel='stylesheet' type='text/css'>");
	pop_gallery.document.write("<body>");
	pop_gallery.document.write("<p align=center><img src= " + myImage + "><br><br><b><font face=verdana size=2>" + myTittle+ "</b>.");
	pop_gallery.document.write("<font face=verdana size=1><br><br>"+myText);

}

function popupItemImageGallery(gallery,num) {
	//
	var myGallery = eval("ar_gallery_"+gallery);
	//
	popupImageGallery("../images/gallery/0/"+myGallery[num][0],myGallery[num][1],myGallery[num][2])
	//
}

function showImageGalleryText(myTittle, myText) {
	//
	document.getElementById("imageGallery_text").innerHTML='<span class="content_text"><span class="title_text"><strong>'+myTittle+'</strong></span><br>'+myText+'</span>';
	//
}

// ---------------------------------------------------------------------------------------
//  fireworks over behaviors
// ---------------------------------------------------------------------------------------


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];}
}



// ---------------------------------------------------------------------------------------
// flash detect
// ---------------------------------------------------------------------------------------


// initialize global variables

var detectableWithVB = false;
var pluginFound = false;
var MinimalVersion= 8;

// functions

function redirectCheck(pluginVersion, pluginFound, SWF_NAME, SWF_WIDTH, SWF_HEIGHT, SWF_BGCOLOR, SWF_QUALITY, SWF_WMODE, SWF_ID, SWF_VARS) {
	
	if( pluginFound ) {
		// Verify version
		if(pluginVersion >= MinimalVersion) {

			var myVars = SWF_VARS+"&object_id="+SWF_ID;

			document.writeln('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" VIEWASTEXT id='+SWF_ID+' name='+SWF_ID+' width="'+ SWF_WIDTH +'" height="'+ SWF_HEIGHT +'" wmode="'+SWF_WMODE+' swLiveConnect="TRUE" showMenu="false">');
			document.writeln('<PARAM NAME=movie VALUE="'+SWF_NAME+'" >');
			document.writeln('<PARAM NAME=FlashVars VALUE="'+myVars+'">');
			document.writeln('<PARAM NAME=quality VALUE="'+SWF_QUALITY+'">');
			document.writeln('<PARAM NAME="wmode" VALUE="'+SWF_WMODE+'" >');
			document.writeln('<PARAM NAME="showMenu" VALUE="false">');
			document.writeln('<PARAM NAME="bgcolor" value="'+SWF_BGCOLOR+'">'); 
			document.writeln('<EMBED src="' + SWF_NAME + '" showMenu="false" name="'+SWF_ID+'" FlashVars="'+myVars+'" swLiveConnect="TRUE" width="'+ SWF_WIDTH +'" height="'+ SWF_HEIGHT +'" type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" bgcolor="' + SWF_BGCOLOR + '" quality="' + SWF_QUALITY + '" wmode="'+SWF_WMODE+'"></EMBED>');
			document.writeln('</OBJECT>');
			
		} else {

			noFlashFound();
		}
		
    } else {

		noFlashFound();
    }	
}

function detectFlash( SWF_NAME, SWF_WIDTH, SWF_HEIGHT, SWF_BGCOLOR, SWF_QUALITY, SWF_WMODE, SWF_ID, SWF_VARS) {
    pluginFound = detectPlugin('Shockwave','Flash'); 

    // if not found, try to detect with VisualBasic
    if( !pluginFound && detectableWithVB ) {
		pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.' + versionFlash() );
    }
	pluginVersion = versionFlash();
    // check for redirection
    return redirectCheck(pluginVersion, pluginFound, SWF_NAME, SWF_WIDTH, SWF_HEIGHT, SWF_BGCOLOR, SWF_QUALITY, SWF_WMODE, SWF_ID, SWF_VARS);
}

function versionFlash() {
	var sAux = 8;
	
	for( i = 10; i > 2; i-- ) {
		
		pluginFound = detectPlugin('Shockwave Flash ' + i); 		
		// if not found, try to detect with VisualBasic
		if(!pluginFound && detectableWithVB) {
			pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.' + i);
		}
		if ( pluginFound ) {
			sAux = i;
			break;
		}
	}
	
	return sAux;
}

function detectPlugin() {

    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;

    // consider pluginFound to be false until proven true
    var pluginFound = false;

    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
		var pluginsArrayLength = navigator.plugins.length;
	
		// for each plugin...
		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	
			// loop through all desired names and check each against the current plugin name
			var numFound = 0;
			for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
			
				// if desired plugin name is found in either plugin name or description
				if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
					(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
					// this name was found
					numFound++;
				}   
			}
	
			// now that we have checked all the required names against this one plugin,
			// if the number we found matches the total number provided then we were successful
			if(numFound == daPlugins.length) {
				pluginFound = true;
				// if we've found the plugin, we can stop looking through at the rest of the plugins
				break;
			}
		}
    }
    
    return pluginFound;
    
} // detectPlugin

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

function noFlashFound() {
	
	document.location="noflash.htm";
}
