$(document).ready(function()
{
	startRotator();
});
function startRotator()
{

	 $.ajaxSetup ({  
         cache: false,
		 error:function(x,e){
			if(x.status==0){
			 $("#jbRotator").append('You are offline!!\n Please Check Your Network.');
			}else if(x.status==404){
			 $("#jbRotator").append('Requested URL not found.');
			}else if(x.status==500){
			 $("#jbRotator").append('Internel Server Error.');
			}else if(e=='parsererror'){
			 $("#jbRotator").append('Error.\nParsing JSON Request failed.');
			}else if(e=='timeout'){
			 $("#jbRotator").append('Request Time out.');
			}else {
			 $("#jbRotator").append('Unknow Error.\n'+x.responseText);
			}
		}

    }); 
	
	$.ajax({
		type: "GET",
		url: xmlpath,
		dataType: "text",
		success: function(data) { 
		
			var xml;
			if ( $.browser.msie ) {
			xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.async = false;
			xml.loadXML(data);
			} else {
			xml = data;
			}
		
		parseXml(xml); }
	
		
	  });






	function parseXml(xml)
	{
		var i= 0;
		var spacing = 2;
		
		///set hieght of div
		$("#jbRotator").height(imageHeight);
		
	   $(xml).find("banners").each(function()
	  {
	
		  
		  $(this).find("jpg").each(function()
			{									 
		  
				i++;
				
			});
		  
	
		  
	  });
	 
	 
	  var thumbWidth = Math.round((imageWidth - ((i-1)*spacing))/i);
	 
	  $(xml).find("banners").each(function()
	  {
		  $("#jbRotator").append('<div id="slideshowR" class="pics"></div><ul id="navR"></ul>');
		  var k = 0;
		  $(this).find("jpg").each(function()
			{									 
		  		k++;
				var myt = "<div>";
				
				
				
				
				if ($(this).attr('head').length >2){
					myt +="<span class='rotatorheader'>"+ $(this).attr('head') + "</span><span class='rotatordesc'>"+ $(this).attr('desc') + "</span>";
				}
				
				
				
				myt +="<a href='"+$(this).attr("link")+"' target='_parent'><img src='"+$(this).attr("image")+"' width='"+imageWidth+"' height='"+imageHeight+"'/></a></div>";
				
				$('#slideshowR').append(myt);
				
				
				
					$("#navR").append("<li class='tRight'><a href='#'></a></li>"  );	
				
				
				
			});
		  
		  
		
		  
	  });
	
	 
	 $("#jbRotator").append('<style type="text/css">body{ margin:0;padding:0;}'
						+'#jbRotator{width:'+imageWidth+'px;overflow:hidden; font-size:15px;color:#fff;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}'
						 +'#jbRotator #navR { position:absolute;top:'+(imageHeight - 40)+'px;right:20px; white-space: nowrap;z-index:999999 }'
						 +'#jbRotator #navR li { width: 27px; margin-top:2px;float: left !important; list-style: none;padding:0; }'
						 +'#jbRotator #navR li a { width: 27px; height:25px;  background:url("/Pics/custom/rotatorDots.png");  display: block; }'
						 +'#jbRotator #navR li a img{filter:alpha(opacity=50);opacity:.50;}'
						 +'#jbRotator #navR li.activeSlide a{ background: url("/Pics/custom/rotatorDots.png") 0 -24px; }'
						 +'#jbRotator #navR li a:focus img { outline: none; }'
						 +'#jbRotator img { border: none; }'
						 +'#navR .tRight{margin-left:3px;}'
						 +'#jbRotator ul {margin:0px;padding:0px;}'
						 +'#jbRotator{position:relative;}'
						 +'#jbRotator .rotatorheader{position:absolute;top:190px;z-index:99999;background:#da0000;padding:5px;padding-left:100px;}'
						 +'#jbRotator .rotatordesc{position:absolute;top:230px;z-index:99999;background:#da0000;padding:5px;padding-left:150px;}'
						 
						 +'</style>');
	 
	 
	 
	 
	 
	 
	 
	 
	  $('#slideshowR').cycle({
        fx:     transition,
        speed:  'slow',
        timeout: rotateSpeed+'000',
        pager:  '#navR',
    	cleartypeNoBg:  true,
        pagerAnchorBuilder: function(idx, slide) {
        // return selector string for existing anchor
        return '#navR li:eq(' + idx + ') a';
    }

    });
	 
	 
	}

	

}




