function PortalUI(){
	
	this.type = "";
	this.over = false;
	this.value = 0;
	this.tab = '';
	this.curid = '';
	
	this.callCommand = function(clink, sublink, subsection, postval, curid){
		this.type = subsection;
		this.tab = postval;
		this.curid = curid;
		startglazer = false;
		clist = 'callAjax_PORTAL/'+clink+'/'+sublink+'/'+subsection+',_'+postval+',_'+curid+'/setportal';
		myTimer.queuePush(clist);
	};
	
	this.callLink = function(clink, sublink, subsection, postval){
		this.type = subsection;
		window.location = "/p/"+clink+"/"+sublink+"/"+subsection+"/"+postval;
	};
	
	this.resize = function(){
		if(openaction)
			actionObj.resize();
	};
	
	this.callSearch = function(clink, sublink, subsection){
		this.type = subsection;
		upost = document.getElementById('search').value;
		upost = upost.replace(/\s/g, '_');
		postval = "None,_Search,_"+upost;
		window.location = "/p/"+clink+"/"+sublink+"/"+subsection+"/"+postval;
	};
	
	this.callImgLink = function(clink, tab, pic){
		if(tab == "Most_Watched") tab = "Most_Viewed"; 
		postval = tab+',_img,_'+pic;
		window.location = "/p/"+clink+"/"+tab+"/Sectionlist/"+postval;
	};
	
	this.newPage = function(url){
		window.location = url;
	};
	
	this.rateContent = function(clink, sublink, subsection, postval, rating, id){
		startglazer = false;
		rating -= 1;
		
		myTimer.queuePush('callAjax_PORTAL/'+clink+'/'+sublink+'/'+subsection+',_'+postval+',_rate,_'+rating+',_'+id+'/setportal');
		alert("rating: "+rating+". id: "+id);
	};
	
	this.openComment = function(signedin, type, loc, cloc, clink){
		wrd = clink.toLowerCase();
		wrd = wrd.substr(0, wrd.length -1);
		if(!signedin){
			alert("You must Sign in or Create an Account to post a comment on this "+wrd);
		}
		else if(loc != cloc && loc != ""){
			alert("You must be part of the "+loc+" network to comment on this "+wrd);	
		}
		else{
			obj = document.getElementById(type).style;
			if(obj.display == "none")
				obj.display = "block";
		}
		
	};
	
	this.resetSearch = function(obj){
		val = obj.value;
		if(val == "Search")
			obj.value = "";
	};
	
	this.setFlashPlayer = function(){
		flowplayer("player", "/UI/flash/flowplayer-3.1.0.swf",  { 
			clip: { 
			autoPlay: false, 
			autoBuffering: true
			} 
		}); 
	};
	
	this.initPage = function(type){
		switch(type){
			case "PhotoViewer": 
				stoptheload(); 
				this.over = false; 
				this.resetOver(this.value); 
			break;
			case "VideoViewer": 
				if(this.tab != "Tools")
					this.setFlashPlayer(); 
			break;
			case "StatInfo":
				vals = this.curid.split(',_');
				left = vals[vals.length-1]/1;
				cobj = document.getElementById('col_0');
				if(cobj != null)
					cobj.style.width = (cobj.offsetWidth+20)+'px';
				obj = document.getElementById('col_'+left);
				while(obj != null){
					left ++;
					obj.style.width = (obj.offsetWidth+1)+'px';
					obj = document.getElementById('col_'+left);
				}
			break;
		}
	};
	
	this.interpret = function(){
		stoptheload();
		myLarge.removeGlaze();
		switch(this.type){
			case "": break;
			case "logout": this.signout(); break;
			default:
				document.getElementById('main_'+this.type).innerHTML = req.responseText;
				this.initPage(this.type);
			break;
		}
		this.type = "";
	};
	
	this.selectSeason = function(obj, clink, sublink, subsection){
		this.type = subsection;
		val = obj.options[obj.selectedIndex].value;
		val = val.replace(/\s/, '_');
		postval = "None,_Season,_"+val;
		window.location = "/p/"+clink+"/"+sublink+"/"+subsection+"/"+postval;
	};
	
	this.openApp = function(url){
		window.location = '/'+url;
	};
	
	this.openUrl = function(url){
		window.location = url;
	};
	
	this.signout = function(clink, sublink){
		deleteCookie('cde_u_1x8_l');
		deleteCookie('cderu_0_1xx0x');
		deleteCookie('enter');
		newwindow=window.open('/app', 'ldwin');
		window.location = "/p/"+clink+'/'+sublink;
	};
	
	this.resetContent = function(defcontent, node){
		obj = document.getElementById(node);
		if(obj.value == defcontent){
			obj.innerHTML = "";
			obj.value = "";
			obj.style.color = "#000";
		}
	};
	
	this.deleteCookie = function(cookie_name){
		var cookie_date = new Date();  
		cookie_date.setTime(cookie_date.getTime() - 1);
		document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	}
	
	this.rateContent = function(signedin, loc, cloc, clink, sublink, subsection, postval, rating, id){
		wrd = clink.toLowerCase();
		wrd = wrd.substr(0, wrd.length -1);
		if(!signedin){
			alert("You must Sign in or Create an Account to rate this "+wrd);
		}
		else if(loc != cloc && loc != ""){
			alert("You must be part of the "+loc+" network to rate this "+wrd);	
		}
		else{
			this.type = subsection;
			startglazer = false;	
			this.value = rating;
			if(postval == "") postval = "none"
			this.over = false; 
			this.resetOver(rating);
			alert("You rated this "+wrd+" "+rating+" stars.");
			params.commandlist = ('callAjax_PORTAL/'+clink+'/'+sublink+'/'+subsection+',_'+postval+',_'+id+'/setportal');
			myTimer.queuePush('callAjax_PORTAL/'+clink+'/frate/'+id+',_'+(rating)+',_'+clink+'/callcommandlist');
		}
	};
	
	this.submitBlogComment = function(clink, sublink, subsection, type, id, defcontent, node, obj){
		content = document.getElementById(node).value;
		if(content != "" && content != defcontent){
			obj.disabled = true;
			params.commandlist = 'callAjax_PORTAL/'+clink+'/'+sublink+'/'+subsection+',_'+type+',_'+id+'/setportal';
			this.type = subsection;
			startglazer = false;
			url = "/postublog.php?type=portalcomment&uid="+id+"&cid="+id+"&prm=HOME&cuser=";
			uform = document.getElementById("comment_form");
			uform.action = url;
			uform.submit();
		}
		else{
			alert("No content was entered. ");	
		}
	};
	
	this.submitComment = function(clink, sublink, subsection, type, id, defcontent, node, obj){
		content = document.getElementById(node).value;
		content = content.replace(/,_/g, ', ');
		if(content != "" && content != defcontent){
			obj.disabled = true;
			params.commandlist = 'callAjax_PORTAL/'+clink+'/'+sublink+'/'+subsection+',_'+type+',_'+id+'/setportal';
			this.type = subsection;
			startglazer = false;
			myTimer.queuePush('callAjax_PORTAL/'+clink+'/fcomment/'+id+',_'+content+',_'+clink+'/callcommandlist');
		}
		else{
			alert("No content was entered. ");	
		}
	};
	
	this.setOver = function(c){
		this.over = true;
		for(x = 1; x <= 5; x++){
			cobj = document.getElementById('stars_'+x);
			cimg = cobj.style;
			if(x <= c) cimg.backgroundImage = "url('http://s3.amazonaws.com/ldimages/grey-star_over.gif')"; 
			else cimg.backgroundImage = "url('http://s3.amazonaws.com/ldimages/grey-star.gif')";
		}
		
	};
	
	this.callResetOver = function(def){
		this.over = false;
		stoptheload();
		myTimer.queuePush('resetrating_'+def);
	};
	
	this.resetOver = function(def){
		if(!this.over)
			this.setOver(def/1);	
	};
	
	this.callAdmn = function(clink, sublink, id, subsection, cmdtype, obj){
		
		switch(cmdtype){
			case "Addimg":
				hrs = document.getElementById('video_hr').value;
				mins = document.getElementById('video_min').value;
				secs = document.getElementById('video_sec').value;
				process_hrs = (hrs != "" && hrs != "HR" && validate.validNumber(hrs));
				process_mins = (mins != "" && mins != "MIN" && validate.validNumber(mins));
				process_secs = (secs != "" && secs != "SEC" && validate.validNumber(secs));
				if(process_hrs && process_mins && process_secs){
					obj.disabled = true;
					this.type = subsection;
					startglazer = false;
					cselect = document.getElementById('video_tab');
					selectval = cselect.options[cselect.selectedIndex].value;
					params.commandlist = ('callAjax_PORTAL/'+clink+'/'+sublink+'/VideoViewer,_Tools,_'+id+'/setportal');
					myTimer.queuePush('callAjax_PORTAL/'+clink+'/modifyfrontpage/add,_'+hrs+',_'+mins+',_'+secs+',_'+id+',_'+selectval+'/callcommandlist');
				}
				else{
					alert("You have not entered a valid time");	
				}
			break;
		}
	};
	
	this.resetPage = function(){
		if(openaction && !actionObj.onaction){
			actionObj.removeObj();
		}
	};
	
	this.init = function(){
		myTimer.init();
		if (typeof window.addEventListener != 'undefined'){
			window.addEventListener("click", portalUI.resetPage, false); 
		}
		else if (typeof document.addEventListener != 'undefined'){
			document.addEventListener("click", portalUI.resetPage, false); 
		}
		else if (typeof window.attachEvent != 'undefined'){
			document.onclick = portalUI.resetPage;  
		}
	};
}

var portalUI = new PortalUI();