//tag cloud function to limit the height of the tags being output
//parentElementId - name of the div containing the tag cloud
//maxHeight - Maximum height of the parent div in px
//tagNum - number of tags expected. If this is larger than the actual number of tags then there will be javascript errors. -AB
function hideTagOverflow(parentElementId, maxHeight, tagNum){
	var overflowFlag = false;
	
	if(tagNum == null)
		tagNum = 60;
		
	for(var tagElementIdx = 0; tagElementIdx < tagNum; tagElementIdx++){		
		var elem = document.getElementById("tag"+tagElementIdx);				
		if(elem != null){
			elem.style.display="inline";
			if(document.getElementById(parentElementId).clientHeight > maxHeight)
				elem.style.display="none";
		}
	}
}

var bugReport = new BugReport;
function BugReport(){};
BugReport.prototype.submitForm = function(form){
	$.post('/bug', {body: encodeURIComponent(form.bugBody.value),uri: window.location.href}, function(data){
		if(data.response){
			document.getElementById('bugReport').innerHTML = data.response;
		} else {
			document.getElementById('bugReport').innerHTML = '<h2>Oops!</h2><div>There was an issue sending your data.  Please check your internet connection and try again.</div>';
		}
		this.fadeoutTimeout = setTimeout('bugReport.togglePopup()',3500);
	}, "json");
	return false;
}
BugReport.prototype.togglePopup = function(){
	if(this.isShown == false || this.isShown == undefined){
		this.isShown = true;
		$('#bugReport').fadeIn("slow");
		
	} else {
		this.isShown = false;
		$('#bugReport').fadeOut("slow");
	}
}

var userPopup = new userPopup;
function userPopup(){};
userPopup.bioBox = function(div, name, user_id, size)
{
	if(this.isShown == false || this.isShown == undefined){
		if(document.getElementById(div).innerHTML==''){
			$.get("/PC_load_letter/userPopup",{name:name, uid:user_id, size:size }, 
				  function(data)
				  {
					  if(data != "false")
					  {
						document.getElementById(div).innerHTML = data;
					  }
					  else
					  {
						alert("User Info Unavailable.");	
					  }
				  }
			);
		}
		this.isShown = true;
		$('#' + div).fadeIn("medium");
	} else {
		this.isShown = false;
		$('#' + div).fadeOut("medium");
	}
}

//function is no longer used
function loadHomeFlash()
{
	$.get("/fmaster/loadHomeFlash",{}, 
		  function(data)
		  {
			  if(data != "false")
			  {
				document.getElementById('main_slideshow').innerHTML = data;
			  }
		  }
	);	
}

//function is no longer used
function loadHomeDvd()
{
	$.get("/fmaster/loadStoreModule",{}, 
		  function(data)
		  {
			  if(data != "false")
			  {
				document.getElementById('dvdFlash').innerHTML = data;
			  }
		  }
	);	
}

function mediaFlashBox(type)
{
	$.get("/fmaster/mediaFlashBox",{ type: type, d: null }, 
		  function(data)
		  {
			  if(data != "false")
			  {
				document.getElementById('flashbox').innerHTML = data;
			  }
		  }
	);	
}

function emailMask(email,domain)
{
	document.write('<a href="mailto:'+email+'@'+domain+'">'+email+'@'+domain+'</a>');	
}

//template toggle onClick
function template_toggle(){
	//post to change $this->session->userdata('color_setting')
	var data = null;
	
	$.post("http://www.brink.com/profile/tpl_color", data, function(data){
		window.location.replace(unescape(window.location.pathname))
	});
	
	//toggle css
	//document.getElementById('template_css').href="/styles/new_style_black.css";
	
	//reload page
	//alert('what?');
	//setTimeout(window.location.replace(unescape(window.location.pathname)), 1000);
	//window.location.replace(unescape(window.location.pathname));
}