window.onload = base;
var dtBtnArray = new Array();
var ddBtnArrayChild = new Array();
var slideSpeed = 400;
var switchBoolen = new Array();
var backColorBoolen = new Array();
var opneArray = new Array();
var newspage = 0;
var oldObj = null;
function base(){
	slidDown_con();
	listBtn();
	if(url('links.html')) linkBtn();
	if(url('news.html')) requestText(newspage);
	if(url('filling_systems.html')) hideFilling();
	if(url('downloads.html')&& !url('products_downloads.html')) reposPtag();
	if(url('company_contactus.html') || url('upload_files.html')||url('faq.html')) btnBG();
	if(browser('MSIE 8.0')){if(url('employment_opportunities.html') || url('faq.html') || url('news.html')||url('filling_systems.html'))engine();}
	if(browser('MSIE 6.0')) {liRePos();}
	}

function linkBtn(){
	var btnArray = new Array();
	for(i=0; i<4; i++){
		btnArray.push(document.getElementById('img'+i));
		btnArray[btnArray.length-1].onmouseover = function (){this.firstChild.style.color = '#9fa21f';}
		btnArray[btnArray.length-1].onmouseout = function (){this.firstChild.style.color = '#4d4d4d';}
		}
	}

function btnBG(){
	$('#header_right a').each(function(){
		if(url($(this).attr('href')) == true){
		$(this).css('background-position','0 -28px');	
		}
	});
	
	$('#content_in_left_company a').each(function(){
		if(url($(this).attr('href')) == true){
		$(this).css('background-position','right -50px');	
		}
	});
	}

function liRePos(){
	var kip_nav = document.getElementById('kip_nav');
	if(kip_nav){
		var li = kip_nav.getElementsByTagName('li');
		if(url('kip_scanners.html'))li[1].style.margin = '-19px 0 0 0';
		if(url('kip_finishin_accessories.html'))li[2].style.margin = '-19px 0 0 0';
		}
	}
	
function engine(){
	setInterval(resizeDiv,33);
	}
	
function resizeDiv(){
	var eo_box = $("#eo_box");
	var content_company = $("#content_company");
	var eo_box_top = $("#eo_box").offset().top
	var container = $("#container");
	container.css('height',(content_company.height()+390)+'px');
	}
	
function reposPtag(){
	var div = document.getElementById('content_in_right_services');
	var a = getChildNodes('content_in_right_services','a');
	for(i=0; i<a.length; i++){
		if($(a[i]).text().length<=21){
			if(browser('MSIE 7.0')||browser('MSIE 6.0')){
					a[i].nextSibling.style.margin = '-12px 0 0 0';
					a[i].childNodes[0].style.margin = '1px 0 0 0';
					$(a[i]).css('margin-top','18px');
				}else{
					a[i].nextSibling.style.marginTop = '-12px';
					a[i].childNodes[0].style.margin = '3px 0 0 0';
					$(a[i]).css('margin-top','9px');
				}
			
			}
		}
	}
	
function slidDown_con(){
	if(url('employment_opportunities.html') || url('faq.html') ||url('news.html')){

	var theObj = document.getElementById('eo_box');
	var theObjChild = theObj.getElementsByTagName('div');
		
		for(i=0; i<theObjChild.length; i++){
		switchBoolen.push(true);
		opneArray.push(true);
		dtBtnArray.push($(theObjChild[i]));
		
		var num = dtBtnArray.length-1;
		
		$(dtBtnArray[dtBtnArray.length-1]).hide();
		
		if(!browser('MSIE')){
		ddBtnArrayChild.push(theObjChild[i].previousSibling.previousSibling);
		}else{
			ddBtnArrayChild.push(theObjChild[i].previousSibling);
			}
			
		ddBtnArrayChild[num].name = i;
		
		if(i%2 == 0) ddBtnArrayChild[num].style.backgroundColor = "#f0f0db";
		ddBtnArrayChild[num].onclick = function(){showCont(this.name)}
		ddBtnArrayChild[num].onmouseover = function(){this.style.backgroundPosition = 'right 0px';}
		ddBtnArrayChild[num].onmouseout = function(){this.style.backgroundPosition = 'right -27px';}
			}
		}
		//requestText('eo_box','news.xml');
	}

function showCont(e){
		dtBtnArray[e].slideDown(slideSpeed);
	ddBtnArrayChild[e].onmouseout = function(){this.style.backgroundPosition = 'right 0px';}
	//switchBoolen[e] = false;
	
	if(oldObj != null){
		if(oldObj != e){
		dtBtnArray[oldObj].slideUp(slideSpeed);
		ddBtnArrayChild[oldObj].style.backgroundPosition = 'right -27px';
		ddBtnArrayChild[oldObj].onmouseout = function(){this.style.backgroundPosition = 'right -27px';}
		opneArray[e] = true;
		//switchBoolen[oldObj] = true;
		}else{
			if(opneArray[e] == true){
				dtBtnArray[oldObj].slideUp(slideSpeed);
				ddBtnArrayChild[oldObj].style.backgroundPosition = 'right -27px';
				ddBtnArrayChild[oldObj].onmouseout = function(){this.style.backgroundPosition = 'right -27px';}
			opneArray[e] = false;
			}else{
				dtBtnArray[e].slideDown(slideSpeed);
				ddBtnArrayChild[e].style.backgroundPosition = 'right 0px';
				opneArray[e] = true;
				}
			}
	}
	oldObj = e;
	}
	
	
