//+J+M+J+


var imagePath = 'img/projectorbuttons/';
var projButtons = Array();

$.ajax({
	url: "mainSetup.xml",
        async: false,
	processData: false,
	dataType: "xml",
	success: function(xml) {
	$(xml).find('section').each(function(){
		var projButton = document.createElement('img');
		var buttonUrl = $(this).attr('buttonUrl');
		var sectionName =  $(this).attr('name');
		$(projButton).attr({
			src: imagePath + buttonUrl,
			    title: sectionName,
			    alt: sectionName
			    
			    });
		
		var buttonOverUrl =  $(this).attr('buttonOverUrl');
		var buttonPressUrl =  $(this).attr('buttonPressUrl');
		$(projButton).hover(function(){
			if (!($(this).attr('src') == imagePath + buttonPressUrl)){
			    $(this).attr({
				    src: imagePath + buttonOverUrl
					});
			}
		    },
		    function(){
			if (!($(this).attr('src') == imagePath + buttonPressUrl)){
			    $(this).attr({
				    src: imagePath + buttonUrl
					});		
			}			
		    }
		    );
		
		var buttonPressUrl =  $(this).attr('buttonPressUrl');

		var postData = '';
		
		var i = 1;
		postData = 'headlineImgUrl=' + imagePath + $(this).attr('headlineImgUrl'); 
		$(this).find('rssFeed').each(function(){
			postData += '&url_' + i + '=' + $(this).attr('url') + '&show_' + i + '=' + $(this).attr('show');
			i++;
		    }
		    );
		
		$(projButton).click(function(){
			//unpress all buttons
			$('#projButtons img').each(
						   function(){					       
						       $(this).attr({
							       src : imagePath + $(xml).find("section[name='"+$(this).attr('alt')+"']").attr('buttonUrl')
								   });						       
						   });
			//press this button
			$(this).attr({
				src: imagePath + buttonPressUrl
				    });			    
			//go to the RSS feeds 
			$.ajax({
				type : "POST",
				url : 'feedreeder.php' ,
				data : postData ,
				success: function(msg){
				    $('#pageOne').hide();				    
				    $('#newsBox').hide();				    
				    $('#newsBox').empty();
				    $('#newsBox').append(msg);				   
				    $('#newsBox').show();				   
				}
			    }).responseText;
			
		    });

		projButtons.push(projButton);

		
	    });
	}		
    }).responseText;

$(document).ready(function(){
	while(projButtons.length > 0){	    
	    $('#projButtons').append(projButtons.shift());
	}
    });