function addtourl(select) {
	url = window.location.href;
	if (url.indexOf(select.name) > 0) {
		var txt = new RegExp("([\&]?)" + select.name + "=([0-9a-zA-Z]*)");
		url = url.replace(txt, '');
		var txt = new RegExp("([\?]?)" + select.name + "=([0-9a-zA-Z]*)");
		url = url.replace(txt, '?');
	}
	if (url.indexOf('?')) {
		url += '&' + select.name + '=' + select.value;
	} else {
		url += '?' + select.name + '=' + select.value;
	}
	window.location = url;
}

function gallery_start() {
	$("a[rel='gallery1']").colorbox({
		photo : true,
		slideshow : true,
		slideshowAuto : false
	});
	$("a[rel='gallery2']").colorbox({
		photo : true,
		slideshow : true,
		slideshowAuto : false
	});
	document.oncontextmenu=function(){window.status='Right click is disabled';return false;};
}

function resetInput(input, text) {
	if (input.value == text) {
		input.value = '';
	} else if (input.value == '') {
		input.value = text;
	}
}

function showIcons() {
	document.getElementById('smilies').style.display = 'block';
	return false;
}

function hideIcons() {
	document.getElementById('smilies').style.display = 'none';
	return false;
}

function toggleIcons() {
	if (document.getElementById('smilies').style.display == 'block') {
		document.getElementById('smilies').style.display = 'none';
	} else {
		document.getElementById('smilies').style.display = 'block';
	}
	return false;
}

function useIcon(iconlink) {
	if (document.getElementById('chat_text').value == '') {
		document.getElementById('chat_text').value += iconlink.title + ' ';
	} else {
		document.getElementById('chat_text').value += ' ' + iconlink.title + ' ';
	}
	document.getElementById('chat_text').focus();
	return hideIcons();
}

function toUser(userlink) {
	if (document.getElementById('chat_text').value == '') {
		document.getElementById('chat_text').value += '@' + userlink.title + ' ';
	} else {
		document.getElementById('chat_text').value = '@' + userlink.title + ' '
				+ document.getElementById('chat_text').value;
	}
	document.getElementById('chat_text').focus();
	return hideIcons();
}

var chat_lastEntry;
var chat_XMLUrl;
var chat_baseUrl;

function chat_resize() {
	var vH = window.innerHeight ? window.innerHeight : $(window).height();
	// 110 = header, 140 = enter text box
	// vH = vH - 110 - 140;
	vH = vH - 150 - 140;
	if (vH > 100) {
		$('#chat, #chat-resize').height(vH + 24);
		$('#chat .scroll').height(vH - 24);
	}
}

function chat_start(base, xml, last) {
	chat_lastEntry = last;
	chat_XMLUrl = xml;
	chat_baseUrl = base;
	if ($('#chat').length) {
		$('#chat').addClass('chat-resizable');
		$('#chat .scroll').wrap('<div id="chat-resize"></div>');
		chat_resize();
		$(window).resize(chat_resize);
	}
	setTimeout("chat_ajax()", 1000);
}

function chat_parse(html) {
	var entries = html.getElementsByTagName('entry');
	var last = 0;
	for (i = entries.length; i > 0; i--) {
		var entry = entries[i - 1];
		var attr = entry.attributes;
		id = attr.getNamedItem("id").value;
		if (last == 0) {
			chat_lastEntry = id;
			last = id;
		}
		if (document.getElementById("chatentry" + id)) {
			continue;
		}
		chat_showLine(id, attr, entry);
	}
	setTimeout("chat_ajax()", 3000);
}

function chat_ajax() {
	$.ajax({
		url : chat_XMLUrl + chat_lastEntry,
		cache : false,
		success : chat_parse
	});
}

