$(function()
{

	$.ajax({ type: "GET", url: "xml/data.xml", dataType: ($.browser.msie) ? "text" : "xml", complete: function(d, s) 
	{
			var text = "";
			text = String(d.responseText);
			var theXML = createXMLDocument(text);
            $(theXML).find('com').each(function() {
						var id = $(this).attr('id');
						//alert(id);
						var titre = $(this).find('titre').text();
						//var accroche = $(this).find('accroche').text();
						//console.log("titre:" + titre + ";accroche:" + accroche);
						
						// titre de la news
						//alert($("#"+$(this).attr('id')).children(".titre_news"));*
						
						$("#cadre").append('<div id="'+id+'" class="slidenews"><div id="date"><span class="news_date_jour"></span><span class="news_date_mois"></span></div><div class="new_box"><p class="eimm_date titre_news"></p><p class="text_news"></p><div class="eimm_consultez titre_lien_news"></div></div><div class="eimm_clear"></div></div>');  
						
						var idNews = "#"+$(this).attr('id');
						$(idNews).children(".new_box").children(".titre_news").append($(this).find('titre').text()); 
						$(idNews).children(".new_box").children(".text_news").append($(this).find('accroche').text());
						$(idNews).children("#date").children(".news_date_jour").append($(this).find('jour').text());
						$(idNews).children("#date").children(".news_date_mois").append($(this).find('mois').text());
					
						
					if($(this).find('lien').text()!="none"){
						$(idNews).children(".new_box").children(".titre_lien_news").append('<a href="'+$(this).find('lien').text()+'" title="'+$(this).find('accroche').text()+'"  target="'+$(this).find('target').text()+'">'+$(this).find('titrelien').text()+'</a>');
						}
						
						
//if ( $(this).find('flash').text().match('flash') ) { $("#"+$(this).attr('id')).append($(this).find('flash').text()); }
//else { $("#"+$(this).attr('id')).append('<a xtclib="'+$(this).attr('id')+'" href="'+$(this).find('lien').text()+'" title="'+$(this).find('accroche').text()+'" '+$(this).find('popup').text()+' ><img src="'+$(this).find('image').text()+'" height="'+$(this).find('hauteur').text()+'" width="'+$(this).find('largeur').text()+'" /></a>'); }

					});
				autoslide();					
						
	}});
	

	
	
function createXMLDocument(string)
{

	 var browserName = navigator.appName;
	 var doc;
	 if (browserName == 'Microsoft Internet Explorer')
	 {
	  doc = new ActiveXObject('Microsoft.XMLDOM');
	  doc.async = 'false'
	  doc.loadXML(string);
	 } else {
	  doc = (new DOMParser()).parseFromString(string, 'text/xml');
	 }

	 return doc;
}


function autoslide()
{
//options( 1 - ON , 0 - OFF)  
        var auto_slide = 1;  
        var hover_pause = 1;  
        var key_slide = 1; 
		var obj = $("#slidesContainer"); 
		var s = $('.slidenews').length;
		//var s = $("#cadre").children().length;
		$('#slidesContainer').css("overflow","hidden");
        //speed of auto slide(  
        var auto_slide_seconds = 4000;
		
		if(s==2)
		{
			auto_slide = 0;
			hover_pause = 0;
			key_slide =	 0;
			$('#nextBtn').hide();
			$('#prevBtn').hide();
			
		}

     /* IMPORTANT: i know the variable is called ...seconds but it's 
        in milliseconds ( multiplied with 1000) '*/  
  
        /*move the last list item before the first item. The purpose of this is 
        if the user clicks to slide left he will be able to see the last item.*/  
     //  $('#cadre .slidenews:first').before($('#cadre .slidenews:last'));  
  
        //check if auto sliding is enabled  
        if(auto_slide == 1){  
            /*set the interval (loop) to call function slide with option 'right' 
            and set the interval time to the variable we declared previously */  
            var timer = setInterval('slide("next")', auto_slide_seconds);  
  
            /*and change the value of our hidden field that hold info about 
            the interval, setting it to the number of milliseconds we declared previously*/  
            $('#hidden_auto_slide_seconds').val(auto_slide_seconds);  
        }  
  
        //check if hover pause is enabled  
        if(hover_pause == 1){  
            //when hovered over the list  
            $('#cadre, .eimm_news_button_top, .eimm_news_button').hover(function(){  
                //stop the interval  
                clearInterval(timer)  
            },function(){  
                //and when mouseout start it again  
                timer = setInterval('slide("next")', auto_slide_seconds);  
            });  
  
        }  
  
        //check if key sliding is enabled  
        if(key_slide == 1){  
  
            //binding keypress function  
            $(document).bind('keypress', function(e) {  
                //keyCode for left arrow is 37 and for right it's 39 '  
                if(e.keyCode==37){  
                        //initialize the slide to left function  
                        slide('previous');  
                }else if(e.keyCode==39){  
                        //initialize the slide to right function  
                        slide('next');  
                }  
            });  
  
        }  

}


});
