//Will be set to 1 if they report a site
var has_canceled = 0;
var doc = false;
var docTitle = 'Start Page';
function confirmExit()
{
	has_canceled = 1;
	return "You're either done surfing for the time being or this site tried to halt your session.";
} 
function ajax_start()
{
	var XMLHttpRequestObject = false; 
	if (window.XMLHttpRequest)
	{
		XMLHttpRequestObject = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		XMLHttpRequestObject = new ActiveXObject('Microsoft.XMLHTTP');
	}	
	return XMLHttpRequestObject;
}
function display_ajax_html(page, args, div_id, XMLHttpRequestObject, callback, callback_args)
{
	if(XMLHttpRequestObject)
	{
		var params = args;

		XMLHttpRequestObject.open('POST', '/ajax.php?do='+page, true); 
		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		XMLHttpRequestObject.onreadystatechange = function() 
			{ 
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
					{ 
						if(callback)
							callback(XMLHttpRequestObject.responseText, callback_args);
						else
							doc.getElementById(div_id).innerHTML = XMLHttpRequestObject.responseText;

					} 
			} 
		XMLHttpRequestObject.send(params); 
	}
}
function report_site()
{
	var answer = confirm('Are you certain you want to report this site?');
	if(answer)
	{
		//Grab site
		var site = doc.getElementById('site_id').innerHTML;
		//Report
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('report', '&site='+site, '', XMLHttpRequestObject, do_nothing);	
		doc.getElementById('report_site').innerHTML = "<span class='link_button'>Reported</span>";
		//Update iframe size
		update_size();
	}
}
function vote(type)
{
	doc.getElementById('vote_area').innerHTML = "<span style='margin-left: 5px;'><img src='/images/thumb_"+type+".png' style='border:0px;' /></span>";
	var site_id = doc.getElementById('site_id').innerHTML;
	//Approve site
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('vote_site', '&site='+site_id+'&vote='+type, '', XMLHttpRequestObject, do_nothing);
	parent.tooltip.hide();
	//Update iframe size
	update_size();	
}
function about()
{
	if(doc.getElementById('show_name').style.display != 'none')
	{
		//Update size
		//doc.getElementById('about').style.width = '500px';
		//doc.getElementById('about').style.height = '75px';
		doc.getElementById('about_text').style.display = 'block';
		doc.getElementById('about_text').style.width = '';
		doc.getElementById('show_name').style.display = 'none';
		doc.getElementById('hide_name').style.display = 'inline';
	}
	else //If big, hide
	{
		//Update size
		doc.getElementById('surf_bar_inner').style.minWidth = '160px';
		doc.getElementById('about').style.minWidth = '160px';
		doc.getElementById('about').style.minHeight = '';
		doc.getElementById('about_text').style.display = 'none';
		doc.getElementById('show_name').style.display = 'inline';
		doc.getElementById('hide_name').style.display = 'none';	
	}
	//Update iframe size
	update_size();
}
function bonus_counter(count)
{
	var new_count = count-1;
	if(new_count == 0)
	{
		//They weren't quick enough, don't give credits, but update bonus count
		give_bonus(false);
	}
	else
	{
        document.getElementById('bonus_counter').innerHTML = new_count;
		var delay = function() { bonus_counter(new_count); };
		var bonus_timeout = setTimeout(delay, 2000);
	}
}
function update_counter(count, validate)
{
	var new_count = count-1;
	if(new_count == 0)
	{
		//Validation page, passed
		if(validate)
		{
			var site = doc.getElementById('site_id').innerHTML;
			//Approve site
			XMLHttpRequestObject = ajax_start();
			display_ajax_html('approve_site', '&site='+site, '', XMLHttpRequestObject, load_members);				
		}
		else
		{		
			//Set to "loading"
			document.title = 'Thumbvu Surf - '+docTitle;
       		document.getElementById('counter').innerHTML = '<img src="/images/surf_load.gif" alt="0"/>';
			//Grab the thumbs
			grab_thumbnails(0, false);
			
			//Report current site for breaking frames if 1
			if(has_canceled == 1)
			{
				//Grab site
				var site = doc.getElementById('site_id').innerHTML;
				//Report
				XMLHttpRequestObject = ajax_start();
				display_ajax_html('report', '&site='+site+'&framebreak=1', '', XMLHttpRequestObject, do_nothing);		
				has_canceled = 0;			
			}
		}
	}
	else
	{
		document.title = 'Thumbvu Surf - '+docTitle+' - '+new_count;
        document.getElementById('counter').innerHTML = new_count;
		var delay = function() { update_counter(new_count, validate); };
		setTimeout(delay, 1000);
	}
		
}
function load_members()
{
	window.location = 'sites';
}
function grab_thumbnails(times, success)
{
	if(times > 0)
		//Load img for More area
		doc.getElementById('next').innerHTML = "<img src='/images/surf_load.gif' alt='loading'/>";
	//Don't let em do more than 4 times
	if(times <5)
	{
		//If they clicked on a site check
		if(success)
			var extra = "&check=true";
		else
			var extra = "";
		//Grab thumbnails
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('get_new_thumbs', '&times='+times+extra, '', XMLHttpRequestObject, update_thumbs, times);
	}
}
function update_thumbs(json, times)
{
	if(times == 0)
	{
		//Only on first load
		//show/hide link
		document.getElementById('counter').innerHTML = "<a href='#' onclick='parent.minimize();' class='link_button' style='background-color:#111111;'>Hide</a>";
		//Update size
		doc.getElementById('surf_bar_inner').style.minWidth = '655px';
		doc.getElementById('about').style.minWidth = '655px';
		doc.getElementById('about_text').style.width = '655px';
		doc.getElementById('pic_social').style.maxWidth = '300px';
		if(doc.getElementById('listad'))
			doc.getElementById('listad').style.clear = 'none';
		doc.getElementById('surf_bar_inner').style.minHeight = '190px';
	}
	doc.getElementById('thumbs').style.display = 'block';
	doc.getElementById('thumbs').innerHTML = json;
	
	//Show logo
	doc.getElementById('surf_logo').style.display = 'block';
		
	//Show new window button
	doc.getElementById('new_window').style.display = 'inline';
	
	//Put the credit info
	document.getElementById('credit_info').style.display = 'inline';
	doc.getElementById('vote_area').style.display = 'inline';
	document.getElementById('user_info').style.display = 'none';
	//Update iframe size
	update_size();
}
function next_page(campaign_id)
{
	//Loading image
	doc.getElementById('thumb_'+campaign_id).innerHTML = "<img src='/images/new_thumb.gif' alt='loading...' />";
	if(campaign_id < 3)
	{
		//Bot check
		if(campaign_id == 0)
		{
			//Good
			grab_thumbnails(0, true);
		}
		else
		{
			//Bad
			//Log error
			XMLHttpRequestObject = ajax_start();
			display_ajax_html('log_error', '', '', XMLHttpRequestObject, do_nothing);
		}
	}	
	else
	{
		//Update credits and get new url/other user social stuff
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('get_new_info', '&campaign_id='+campaign_id, '', XMLHttpRequestObject, output_next_page);
	}

	$("#DivIdTextbox").show();
	$("#DivIdSurfChat").hide();	

}
function give_bonus(late)
{
	//too slow
	if(late)
		var extra = '&late=true';
	else
		var extra = '';
	//Add the credits
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('bonus', extra, '', XMLHttpRequestObject, add_credits);
	if(document.getElementById('bonus_bar').style.display != 'none')
	{
		$("#bonus_bar").hide("explode");
		clearTimeout(bonus_timeout);
	}
}
function add_credits(json)
{
	document.getElementById('user_info').innerHTML = json;
	document.getElementById('user_info1').innerHTML = json;
}
function output_next_page(responseText)
{
	var json_array = eval('(' + responseText + ')');
	//New site stuff
	docTitle = json_array['site_name'];
	document.title = 'Thumbvu Surf - '+docTitle+' - 10';
	document.title = 'Thumbvu Surf - '+docTitle;
	document.getElementById('top_frame').src = json_array['url'];
	doc.getElementById('new_window_a').href = json_array['url'];
	doc.getElementById('about_user_id').innerHTML = json_array['user_id'];
	doc.getElementById('site_id').innerHTML = json_array['site_id'];
	
	//Bonus
	if(json_array['bonus'] <= 0)
	{
		document.getElementById('bonus_bar').style.display = 'block';
		document.getElementById('bonus_bar_inner').innerHTML = "<a href='#' onclick='give_bonus(false);'><span id='bonus_counter'>9</span> You've earned "+json_array['bonus_amount']+" credits!  Click to close.</a>";	
		//Start countdown
		bonus_counter(9);
	}
		
	document.getElementById('sessionsurfs').innerHTML = parseInt(document.getElementById('sessionsurfs').innerHTML)+1;
	document.getElementById('bonus_pages').innerHTML = json_array['bonus'];
	document.getElementById('nerd_surf').innerHTML = json_array['nerdsurf'];
	
	//Update credit count
	document.getElementById('user_info').innerHTML = json_array['user_info'];
	document.getElementById('user_info1').innerHTML = json_array['user_info'];
	
 	doc.getElementById('surf_bar_inner').style.minWidth = doc.getElementById('surf_bar_inner').offsetWidth+1+'px';

	//Update other user social stuff
	doc.getElementById('surf_name').innerHTML = json_array['name'];
	var new_text = "<div style='float:left;font-weight:bold;'>"+json_array['name']+'</div><div style="clear:both;float:left;">'+json_array['rating']+'</div><div style="float: left;clear:both;" id="pic_social">';
	if(json_array['pic'])
		new_text += "<span style='float:left;margin-bottom:5px;'>"+json_array['pic']+"</span>";
	new_text += "<span style='float:left;' id='social_icons'>";

	/* IMLOOP INTEGRATION */
	if(json_array['imloop'] != '' && json_array['imloop'] != null)
	{
		if( json_array['friends'] == 'f' )
			new_text += "<a href='javascript: void( 0 );' onclick=\"parent.im_add_friend('" + json_array['imloop'] + "');\" class='icon_light' title='Add as friend'><img src='/images/icons/im_32.png' style='border:0px;' /></a> ";
		else
			new_text += "<a href='http://imloop.com/#!/" + json_array['imloop'] + "' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/im_32.png' style='border:0px;' /></a> ";
	}
	/* END IMLOOP INTEGRATION */
	
	if(json_array['twitter'] != '' && json_array['twitter'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/twitter' rel='external' target='_BLANK'><img src='/images/icons/twitter_32.png' style='border:0px;' /></a> ";
	if(json_array['facebook'] != '' && json_array['facebook'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/facebook' rel='external' target='_BLANK'><img src='/images/icons/facebook_32.png' style='border:0px;' /></a> ";
	if(json_array['youtube'] != '' && json_array['yahoo'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/youtube' rel='external' target='_BLANK'><img src='/images/icons/youtube_32.png' style='border:0px;' /></a> ";
	if(json_array['blog'] != '' && json_array['blog'] != null)
		new_text += "<a href='"+json_array['blog']+"' rel='external' target='_BLANK'><img src='/images/icons/rss_32.png' style='border:0px;' /></a> ";
	//upgraded sites array
	var sites_array = new Array("digg", "linkedin", "blogger", "flickr", "tumblr", "email", "yahoobuzz", "myspace", "vimeo", "orkut", "stumbleupon", "picasa", "friendfeed", "lastfm", "skype", "aim", "google");
	for(var site in sites_array)	
	{
		if(json_array[sites_array[site]] != '' && json_array[sites_array[site]] != null)
			new_text += "<a href='"+json_array[sites_array[site]]+"' rel='external' target='_BLANK'><img src='/images/icons/"+sites_array[site]+"_32.png' style='border:0px;' /></a> ";	
	}
	new_text += "</span></div>";
	if(json_array['listad'] == 'true')
		new_text += "<div id='listad'>"+json_array['listad_header']+"<br />"+json_array['listad_html']+"</div>";
	//If they don't have anything at all...
	if(new_text == "<span style='float:left;'>"+json_array['name']+'</span><span style="float: left;margin-left:15px;"></span>')
		new_text += '<span style="float: left;margin-left:15px;"> doesn\'t have any profile information entered.</span>';
	doc.getElementById('about_text').innerHTML = new_text;
	if(json_array['listad'] == 'true')
	{
		//Fill in name and email
		var fill_name = doc.getElementsByName('name');
		var fill_fullname = doc.getElementsByName('fullname');
		var fill_email = doc.getElementsByName('email');
		if(fill_name.length > 0)
			fill_name[0].value = json_array['surfer_name'];
		if(fill_fullname.length > 0)
			fill_fullname[0].value = json_array['surfer_name'];
		if(fill_email.length > 0)
			fill_email[0].value = json_array['surfer_email'];
	}
	doc.getElementById('surf_bar_inner').style.minWidth = '160px';
	doc.getElementById('about').style.minWidth = '160px';
	doc.getElementById('pic_social').style.maxWidth = '160px';
	if(doc.getElementById('listad'))
		doc.getElementById('listad').style.clear = 'left';
	doc.getElementById('about_text').style.width = '';
	doc.getElementById('surf_bar_inner').style.minHeight = '15px';
	
	//Hide logo
	doc.getElementById('surf_logo').style.display = 'none';
	
	//Hide new window button
	doc.getElementById('new_window').style.display = 'none';

	doc.getElementById('thumbs').style.display = 'none';
	document.getElementById('counter').innerHTML = 10;

	//Update reported link
	doc.getElementById('report_site').innerHTML = "<a href='#' onclick='parent.report_site();' class='link_button'>Report</a>";
	
	//Update thumbs area
	if(!json_array['vote'])
		doc.getElementById('vote_area').innerHTML = "<span><a href='#' onclick=\"parent.vote('up');\" onmouseover=\"parent.tooltip.show('I like this site', 200);\" onmouseout=\"parent.tooltip.hide();\"><img src='/images/thumb_up.png' style='width:23px;border:0px;' /></a><span id='thumb_tip_like' style='display:none;position:absolute;'></span></span><span style='margin-left: 5px;'><a href='#' onclick=\"parent.vote('down');\" onmouseover=\"parent.tooltip.show('I dislike this site', 200);\" onmouseout=\"parent.tooltip.hide();\"><img src='/images/thumb_down.png' style='width:23px;border:0px;' /></a><span id='thumb_tip_dislike' style='display:none;position:absolute;'></span></span>";
	else
		doc.getElementById('vote_area').innerHTML = "<span style='margin-left: 5px;'><img src='/images/thumb_"+json_array['vote']+".png' style='border:0px;' /></span>";
		
	//Hide that link
	doc.getElementById('vote_area').style.display = 'none';
	document.getElementById('credit_info').style.display = 'none';
	document.getElementById('user_info').style.display = 'inline';
	
	update_counter(10);
	//Update iframe size, once initally, once after a .5sec to give about time to load
	update_size();
	setTimeout("update_size();", 500);
}
/*
function show_listad(userid)
{
	doc.getElementById('listad').style.display = 'block';

	XMLHttpRequestObject = ajax_start();
	display_ajax_html('listad', '&user_id='+userid, 'listad_inner', XMLHttpRequestObject);		
}
*/
function minimize()
{
	document.getElementById('handle').style.width = '75px';		

	doc.getElementById('thumbs').style.display = 'none';
	if(doc.getElementById('next'))
		doc.getElementById('next').style.display = 'none';
	document.getElementById('credit_info').style.display = 'none';
	doc.getElementById('vote_area').style.display = 'none';
	doc.getElementById('about').style.display = 'none';
	doc.getElementById('surf_bar_inner').style.display = 'none';
	document.getElementById('counter').innerHTML = "<a href='#' onclick='parent.maximize();' class='link_button' style='background-color:#111111;'>Show</a>";
	//Update iframe size
	update_size();
}
function maximize()
{
	doc.getElementById('thumbs').style.display = 'block';
	if(doc.getElementById('next'))
		doc.getElementById('next').style.display = 'block';
	document.getElementById('credit_info').style.display = 'inline';
	doc.getElementById('vote_area').style.display = 'inline';
	doc.getElementById('about').style.display = 'block';
	doc.getElementById('surf_bar_inner').style.display = 'block';
	document.getElementById('counter').innerHTML = "<a href='#' onclick='parent.minimize();' class='link_button' style='background-color:#111111;'>Hide</a>";
	//Update iframe size
	update_size();
}
function thumb_tip(text)
{
	if(doc.getElementById('thumb_tip_'+text).style.display == 'none')
	{
		doc.getElementById('thumb_tip_'+text).style.display = 'block';
		doc.getElementById('thumb_tip_'+text).innerHTML = text;
	}
	else
		doc.getElementById('thumb_tip_'+text).style.display = 'none';
}
function on_load(validate)
{
	//Make 100% height
	resize_iframe();
	//Resize Chat Frame
	resize_chatframe();
	//Add in the iframe shim
	var shimmer = document.createElement('iframe');
	shimmer.id='shimmer';
	shimmer.style.position='absolute';
	shimmer.style.width = '250px';
	shimmer.style.height = '1px';
	shimmer.style.top='21px';
	shimmer.style.left='0';
	shimmer.style.zIndex='50';
	/*if(-1 != navigator.userAgent.toLowerCase().indexOf("mac"))
	{
		shimmer.style.opacity='.90';
		shimmer.style.filter='alpha(opacity=90)';
	}*/
	shimmer.style.overflow='hidden';
	shimmer.setAttribute('frameborder','0');
	shimmer.setAttribute('src','/surf_frame.php');
	shimmer.setAttribute('scrolling','no');
 	document.getElementById('surf_bar').appendChild(shimmer);
 }
function surf_on_load(validate)
{
	get_frame();
	document.getElementById('loading').style.display = 'none';
	//Update with startpage
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('get_startpage', '', '', XMLHttpRequestObject, update_startpage);

	update_counter(10, validate);
}
function update_startpage(responseText)
{
	var json_array = eval('(' + responseText + ')');

	//Update other user social stuff
	doc.getElementById('surf_name').innerHTML = json_array['name'];
	var new_text = "<div style='float:left;'>"+json_array['name']+'</div><div style="clear:both;float:left;">'+json_array['rating']+'</div><div style="float: left;clear:both;" id="pic_social">';
	if(json_array['pic'])
		new_text += "<span style='float:left;margin-bottom:5px;'>"+json_array['pic']+"</span>";
	new_text += "<span style='float:left;' id='social_icons'>";
	
	/* IMLOOP INTEGRATION */
	if(json_array['imloop'] != '' && json_array['imloop'] != null)
	{
		if( json_array['friends'] == 'f' )
			new_text += "<a href='javascript: void( 0 );' onclick=\"parent.im_add_friend('" + json_array['imloop'] + "');\" class='icon_light' title='Add as friend'><img src='/images/icons/im_32.png' style='border:0px;' /></a> ";
		else
			new_text += "<a href='http://imloop.com/#!/" + json_array['imloop'] + "' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/im_32.png' style='border:0px;' /></a> ";
	}
	/* END IMLOOP INTEGRATION */
	
	if(json_array['twitter'] != '' && json_array['twitter'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/twitter' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/twitter_32.png' style='border:0px;' /></a> ";
	if(json_array['facebook'] != '' && json_array['facebook'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/facebook' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/facebook_32.png' style='border:0px;' /></a> ";
	if(json_array['youtube'] != '' && json_array['yahoo'] != null)
		new_text += "<a href='/track/"+json_array['user_id']+"/youtube' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/youtube_32.png' style='border:0px;' /></a> ";
	if(json_array['blog'] != '' && json_array['blog'] != null)
		new_text += "<a href='"+json_array['blog']+"' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/rss_32.png' style='border:0px;' /></a> ";
	//upgraded sites array
	var sites_array = new Array("digg", "linkedin", "blogger", "flickr", "tumblr", "email", "yahoobuzz", "myspace", "vimeo", "orkut", "stumbleupon", "picasa", "friendfeed", "lastfm", "skype", "aim", "google");
	for(var site in sites_array)	
	{
		if(json_array[sites_array[site]] != '' && json_array[sites_array[site]] != null)
			new_text += "<a href='"+json_array[sites_array[site]]+"' rel='external' target='_BLANK' class='icon_light'><img src='/images/icons/"+sites_array[site]+"_32.png' style='border:0px;' /></a> ";	
	}
	new_text += "<span></div>";
	if(json_array['listad'] == 'true')
		new_text += "<div id='listad'>"+json_array['listad_header']+"<br />"+json_array['listad_html']+"</div>";
	//If they don't have anything at all...
	if(new_text == "<span style='float:left;'>"+json_array['name']+'</span><span style="float: left;margin-left:15px;"></span>')
		new_text += '<span style="float: left;margin-left:15px;"> doesn\'t have any profile information entered.</span>';
	doc.getElementById('about_text').innerHTML = new_text;
	if(json_array['listad'] == 'true')
	{
		//Fill in name and email
		var fill_name = doc.getElementsByName('name');
		var fill_fullname = doc.getElementsByName('fullname');
		var fill_email = doc.getElementsByName('email');
		if(fill_name.length > 0)
			fill_name[0].value = json_array['surfer_name'];
		if(fill_fullname.length > 0)
			fill_fullname[0].value = json_array['surfer_name'];
		if(fill_email.length > 0)
			fill_email[0].value = json_array['surfer_email'];
	}
	//Update iframe size, once initally, once after a .5sec to give about time to load
	update_size();
	setTimeout("update_size();", 500);
}

function postchatmessage()
{

	if ( document.getElementById('txtmsg').value.length<=200 )
	{
		var txtmessage = document.getElementById('txtmsg').value;
		//Update Chat Message
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('chat_msg', '&txtmessage='+txtmessage, '', XMLHttpRequestObject, output_chatmsg);
		document.getElementById('txtmsg').value="";
		return false;
	}
	else
	{
		alert("The Message must be less than 200 Characters.");
		return false;
	}
}

function output_chatmsg(responseText)
{
	$("#top_framechat").contents().find("#divIdChat").prepend(responseText);
}

function showTime()
{
	$("#top_framechat").contents().find("#divIdChat .chattime").toggle();
	//$("#divIdChat .chattime").toggle();
	return false;
}

function hideChat()
{
	$("#chatpanel").toggle();
}

function showChatAds()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('chat_ads', '', '', XMLHttpRequestObject, output_adschatmsg);	
}

function output_adschatmsg(responseText)
{	
	//var json_array = eval('(' + responseText + ')');	
	$("#top_framechat").contents().find("#divIdChat").prepend(responseText);
	
}

function checkIdleTime()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('chat_idletime', '', '', XMLHttpRequestObject, output_disablechat);	
}

function output_disablechat(responseText)
{
	if ( responseText=="N" )
	{
		$("#DivIdTextbox").hide();
		$("#DivIdSurfChat").show();		
	}
	else
	{
		$("#DivIdTextbox").show();
		$("#DivIdSurfChat").hide();
	}
}

function refreshChatFrame()
{
	document.getElementById('top_framechat').contentDocument.location.reload(true);	
}

function get_frame()
{
	var frame = document.getElementById('shimmer');
	doc = frame.contentDocument;
      if (doc == undefined || doc == null)
          doc = frame.contentWindow.document;
 	doc.getElementById('surf_bar_inner').style.minWidth = doc.getElementById('surf_bar_inner').offsetWidth+1+'px';
 	frame.style.border='1px solid #cccccc';
	frame.style.borderTop='0px';
	frame.style.zIndex='500';
	frame.setAttribute('frameborder','0'); 
    //Get frame size and update our iframe
	update_size();
 	//Put iframe on top
	//setInterval("doc.getElementById('background1').innerHTML = Math.floor(Math.random()*11);", 1);
}
function update_size()
{
	var newWidth = doc.getElementById('surf_bar_inner').offsetWidth;
	if(doc.getElementById('about').offsetWidth > newWidth)
		newWidth = doc.getElementById('about').offsetWidth;
	var newHeight = doc.getElementById('surf_bar_inner').offsetHeight;
	
	if( -1 != navigator.userAgent.indexOf ("MSIE") )
	{
		//newWidth = newWidth + 30;
	}
	document.getElementById('shimmer').style.width = newWidth+'px';
	document.getElementById('handle').style.width = newWidth-6+'px';
	doc.getElementById('about').style.minWidth = newWidth-22+'px';
	doc.getElementById('about_text').style.width = newWidth-22+'px';
	doc.getElementById('surf_bar_inner').style.minWidth = newWidth-22+'px';
	document.getElementById('shimmer').style.height = newHeight+doc.getElementById('about').offsetHeight+'px';
}
function resize_iframe()
{
	//Iframe size
	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the window
	document.getElementById("top_frame").style.height=parseInt(height-document.getElementById("top_frame").offsetTop-8)+"px";
}
function resize_chatframe()
{
	//resize the iframe according to the size of the window
	//document.getElementById("top_framechat").style.height="95%";
	//Iframe size
	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}

	//resize the iframe according to the size of the window
	document.getElementById("top_framechat").style.height=parseInt(height-document.getElementById("top_framechat").offsetTop-10)+"px";
	
}

function ignoremessage(userid,ignoreuserid)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('ignore_message', '&ignoreuserid='+ignoreuserid, '', XMLHttpRequestObject, output_ignorechat);	
}

function output_ignorechat(userid)
{
	refreshChatFrame();
}

function do_nothing()
{
	//Best function ever
}
//Tooltips
var tooltip=function()
{
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = doc.all ? true : false;
	return{
		show:function(v,w)
		{
			if(tt == null)
			{
				tt = doc.createElement('div');
				tt.setAttribute('id',id);
				c = doc.createElement('div');
				c.setAttribute('id',id + 'cont');
				tt.appendChild(c);
				doc.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				doc.onmousemove = this.pos;
   			}
   			//lazy
			w = false;
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie)
			{
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  		},
  		pos:function(e)
  		{
			var u = ie ? event.clientY + doc.docElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + doc.docElement.scrollLeft : e.pageX;

			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) - 60 + 'px';
  		},
  		fade:function(d)
  		{
   			var a = alpha;
  			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    		var i = speed;
   			if(endalpha - a < speed && d == 1)
   			{
    			i = endalpha - a;
   			}
   			else if(alpha < speed && d == -1)
   			{
    			i = a;
   			}
   				alpha = a + (i * d);
   				tt.style.opacity = alpha * .01;
   				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}
  			else
  			{
    		clearInterval(tt.timer);
			if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function()
 		{
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

window.onresize=resize_iframe;