function chat_showLine(id, attr, entry) {
	var tbl = document.getElementById('chat_entries');
	var row = tbl.insertRow(0);
	row.id = 'chatentry' + id;

	var td = row.insertCell(0);
	td.className = "time";
	var textNode = document.createTextNode(attr.getNamedItem("added").value);
	td.appendChild(textNode);

	td = row.insertCell(1);
	if (attr.getNamedItem("sys").value == "0") {
		var bold = document.createElement("b");
		bold.className = attr.getNamedItem("gender").value;
		bold.appendChild(document
				.createTextNode(attr.getNamedItem("nick").value + ":"));
		td.appendChild(bold);
		td.appendChild(document.createTextNode(" "));
		if (entry.firstChild) {
			td.innerHTML += chat_toSmilies(entry.firstChild.nodeValue);
		}
	} else {
		textNode = document.createTextNode(entry.firstChild.nodeValue);
		td.className = "status";
		td.appendChild(textNode);
	}
}

function chat_toSmilies(text) {
	var smiley_array = [':)', ':D', '8)', ';)', ':P', ':x', ':*', ':(', ':o'];
	for ( var i = 0; i < smiley_array.length; i++) {
		var smiley_img = '<img alt="' + smiley_array[i] + '" src="'
				+ chat_baseUrl + 'img/chat/smile' + (i + 1) + 'small.gif" />';
		text = text.replace(smiley_array[i], smiley_img);
	}
	return text;
}

var player_curSize;
var player_wndHeight;
var player_wndWidth;
function player_start(size) {
	if (size == 'normal')
	{
		var width = 720;
		var height = 405 + 65;
		document.getElementById('wrapper').className = "normal";
	}
	if (size == 'mini')
	{
		var width = 360;
		var height = 203 + 65;
		document.getElementById('wrapper').className = "mini";
	}
	if (size == 'full')
	{
		var player = document.getElementById('media_player');
		if(player.playState == 3)
		{
			try
			{
				player.fullScreen = true;
			}
			catch (err){}
		}
		return false;
	}
	document.getElementById('playerwindow').style.width = width + "px";
	document.getElementById('player').style.width = width + "px";
	document.getElementById('player').style.height = height + "px";
	player_wndWidth = width + 50;
	player_wndHeight = height + 250;
	player_window(player_wndWidth, player_wndHeight);
	player_curSize = size;
	return false;
}

function player_window(x, y) {
	window.resizeTo(x, y);
	window.moveTo((screen.width - x)/2,(screen.height - y)/2);
	window.focus();
}

function player_resize(x, y) {
	var ratio = x / y;
	var width = document.getElementById('player').style.width.replace('px', '');
	var height = document.getElementById('player').style.height.replace('px', '');
	var newheight = (width / ratio) + 65;
	document.getElementById('player').style.height = newheight + 'px';
	if (x == 4)
	{
		document.getElementById('ratio169').className = 'normal';
		document.getElementById('ratio43').className = 'highlight';
	}
	else
	{
		document.getElementById('ratio43').className = 'normal';
		document.getElementById('ratio169').className = 'highlight';
	}
	if (height < newheight)
	{
		player_wndHeight += (newheight - height);
	}
	else
	{
		player_wndHeight -= (height - newheight);
	}
	player_window(player_wndWidth, player_wndHeight);
	return false;
}

function form_limitChecks(name, allowed, msg) {
	var inputs = $("input[name*='"+name+"']");
	var checked = 0;
	for (i = 0; i < inputs.length; i++) {
		if (inputs[i].checked) {
			checked++;
		}
	}
	if (checked > allowed && msg) {
		alert(msg);
	}
	return checked <= allowed;
}

function openPopup(link, extra) {
	wnd = window.open(link.href, link.target, 'width=984, height=700,scrollbars=yes,resizable=yes,dependent=yes,full_screen=yes,status=no,location=no,directories=no,toolbar=no' + extra);
	if (wnd) {
		wnd.focus();
		return false;
	}
	else {
		return true;
	}
}

function confirmation(question) {
	return confirm(question);
}

function replyAction(input, action) {
	var el = document.getElementById('subaction');
	el.value = action;
	var el = document.getElementById('replysubmit');
	el.click();
}

function on_ctrl_enter( e ) {
	if(e == 10)
	{
		var el = document.getElementById('replysubmit');
		el.click();
	}
	else
	{
		return false;
	}
}

var profile_XMLUrl;
function profile_Change(id) {
	var el_select = document.getElementById('write_sender');
	for( i = 0; i < el_select.options.length; i++ )
    {
         // Is this the ID we are looking for?
          if( el_select.options[i].value == id )
          {
                // Select it
       	   el_select.selectedIndex = i;
                // Yes, so stop searching
                break;
          }
    }
}

