
function RotationWithImagesJSWidget() {

    this.width=200;
	this.height=200;
	this.alternate="Yes";
	this.image_width=100;
	this.title_size=14;
	this.title_color="000000";
	this.text_size=11;
	this.text_color="000000";
	this.background="FFFFFF";
	this.border="CCCCCC";
	this.feed="";
	this.div_name="";
	this.padding=4;
	this.scroll_width=17;
	this.link_color="000000";
	this.pagenate_height=20;
	this.auto_on=1;
	this.call_on=0;
	this.delay=5000;
	this.current_page=1;
	this.pages=0;

    this.draw = function () {
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			this.scroll_width=19;
		}
		if(this.title_color==""){
			this.title_color="000000";
		}
		if(this.text_color==""){
			this.text_color="000000";
		}
		if(this.link_color==""){
			this.link_color="0000FF";
		}
		document.write('<div id="' + this.div_name + '_output"></div>');
		PrepSN_Bridge_Draw(this.div_name,this.feed,this.div_name + ".checker();",this.div_name + ".sendBack([RESULT]);");
    };
	this.checker = function (){
		return true;
	}
	this.sendBack = function ( the_xml ){

		try{ //Internet Explorer
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML( the_xml );
		}catch(e){
			try{ //Firefox, Mozilla, Opera, etc.
		
				parser=new DOMParser();
				xmlDoc=parser.parseFromString( the_xml ,"text/xml");
			}catch(e){
				alert(e.message);
				return;
			}
		}
		var len = xmlDoc.getElementsByTagName("item").length;

		var output="";

		output += '<div style="width:' + this.width + 'px;height:' + this.height + 'px;';
		if(this.border!=""){
			output += 'border:1px solid #' + this.border + ';';
		}
		if(this.background!=""){
			output += 'background:#' + this.background + ';';
		}
		output += 'overflow:hidden;" align=left>';
		
		this.pages=len;

		for(i=1;i<=len;i++){

			output += '<table ID="' + this.div_name + '_story' + i + '" cellspacing="0" cellpadding="0" style="';
			
			if( i > 1 ){ output += 'display:none;'; }

			output += 'height:' + this.height + 'px;">';

			var fetch=i;
			
			var media = xmlDoc.getElementsByTagName("item")[fetch-1];

			var vals = new Array();
			if(typeof(media.getElementsByTagName("title")[0].textContent)!="undefined"){
				vals["title"]=media.getElementsByTagName("title")[0].textContent;
				vals["description"]=media.getElementsByTagName("description")[0].textContent;
				vals["link"]=media.getElementsByTagName("link")[0].textContent;
				vals["pubDate"]=media.getElementsByTagName("pubDate")[0].textContent;
				vals["image"]=media.getElementsByTagName("image")[0].textContent;
			}else{
				vals["title"]=media.getElementsByTagName("title")[0].firstChild.nodeValue;
				vals["description"]=media.getElementsByTagName("description")[0].firstChild.nodeValue;
				vals["link"]=media.getElementsByTagName("link")[0].firstChild.nodeValue;
				vals["pubDate"]=media.getElementsByTagName("pubDate")[0].firstChild.nodeValue;
				vals["image"]=media.getElementsByTagName("image")[0].firstChild.nodeValue;
			}
			temp=vals["pubDate"].split(" ");
			month="";
			day="";
			try{
				month=temp[2];
				day=parseInt(temp[1],10);
			}catch(e){

			}

			

			var a1='<a href="' + vals['link'] + '" style="background:none;text-decoration:none;font-family:arial;font-weight:bold;font-size:' + this.title_size + 'px;color:#' + this.title_color + ';">';
			var a2='<a href="' + vals['link'] + '" style="background:none;text-decoration:none;font-family:arial;font-weight:none;font-size:' + this.text_size + 'px;color:#' + this.text_color + ';">';
			

			output += '<tr>';
				var title_height = Math.ceil(this.title_size  * 2.3);
				var text_height = this.height - title_height - 2 * this.padding  - this.pagenate_height;

				if(this.alternate==0 || i%2==0){
					padding2="padding:" + this.padding + "px;";
					padding1="padding:" + this.padding + "px;padding-left:0px;";
				}else{
					padding1="padding:" + this.padding + "px;";
					padding2="padding:" + this.padding + "px;padding-left:0px;";
				}

				var cell1='<td style="width:' + ( this.width - this.image_width ) + 'px;' + padding1 + '" valign=top>';
				cell1 += '<div style="overflow:hidden;width:' + ( this.width - this.image_width - 3 * this.padding ) + 'px;height:' + title_height + 'px">' + a1 + vals["title"] + '</a></div>';
				cell1 += '<div style="overflow:hidden;width:' + ( this.width - this.image_width - 3 * this.padding ) + 'px;height:' + text_height + 'px">' + a2 + month + ' ' + day + ' - ' + vals["description"] + '</a></div>';
				
				cell1 +="<div align=center style='padding-top:" + this.padding + "px;overflow:hidden;width:" +  ( this.width - this.image_width - 3 * this.padding ) + "px;height:" + (this.pagenate_height) + "px;'>";
				cell1 +="<table cellspacing=0 cellpadding=0>";
				cell1 +="<tr>";
				cell1 +="<td nowrap style='padding-right:20px;'><a href='javascript:void(0);' onClick='javascript:" + this.div_name + ".changePage(-1,0)' style='background:none;font-weight:bold;font-family:arial;font-size:11px;color:#" + this.link_color + ";text-decoration:none;'>&laquo; Prev</a></td>";
				cell1 +="<td nowrap style='font-size:11px;font-family:arial;color:#" + this.text_color + ";'>";
				cell1 +="<span ID='" + this.div_name + "_" + i + "_pagenum'>1</span> / " + len;
				
				cell1 += " | <a href='javascript:void(0);' onClick='javascript:" + this.div_name + ".changePage(0)' style='background:none;font-weight:bold;font-family:arial;font-size:11px;color:#" + this.link_color + ";text-decoration:none;'><span ID='" + this.div_name + "_" + i + "_play'>Pause</span></a>";
				
				cell1 +="</td>";
				cell1 +="<td nowrap style='padding-left:20px;'><a href='javascript:void(0);' onClick='javascript:" + this.div_name + ".changePage(1,0)' style='background:none;font-weight:bold;font-family:arial;font-size:11px;color:#" + this.link_color + ";text-decoration:none;'>Next &raquo;</a></td>";
				cell1 +="</tr>";
				cell1 += "</table>";
				cell1 +="</div>";

				cell1 += '</td>';
				var cell2='<td style="width:' + ( this.image_width ) + 'px;' + padding2 + '" valign=top align=center>' + a1 + '<img border=0 src="' + vals['image'] + '&w=' + this.image_width + '&h=' + ( this.height - 2 * this.padding ) + '"></a></td>';
			
			

			if(this.alternate==0 || i%2==0){
				output += cell2 + "" + cell1;
			}else{
				output += cell1 + "" + cell2;
			}

			output += '</tr>';
			output += '</table>';
		}

		output += '</div>';

		document.getElementById(this.div_name + "_output").innerHTML=output;

		setTimeout(this.div_name + ".changePage(1,1);",this.delay);
		this.auto_on=1;
		this.call_on=1;
	
	}

	this.changePage = function (dir,auto){
		try{
			if(auto==1){
				this.call_on=0;
			}
			if(dir==0){
				if(this.auto_on==0){
					this.auto_on=1;
					if(this.call_on==0){
						this.call_on=1;
						setTimeout(this.div_name + ".changePage(1,1);",this.delay);
					}
					document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Pause";
				}else{
					this.auto_on=0;
					document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Play";
				}
			}else{
				if(auto==1 && this.auto_on==0){

				}else{
					if(auto==0){
						this.auto_on=0;
						document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Play";
					}else{
						this.auto_on=1;
						document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Pause";
					}
					if(this.pages > 1){
						var new_page=0;
						if(dir==1){
							new_page=this.current_page + 1;	
							if(new_page > this.pages){
								new_page=1;
							}
						}else if(dir==-1){
							new_page=this.current_page - 1;
							if(new_page==0){
								new_page=this.pages;
							}
						}
						document.getElementById(this.div_name + "_story" + this.current_page).style.display="none";
						this.current_page=new_page;
						document.getElementById(this.div_name + "_" + this.current_page + "_pagenum").innerHTML=this.current_page;
						document.getElementById(this.div_name + "_story" + this.current_page).style.display="";

						if(auto==0){
							this.auto_on=0;
							document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Play";
						}else{
							this.auto_on=1;
							document.getElementById(this.div_name + "_" + this.current_page + "_play").innerHTML="Pause";
						}

						if(this.auto_on==1){
							if(this.call_on==0){
								this.call_on=1;
								setTimeout(this.div_name + ".changePage(1,1);",this.delay);
							}
						}
					}else{
						if(this.auto_on==1){
							this.auto_on=0;
						}
					}
				}
			}
		}catch(e){
			this.auto_on=0;
		}
	}
}
