$(document).ready(function(){
   $('#search_bar').click(function() {
      $('#search_bar').css("background-position", '0 -21px');
   });
});

function ClearBG(obj, color) { obj.style.background = "#"+color; }

function ReinstateBG(obj,url,color,left,top) { obj.style.background = "#"+ color +" url(" + url + ") no-repeat "+ left +"px "+ top +"px"; }


var speedIn = 300;
var speedOut = 300;
var widthMin = 210;

var aeroBtn = false;
var aeroPanel = false;
var windBtn = false;
var windPanel = false;
var indBtn = false;
var indPanel = false;

function languageonchange(selectobj) 
{ 
  if (selectobj.selectedIndex == 0)
  {window.location="http://www.hexcel.com"};
  if (selectobj.selectedIndex == 1)
  {window.location="http://www.hexcel.com/cn/"};
  if (selectobj.selectedIndex == 2)
  {window.location="http://www.hexcel.com/fr/"};
} 

function Panels() {
   $("#aeroVertBtn").mouseover(function(){ aeroBtn = true;  $("#aeroVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#aeroVertBtn").mouseout(function() { aeroBtn = false; if(!aeroPanel) { $("#aeroVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
   $("#aeroVertPanel").mouseover(function(){ aeroPanel = true;  $("#aeroVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#aeroVertPanel").mouseout(function() { aeroPanel = false; if(!aeroBtn) { $("#aeroVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
	 
   $("#windVertBtn").mouseover(function(){ windBtn = true;  $("#windVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#windVertBtn").mouseout(function() { windBtn = false; if(!windPanel) { $("#windVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
   $("#windVertPanel").mouseover(function(){ windPanel = true;  $("#windVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#windVertPanel").mouseout(function() { windPanel = false; if(!windBtn) { $("#windVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
	 
   $("#indVertBtn").mouseover(function(){ indBtn = true;  $("#indVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#indVertBtn").mouseout(function() { indBtn = false; if(!indPanel) { $("#indVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
   $("#indVertPanel").mouseover(function(){ indPanel = true;  $("#indVertPanel").stop().animate({ left: "0px", width: 256 }, speedOut ); });
   $("#indVertPanel").mouseout(function() { indPanel = false; if(!indBtn) { $("#indVertPanel").stop().animate({ left: "276px", width: widthMin }, speedIn ); } });
}

function world_map() {
   $('.point').mouseover(function(){
      var height = $('#pop_' + $(this).attr("id")).height();
      var left = $(this).css("left");
      var new_left = left.replace('px', '') - 80;
      
      var top = $(this).css("top");
      var new_top = top.replace('px', '') - height + 7;
      
      $('#pop_' + $(this).attr("id")).css("left", new_left + 'px');
      $('#pop_' + $(this).attr("id")).css("top", new_top + 'px');
      
      $('.mapup').hide();
      
      $('#pop_' + $(this).attr("id")).show();
   });
   $('.mapup').mouseout(function(){
      $('.mapup').hide();
   });
}


function alternateColor(id)
{ 
 if(document.getElementsByTagName){ 
   if(document.getElementById(id)) {
   var table = document.getElementById(id);   
   var rows = table.getElementsByTagName("tr");   
   for(i = 0; i < rows.length; i++){           
 //manipulate rows 
     if(i % 2 == 0){ 
       rows[i].className = "hxl-even"; 
     }else{ 
       rows[i].className = "hxl-odd"; 
     }       
   } 
 }
 } 
}

function newWin(newPage, win, w, h) {
if (!w) {
 var win, w, h;
       win= "win";
	w = "200";
	h = "230";
}
  infoWindow= window.open(newPage, win, 'width=' + w + ',height=' + h + ',scrollbars=yes,resizable=yes')
  infoWindow.focus();
}

function toggle(year) {

   if (document.getElementById('news-year-list-'+year).style.display == 'block')
      document.getElementById('news-year-'+year).className = 'news-year';
   else
      document.getElementById('news-year-'+year).className = 'news-year news-year-open';


   $('#news-year-list-'+year).slideToggle();
	document.getElementById('news-year-'+year).blur();
   return false;
}

/**
 * FAQ object that handles our actions for our page.
 *
 * @constructor
 */
var FAQ = function (id)
{
	var self = this;

	/**
	 * Initialize the object and load up the data
	 *
	 * @param {string} id The id attribute of the container div holding the FAQs
	 */
	self.init = function (id)
	{
		self.holder = document.getElementById(id);
		self.load();
	};

	/**
	 * Load in all the FAQs fron the markup
	 */
	self.load = function ()
	{
		self.questions = [];
		
		var eles = self.holder.getElementsByTagName('div');
		for (var i = 0; i < eles.length; i++)
		{
			if (eles[i].className == 'faq-entry')
			{
				var q = eles[i].getElementsByTagName('a');
				var a = eles[i].getElementsByTagName('div');

				if (q.length == 1 && a.length == 1)
				{
					// Hide the answer and set up the click listener
					a[0].style.display = 'none';
					self.setupListener(q[0], a[0]);
				
					self.questions.push({
						question : q[0],
						answer   : a[0]
					});
				}
			}
		}
	};

	/**
	 * Creates a listener on the click event of the <question> to show the <answer>
	 *
	 * @param {HTMLElement} question The anchor tag holding the question
	 * @param {HTMLElement} answer The element containing the answer to show
	 */
	self.setupListener = function (question, answer)
	{
		question.onclick = function (e)
		{
			// Hide all
			for (var i = 0; i < self.questions.length; i++)
			{
				self.questions[i].answer.style.display = 'none';
			}

			answer.style.display = 'block';

			// Return false to keep from following our href
			return false;
		};
	};

	self.init(id);
};
