function storyInit()
{	
	var timestamp = Number(new Date());
	var current_mode = getMode(timestamp);
	if (current_mode == "BP") {
		xmlFile = "xml/story_rotator_brick_pro_en.xml";
	}else{
		xmlFile = "xml/story_rotator_en.xml";
	}
	var num_stories = 0;
	var current_story = 0;
	var next_story = 0;
	var pheight = 0;
	$.ajax({
		type: "GET",
		cache: false,
		url: xmlFile,
		dataType: "xml",
		success: function(xml) {
			var i=0;
			$(xml).find('story').each(function(){
											   
				i++;
				var title = $(this).find('title').text();
				var image = $(this).find('image').text();
				var targeturl = $(this).find('targeturl').text();
				var storytext = $(this).find('storytext').text();
				
				
				$('<div id="story-'+i+'" class="stories" style="display:none;"></div>').appendTo('#story-container');
				$('<div id="story-image-'+i+'" class="story-image" style="background:url(/images/hp_images/'+image+') no-repeat;"></div>').appendTo('#story-'+i);
				//$('<div class="trans"></div>').html('<img src="images/trans.gif" height="50" alt="" border="0" />').appendTo('#story-image-'+i);
				
				if (targeturl){
					$('<div id = "st'+i+'" class="story-text"></div>').html('<a href="'+targeturl+'" descript="'+i+'">'+title+'</a><br /><span style="font-size:14px;">'+storytext+'</span>').appendTo('#story-container');
				}else{
					$('<div id = "st'+i+'" class="story-text"></div>').html(title+'<br /><span style="font-size:14px;">'+storytext+'</span>').appendTo('#story-container');
			
				}
				});	
			$('#story-1').fadeIn('slow', function() { });
			$('#st1').show()
			$('<div id = "plat1" class="platformWhite"></div>').appendTo('#story-container');
			$('<div id = "plat2" class="platform"></div>').appendTo('#story-container');
			$('<div id="story-links" class="story-links"></div>').appendTo('#story-container');
			
			num_stories = i;
			current_story = 1;
			next_story = current_story + 1
			
			for ( x=1;x<=i;x++)
			{
				$('#story-links').append('<div class="link-container"><a  linkto="'+x+'">'+x+'</a></div> ');
				
			}
			$('#story-links').append('<div class="clear"></div>');
			
			$('[linkto=1]').parent().addClass('link-containerOn');
			
			jQuery('.story-links a').bind('click', function() {
				clearInterval(start); 
				startRotation(); 
				if (current_story != jQuery(this).attr('linkto'))
				{
					$('#story-' + current_story).fadeOut('slow', function() { });
					$('#story-' + jQuery(this).attr('linkto')).fadeIn('slow', function() { });
					$('#st'+current_story).hide();
					$('#st'+ jQuery(this).attr('linkto')).show();
					jQuery('.story-links a').parent().removeClass('link-containerOn');
					jQuery(this).parent().addClass('link-containerOn');
					current_story=parseInt(jQuery(this).attr('linkto'),10);
					next_story=current_story + 1;
					if (next_story > num_stories) next_story = 1;
				}
			return false;
   			});	
			
		}
	});

	
	
	startRotation = function(){  start = setInterval(function(){ rotate(); }, 7000); };
	
	rotate = function(){
		$('#story-'+current_story).fadeOut('slow', function() {  });
		$('#story-'+next_story).fadeIn('slow', function() { });

		$('#st'+current_story).hide();$('#st'+next_story).show();
		
		current_story++;
		if (current_story > num_stories) current_story = 1;
		//var pheight=0;
			//	pheight = $("#st"+current_story).height();
			//	$("#plat"+current_story).css('height', pheight + 30 + "px");
			//	$("#st"+current_story).css('top', "0px");
				//alert(pheight);
				
		next_story=current_story + 1;
		if (next_story > num_stories) next_story = 1;
		$('[linkto]').parent().removeClass('link-containerOn');
		$('[linkto='+current_story+']').parent().addClass('link-containerOn');
	};
	
startRotation();
}
