(function(){
GupShup.html.dynamicBar = GupShup.html.dynamicBar || {

updateURL : GupShup.conf.contextPath + "/dynamicJsp",

COL_CONTAINER_SUFFIX : "-col",

DYNAMIC_JS_CONTAINER_PREFIX : "dynamicScriptDiv_",

updateTransaction : null,

update : function(prevPage, nextPage, currOrientation, newPageParams, prevParentPage, nextParentPage) {
	var obj = this;
	if (GupShup.util.isInitialized(obj.updateTransaction))
		return false;
	var params = '';	
	if(typeof newPageParams == 'object')
	{
		params = GupShup.util.getQueryStringFromObject(newPageParams,'~','`');
	}	
	if (typeof prevParentPage == "undefined")
		prevParentPage = "";
	if (typeof nextParentPage == "undefined")
		nextParentPage = "";
			
	var qStr = "newPage=" + nextPage + "&newParentPage=" + nextParentPage + "&oldPage=" + prevPage + "&oldParentPage=" + prevParentPage + "&orientation=" + currOrientation + '&newPageParams=' + params + "&withinPage=true";
	var callBack = {
	success: function(o){obj.dynamicBarUpdateSuccess(o,obj)},
	failure: function(o){obj.dynamicBarUpdateFail(o,obj)},
	argument: {oldPage : prevPage, newPage : nextPage, oldParentPage : prevParentPage, newParentPage : nextParentPage, orientation : currOrientation}
	};
	
	obj.updateTransaction = GupShup.ajax.send('GET', this.updateURL + "?" + qStr, callBack, 'DYNAMICBAR');
	return true;
},

abortUpdate : function() {
	if (GupShup.util.isInitialized(this.updateTransaction))
	{
		try
		{
			this.updateTransaction.abort();
		}
		catch (error)
		{
			if (GupShup.conf.jsDebug)
				alert("Could not abort dynamic bar update : error-" + error);
		}
		
		this.updateTransaction = null;
	}
},

dynamicBarUpdateSuccess : function(o,obj) {
		var content = o.responseText;
		//put content in dynamicBar
		if (obj.needForUpdate(content))
		{
			obj.exapand(content, o.argument.orientation);		
		}
		obj.updateTransaction = null;
},

dynamicBarUpdateFail : function(o,obj) {
	obj.updateTransaction = null;
	
	if (GupShup.conf.jsDebug)
		alert("Could not update dynamic bar for: oldPage-" + o.argument.oldPage + ", newPage-"  + o.argument.newPage + ", ori-"  + o.argument.orientation + ", httpStatus-" + o.status);
},

needForUpdate : function(content) {
	if (GupShup.util.trim(content).length < 1)
		return false;
	else
		return true;
},

exapand : function(innerHTML, orientation) {
	var ele = document.getElementById(orientation.toLowerCase() + this.COL_CONTAINER_SUFFIX);
	if (typeof ele != 'undefined')
		ele.innerHTML = GupShup.util.trim(innerHTML);		
}
}
})();