window.onload = function(){
	 $.ajax({
    type: "GET",
    url: "data/vacancy.xml",
	contentType:"application/xml;charset=utf-8",
    dataType: "xml",
    success: function(data){mycarousel_itemAddCallback(data);}
  });
  news_init();
		
}
function mycarousel_itemAddCallback(data)
{

    // Simply add all items at once and set the size accordingly.
    //var items = data.split('|');
	var items = new Array();
	
  $(data).find("vacancy").each(function()
  {
	var pItems = new Array();	
	pItems[0] = $(this).attr("id");
	pItems[1] = $(this).find("title").text();
	pItems[2] = $(this).find("date").text();
	pItems[3] = $(this).find("desc").text();
	pItems[4] = $(this).find("apply").text();
	items.push(pItems);

  });

    for (i = 0; i < items.length; i++) {
		$("#WTID").append(mycarousel_getItemHTML(items[i]));
    }
    
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{

   var str =  '<div id="container" class="letestNewsTd"> <a href="#" onclick="javascrit:ToggleDivs(\'div'+ item[0] +'\');return false;"> <strong>'+ item[1] +'</strong></a>'+
              '<div id="div'+ item[0] +'" class="" style="display:none;"><br>'+
              ''+item[3] +'<div><span class="showHighlight"><strong>APPLY NOW </strong>- </span><a href="'+ item[4] +'">'+ item[4] +'</a> | 022- 42937400 </div></div></div>'
    return str;
};
function news_init()
{
	 $.ajax({
    type: "GET",
    url: "data/news.xml",
	contentType:"application/xml;charset=utf-8",
    dataType: "xml",
    success: function(data){news_itemAddCallback(data);}
  });
		
}
function news_itemAddCallback(data)
{
 // Simply add all items at once and set the size accordingly.	
  $(data).find("news").each(function()  {

	  $("#newsdiv").append('<div class="letestNewsTd"><a href="latest-news.html?id='+ $(this).attr("id") +'">'+  $(this).find("headline").text()+' </a></div>');
  });
    
};

 function ToggleDivs(id)
 {
     var imgSrc = document.getElementById(id).style.display;            
     if(imgSrc == "block")                         
	 {	
        $("#"+ id).slideUp("slow");                    		
		//$("#"+ id).parent("#container").attr("class", "letestNewsTd");

	 }
     else if(imgSrc == "none")           
     { 
		 $("#"+ id).slideDown("slow");        
		 //$("#"+ id).parent().attr("class", "showHighlight");
	 }
 }