function url(pageName){
	var objURL = new Object();
	if(document.URL.match(pageName)){
		return objURL = true;
		}else{
			return objURL = false;
			}
	}
	
function browser(pageName){
	var objURL = new Object();
	if(navigator.userAgent.indexOf(pageName)>-1){
		return objURL = true;
		}else{
			return objURL = false;
			}
	}
	
function getChildNodes(obj,nodetype){
	var theObj = document.getElementById(obj);
	var theObjChild = theObj.getElementsByTagName(nodetype);
	return theObjChild;
	}
	
function listBtn(){	
	if(browser('MSIE 7.0')){
		var atai = '9px 10px';
		}else{
			var atai = '9px 2px';
			}
	
	var kip_nav = document.getElementById('kip_nav');
	
	var products_nav_box = document.getElementById('products_nav_box');
	if(products_nav_box){
	var divBtn = products_nav_box.getElementsByTagName('div');
	divBtn[1].style.backgroundPosition = "0px -15px";
	var p = divBtn[1].getElementsByTagName('p');
	p[0].onmouseover = function (){divBtn[1].style.backgroundPosition = atai;}
	p[0].onmouseout = function (){divBtn[1].style.backgroundPosition = "0px -15px";}
	}
	}
	


var divArray = new Array();
var pbtn = new Array();
function hideFilling(){
	var content_in_right_support = document.getElementById('content_in_right_support');
	var aTag = content_in_right_support.getElementsByTagName('a');
	for(i=0; i<aTag.length; i++){
		opneArray.push(true);
		backColorBoolen.push(true);
		switchBoolen.push(true);
		dtBtnArray.push(aTag[i]);
		pbtn.push(aTag[i].parentNode);
		divArray.push($(aTag[i].parentNode.nextSibling));
		//var num = divArray.length-1;
		pbtn[pbtn.length-1].id = pbtn.length-1;
		pbtn[pbtn.length-1].id = pbtn.length-1;
		dtBtnArray[dtBtnArray.length-1].id = divArray.length-1;
		dtBtnArray[dtBtnArray.length-1].name = divArray.length-1;
		divArray[divArray.length-1].hide();
		pbtn[pbtn.length-1].onclick = function(){showDiv(this.id,dtBtnArray[this.id])}
		pbtn[dtBtnArray.length-1].onmouseover = function(){chackBoolen(this.id);}
		pbtn[dtBtnArray.length-1].onmouseout = function(){chackBoolen2(this.id);}
		dtBtnArray[dtBtnArray.length-1].onmouseout = function(){this.parentNode.style.backgroundColor = '#ffffff';}
		}
	}
	
function chackBoolen(num){
	if(switchBoolen[num] == true){
		dtBtnArray[num].parentNode.style.backgroundColor = '#f2f2f2';
		}
	}
	
function chackBoolen2(num){
	if(switchBoolen[num] == true){
		dtBtnArray[num].parentNode.style.backgroundColor = '#ffffff';
		}else{
			dtBtnArray[num].parentNode.style.backgroundColor = '#f2f2f2';
			}
	}
	
	
function showDiv(num,obj){
	divArray[num].slideDown(slideSpeed);
	dtBtnArray[num].parentNode.style.color = '#561346';
	dtBtnArray[num].parentNode.style.backgroundColor = '#f2f2f2';
	dtBtnArray[num].parentNode.style.backgroundPosition = 'right -27px';
	obj.onmouseout = function(){chackBoolen(this.id);}
	dtBtnArray[num].parentNode.onmouseover = function(){this.style.backgroundColor = '#f2f2f2';}
	dtBtnArray[num].parentNode.onmouseout = function(){chackBoolen2(num);}
	switchBoolen[num] = false;
	
	if(oldObj != null){
		if(oldObj != num){
		divArray[oldObj].slideUp(slideSpeed);
		dtBtnArray[oldObj].parentNode.style.color = '#4D4D4D';
		dtBtnArray[oldObj].parentNode.style.backgroundColor = '#ffffff';
		dtBtnArray[oldObj].parentNode.style.backgroundPosition = 'right 11px';
		dtBtnArray[oldObj].parentNode.onmouseout = function(){this.style.backgroundPosition = 'right 11px'; this.style.backgroundColor = '#ffffff';}
		opneArray[num] = true;
		//switchBoolen[oldObj] = true;
		}else{
			if(opneArray[num] == true){
				divArray[oldObj].slideUp(slideSpeed);
				dtBtnArray[oldObj].parentNode.style.color = '#4D4D4D';
				dtBtnArray[oldObj].parentNode.style.backgroundColor = '#ffffff';
				dtBtnArray[oldObj].parentNode.style.backgroundPosition = 'right 11px';
				dtBtnArray[oldObj].parentNode.onmouseout = function(){this.style.backgroundPosition = 'right 11px'; this.style.backgroundColor = '#ffffff';}
			opneArray[num] = false;
			}else{
				divArray[num].slideDown(slideSpeed);
				dtBtnArray[num].parentNode.style.color = '#561346';
				dtBtnArray[num].parentNode.style.backgroundColor = '#f2f2f2';
				dtBtnArray[num].parentNode.style.backgroundPosition = 'right -27px';
				opneArray[num] = true;
				}
			}
	}
	oldObj = num;
}