/**
 * @author gallema1
 */
$(document).ready(function(){
	
            asyncRequest('/HighLightJobOffers.aspx',onComplete,'GET');
//			$("#holder").accordion({event: "mouseover"});
//		  
//			h.interval = window.setInterval(function(){
//				
//				$('#holder').fadeOut("slow",function(){					
//					placeJobs(h.count);
//					$('#holder').fadeIn("slow");	
//				});
//			},h.time);
		});
			h = {}
//			h.time = 60000;
//			h.flag = 0;
//			h.interval = null;
//			h.aTitles = new Array();
//			h.aCountry = new Array();
//			h.aDescription = new Array();
//			h.aIdJobOffer = new Array();
			h.count = 6;
			h.offset = 6;
		function asyncRequest(url,callback,method){
			if(arguments[3]){
				 var postData = arguments[3];
			}
			var http = null;
			try {
				http = new XMLHttpRequest();
			}catch(e){
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
			http.onreadystatechange = function(){
			//	alert(http.status);
				if(http.readyState == 4 && http.status == 200){
					callback(http);
				}
			}
			http.open(method, url);
			http.send(postData || null);			
		}
		function onComplete (o){
			var xml = o.responseXML;
			h.aTitles = xml.getElementsByTagName('Title');
			h.aCountry = xml.getElementsByTagName('Country');
			h.aDescription = xml.getElementsByTagName('Description');
			h.aIdJobOffer = xml.getElementsByTagName('IdJobOffer');
			placeJobs(h.count);
		}
		placeJobs = function (count){
			
			
			var nodes = '';
			for(var i = count-h.offset;i < count;i++){
			    if(h.aTitles[i] != null)
			    {
				    nodes += '<li><div class="ui-accordion-left"></div>';
				    nodes += '<a target="_blank" href="/Candidates/Search/ViewJobOfferDetail.aspx?id=' + h.aIdJobOffer[i].firstChild.nodeValue + '" class="ui-accordion-link">' + h.aTitles[i].firstChild.nodeValue + '<em>';
				    //nodes += h.aCountry[i].firstChild.nodeValue;
				    nodes += '</em><div class="ui-accordion-right"></div></a>';
				   // nodes += '<div style="display:none">' + h.aDescription[i].firstChild.nodeValue + '</div></li>'; 
			    }
			}
			//nodes +='<p>'+ h.flag +'</p>';
			var holder = document.getElementById('holder');
			holder.innerHTML = '';
			holder.innerHTML = nodes;
//			var offset = h.aTitles.length - count;
//			if(count < h.aTitles.length){
//				h.count += offset;
//				//alert(h.count);
//				
//			}else {
//				var count = 3;
//				h.count = 3;				
//			}			
		}