

// show/hide help in side bar
//document.write ("<style type='text/css'>#help_info {display: none}</style>");// no js support = help info will show
$( document ).ready( function() { $( "#help_info" ).hide(); } );
function showinfo(currinfo) {// show/hide function
//	if ( document.getElementById ) {
//		thisinfo = document.getElementById( currinfo ).style
//			if (thisinfo.display == "block") {
//				thisinfo.display = "none"
//			} else {
//				thisinfo.display = "block"
//			}
//		return false
//	}
	$( "#currinfo" ).toggle();
}
//sidepanel help_link - IE needed href for text-dec
function underline(help_link) {help_link.style.textDecoration='underline';}
function nounderline(help_link) {help_link.style.textDecoration='none';}
function button_over(butt) {butt.style.textDecoration='underline';}
function button_off(butt) {butt.style.textDecoration='none';}

imgSRC = "/iportfolio/css/default/images/form_buttons/";	

if ( document.images ) {
	next_lrgon = new Image
	next_lrgoff = new Image

	next_lrgon.src = imgSRC + "next_lrg_on.gif"
	next_lrgoff.src = imgSRC + "next_lrg_off.gif"
} else {
	next_lrgton = ""
	next_lrgoff = ""

	document.next_lrgbutton = ""
}

/*
 * Uses `load` in addition to `ready` to avoid an issue with the
 * function executing too early
 */
$( document ).ready( function () {
	initNewWindowLinks();
	initNickNameListener();
//	removeFilterButtons();
});

function initNewWindowLinks () {
	$("a.new_window").each (function (i) {
		// make the link open in a new window
		$(this).click (openInNewWindow);
		/*
		// modify the title attribute
		if (this.title == "") {
			$(this).attr ("title", "This link opens in a new window");
		} else {
			$(this).attr ("title", this.title + " (opens in a new window)");
		}
		*/
	});
}

function openInNewWindow () {
	var newWindow = window.open (this.getAttribute ("href"), "_blank");
	newWindow.focus ();
	return false;
}

function initNickNameListener () {
	// add the change listener to #firstName
	$("#firstName").change (updateNickName);
	// add a change listener to kill the first when #nickName is changed
	$("#nickName").change (removeFirstNameListener);
}

function updateNickName () {
	$("#nickName").set ("value", this.value);
}

function removeFirstNameListener () {
	$("#firstName").unchange (updateNickName);
}

function removeFilterButtons() {
	$("#filterButton").remove();
}

function initDropdownWithOtherWidgets () {
	$("form div.select.other").each (function (i) {
		var select = $(this).find ("select");
		var other = $(this).find ("div.other");
		if (select.get(0).value != -1) {
			other.hide ();
		}
		select.change (function () {
			if (this.value == -1) {
				other.slideDown ("slow");
			} else {
				other.slideUp ("slow");
			}
		});
	});
}