function profile_Changed(select) {
	profile_Load(select.value);
}

function profile_Load(id) {
	$.ajax({
		url : profile_XMLUrl + id,
		cache : false,
		success : profile_Parse
	});
}

function profile_ParseClose(html) {
	opener.profile_Parse(html);
	window.close();
}

function profile_Parse(html) {
	var entries = html.getElementsByTagName('entry');
	var last = 0;
	for (i = entries.length; i > 0; i--) {
		var entry = entries[i - 1];
		var attr = entry.attributes;
		var el_link = document.getElementById('profile_link');
		el_link.href = attr.getNamedItem("link").value;
		el_link.title = attr.getNamedItem("name").value;
		var el_img = document.getElementById('profile_img');
		el_img.src = attr.getNamedItem("photo_small").value;
		el_img.alt = attr.getNamedItem("name").value;
	}
}

function profile_Choose(id) {
	opener.profile_Change(id);
	$.ajax({
		url : profile_XMLUrl + id,
		cache : false,
		success : profile_ParseClose
	});
	return false;
}

function template_Change(id, subject, text) {
	var el_subject = document.getElementById('write_subject');
	el_subject.value = subject;
	var el_text = document.getElementById('write_text');
	el_text.value = text;
	var el_id = document.getElementById('write_t');
	if (el_id)
	{
		el_id.value = id;
	}
}

function template_Choose(id) {
	var subject = document.getElementById('subject-'+id);
	var text = document.getElementById('text-'+id);
	opener.template_Change(id, subject.innerHTML, text.innerHTML);
	window.close();
	return false;
}

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


/* jquery scripts */
$(document).ready(function() {

	if ($('div.hint')) {
		$('div.hint').wrap('<div class="hint-wrap"></div>');
		$('div.hint-wrap').hide();
		$('#banner .test,.welcome-community .test').ifixpng();
		$('label.hint').hover(function() {
			$(this).next('div.hint-wrap').fadeIn();
		}, function() {
			$(this).next('div.hint-wrap').hide();
		});
	}

	$(".infield label").inFieldLabels();

	$('#signup_gender').styledSelect({innerClass:'signup_gender'});
	$('#signup_birthday, #signup_birthmonth').styledSelect({innerClass:'signup_born1'});
	$('#signup_birthyear').styledSelect({innerClass:'signup_born2'});

	$('#searchopt select').styledSelect({innerClass:'searchopt'});

	//$('.planspopup,.coinspopup').popup({width: 980,height: 540,left:20,top:20,menubar:0,scrollbars:1});
	$('.campopup,.chatpopup').popup({width: 980,height: 600,left:20,top:20,menubar:0,scrollbars:0});
	$('.popup').popup({status:0});

	 $('.scrollGallery').jScrollHorizontalPane({dragMaxWidth:19,dragMinWidth:19,scrollbarHeight:10});
	 $('.scrollGallery a').hover(function(){
        $('#profile-photo').attr('src',$(this).attr('href'));
		$('#profile-photo').parent('a').attr('href',$(this).attr('href'));
	 });

	$("a.colorbox").colorbox({maxWidth:'90%',maxHeight:'90%'});
	$("a.attach").colorbox({maxWidth:'90%',maxHeight:'90%',photo:'true'});

	$("#ticker #news").jCarouselLite({
		vertical:true,
		visible:1,
		auto: 2000,
		speed: 500
    });

	$('#home-signup .toggleform').click(function(){
		if ($('#signupform').hasClass('visible')) {
			$('#signupform').stop().animate({'left':297}, 500,function(){
				$('#signupformholder').css('z-index','0');
			});
		}   else {
			$('#signupform').stop().animate({'left':0}, 500);
			$('#signupformholder').css('z-index','10');
		}
		$('#signupform').toggleClass('visible');
		return false;
	});

	$(".shoutinput").colorbox({width:"50%", inline:true, href:"#shoutform"});

	$('.back').click(function(){
       history.go(-1);
	   return false;
	});

	$('#userinfo .menu').hover(
		function(){$(this).find('ul').show();},
		function(){$(this).find('ul').hide();}
	);
});