//Start rotating stories for section home pgs ...
function rotator(i,imgTimer,u,n,rotateContainer,mainImg) {
	this.i = i;
	this.imgTimer = imgTimer;
	this.u = u;
	this.n = n;
	this.rotateContainer = rotateContainer;
	this.mainImg = mainImg;
	this.s = "initialising";
	this.c = 0;
	this.dC = 0;
	this.dI;
	this.dR;
	this.rflag = false;
		
	this.init = function(r) {
		this.oX = -999;
		this.oY = -999;
		this.f = Array();
		this.x = 0;
		this.y = 0;
		try {
		this.C = document.getElementById(this.rotateContainer);
		this.p = document.getElementById(this.mainImg);
		if(this.p.offsetparent) {
			var t = this.p;
			while(t.offsetparent) {
				this.x+=t.offsetLeft;this.y+=t.offsetTop;t=t.offsetparent;
			}
		}
		
		var tC = this.C.childNodes;
		for(var i=0;i<=tC.length-1;i++) {
			if(tC[i].nodeType==1) {
				if(tC[i].getAttribute("id").indexOf("news")==0) {
					this.f[this.f.length] = tC[i];
				}
			}
		}
		if(!this.rflag) {
			var tmp = this.f[0].innerHTML;	
			this.c = 0;
		} else {
			var tmp = this.f[this.c].innerHTML;
		}
		
		if(tmp!="") {
			this.p.innerHTML = "<div>"+tmp+"</div>";
		this.buildTools();
		}	
		this.rflag = false;
		} catch(e) { }
	};
	
	this.move = function(f) {
		try {
		if(!f) {
			this.c++;
			(this.c==this.f.length)?this.c=0:this.c;
		} else if(this.mode=="back") {
			this.c--;
			(this.c<0)?this.c = this.f.length-1:this.c;
		} else if(this.mode=="jump") {
			this.c = f-1;
		}
		if(this.f[this.c].innerHTML!="") {
			this.p.innerHTML = "<div>"+this.f[this.c].innerHTML+"</div>";
			this.buildTools();
		}
		} catch(e) {}
	};
	
	this.action = function(action,x) {
		clearTimeout(this.dI);
		if(!action) { action = this.mode; }
		if(this.rflag&&action!="refresh") { this.init(true); }
		switch(action) {
			case "pause":
				this.mode = "pause";
				break;
			case "play":
				this.mode = "play";
				this.move();
				this.rotate();
				break;
			case "back":
				this.mode = "back";
				this.move(true);
				break;			
			case "next":this.mode = "next";
				this.move();
				this.mode = "play";
				this.rotate();break;
			case "jump":
				this.mode= "jump";
				this.move(x);
				break;
			case "refresh":
				this.refresh();
				break;
		}
		return false;
	};
	
	this.rotate = function() {
		this.dI = setTimeout(this.n+".action()",this.i);			
	};
	
	this.refresh = function () {
		try {
		clearTimeout(this.dI);
		if(!this.rflag) {
			this.rflag = true;
		}
		var hash = new Date().getTime();
		this.f[this.c].style.top = this.oY+"px";
		this.f[this.c].style.left = this.oX+"px";
		var req = new genericAjax(this.u+"&hash="+hash,"GET","TEXT",rotatorUpdateDisplay);
		this.dR = setTimeout(this.n+".action('refresh')",this.imgTimer);
		} catch(e) {} 
	};
	
	this.asppImpression = function() {
	}
	
	this.buildTools = function() {
		var s = "<ul><li><a href=\"#\" onclick=\"return "+this.n+".action('back');\">Back</a> <span class=\"bgLight\">&lt;</span> </li><li id=\"rTT\">";
		for(var i=1;i<=this.f.length;i++) {
			if(i==(this.c+1)) { 
			s += "<span>"+i+"</span> "; 
			} 
			else { 
			s += "<a href=\"#\" onclick=\"return "+this.n+".action('jump',"+i+");\">"+i+"</a> "; 
			}
		}
		s += "</li><li> <span class=\"bgLight\">&gt;</span> <a href=\"#\" onclick=\"return "+this.n+".action('next');\">Next</a></li></ul>";
		try {
		document.getElementById("pagingLinks").innerHTML = s;	
		} catch(e) {}
	}

	this.init();this.mode="play";this.rotate();
	this.dR = setTimeout(this.n+".action('refresh')",this.imgTimer);
}


function rotatorUpdateDisplay(content) {
	try {
	var t = document.createElement("div");
	t.innerHTML = content;
	var i = 0;
	while(i<=t.childNodes.length) {
		try {
			if(t.childNodes[i].getAttribute("id")=="sL_p_1") {
				var y = 0;
				while(y<=t.childNodes[i].childNodes.length) {
					try {
						if(t.childNodes[i].childNodes[y].getAttribute("id")=="rotateContainer") {
							var tmp = t.childNodes[i].childNodes[y].innerHTML;
						}
						break;
						
					} catch(e) {}
					y++;				
				}
			break;
			}
		} catch(e) { }
	i++;
	}
	document.getElementById("rotateContainer").innerHTML = tmp;
	if(rotator.mode=="play") { rotator.action('next'); }
		} catch(e) {}
	}
