var systemMsg;
function systemMessage() {
	$(document).ready(function() {
		$("#systemBg").slideDown("normal", closeSystemMessage());
		systemMsg = setInterval('closeSystemMessage()', 3000);
	});
}

function closeSystemMessage() {
	clearInterval(systemMsg);
	$("#systemBg").slideUp("slow");

}

//Fancybox settings
$(document).ready(function() {
	$("a.imageGalleryGroup").fancybox({
		'zoomSpeedIn'	:	600, 
		'zoomSpeedOut'	:	500, 
		'overlayShow'	:	false,
		'imageScale'	: 	true,
		'easingIn'		:	'easeOutBack',
		'easingOut'		:	'easeInBack',
		'overlayShow'	:	true,
		'overlayOpacity':	0.7,
		'frameWidth'	:	800,
		'frameHeight'	:	500,
		'callbackOnClose':	killMedia
	});
});

function fancyDelay() {
	//Fancybox settings
	$(document).ready(function() {
		$("a.imageGalleryGroup").fancybox({
			'zoomSpeedIn'	:	600, 
			'zoomSpeedOut'	:	500, 
			'overlayShow'	:	false,
			'imageScale'	: 	true,
			'easingIn'		:	'easeOutBack',
			'easingOut'		:	'easeInBack',
			'overlayShow'	:	true,
			'overlayOpacity':	0.7,
			'frameWidth'	:	800,
			'frameHeight'	:	500,
			'callbackOnClose':	killMedia
		});
	});
}

function killMedia() {
	if (document.getElementById('MediaPlayer1') && document.getElementById('MediaPlayer1').stop) {	
		document.getElementById('MediaPlayer1').stop();
	}
}

function fancyBoxReady() {
	
	setTimeout('fancyDelay()', 1000);
	
}



//Ajax loadThis function
var xmlhttp = new Array();
var i = 0;

function loadThis(url, destination, functocall, ajaxWidth, loadTiny, showAnimation, animation, action, showFrame, method, params) {
	
	var ie6Test = false;
	var IE6 = false /*@cc_on || @_jscript_version <= 5.7 @*/;
	if(IE6 == true) ie6Test = true;
	
	if(!loadTiny || loadTiny == null || loadTiny == '' || loadTiny == undefined || loadTiny == 'undefined') loadTiny = false;
	
	
	if (!method) method = 'get';
	
	animationArray = new Array();
	animationArray[1] = 'ajax_iamloading.gif';
	animationArray[2] = 'ajax-loader-bar.gif';
	animationArray[3] = 'ajax-loader-flower.gif';

	if(!ajaxWidth) 	ajaxWidth = 400;
	if(!animation) 	animation = 1;
	if(!action) 	action = 'replace';
	if(!showFrame) 	showFrame = 'show';
	


	if(!destination && document.getElementById("ajaxContainer")) {
		$('#ajaxContainer').remove();
		$('#coverImage').remove();
	}	
	

	if (!destination) {
		destination = "ajaxContent";
		
			winHeightD	= $(document).height(); 

			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				winWidth = window.innerWidth;
				winHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				winWidth = document.documentElement.clientWidth;
				winHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				winWidth = document.body.clientWidth;
				winHeight = document.body.clientHeight;
			}

			sWinHeight = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				sWinHeight = window.pageYOffset;
			} else if( document.body &&  document.body.scrollTop  ) {
				//DOM compliant
				sWinHeight = document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop  ) {
				//IE6 standards compliant mode
				sWinHeight = document.documentElement.scrollTop;
			} 
			winHeightD = winHeightD-5;

			$(document.body).append('<div id="coverImage" style="height:'+winHeightD+'px"></div>');
			
			if(showFrame=='hide') {
				$(document.body).append('<div id="ajaxContainer" style="display:none; overflow:hidden; background:none; z-index:20; width:'+(ajaxWidth)+'px; margin:0px; padding:0px; z-index:2000"><div id="ajaxContentBox" class="png" style="background:none; margin:0px; padding:0px; width:'+(winWidth)+'px;"><div id="ajaxContent" class="png" style="background:none; width:'+(winWidth)+'px; overflow:hidden; padding:0px;"></div></div></div>');
			} else {
				if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
					$('#wrapper select').each(function(){ $(this).hide(); });
					$(document.body).append('<div id="ajaxContainer" style="z-index:20; display:none; width:'+ajaxWidth+'px"><div id="ajaxContentBox" class="png"><div id="ajaxContent" class="png" style="width:'+(ajaxWidth-30)+'px"></div><a href="javascript:" onclick="closeAjax();" id="ajaxClose_btn" title="close" class="png"><img src="images/ajax_close-big.png" border="0" alt="Close" class="png" width="48px" height="48px" /></a></div></div>');
				} else {
					$(document.body).append('<div id="ajaxContainer" style="z-index:20; display:none; width:'+ajaxWidth+'px"><div id="ajaxInnerContainer"><img src="images/ajax_left-corner.png" alt="" border="0" class="png" width="16px" id="ajaxContainer_c_1" /><img src="images/ajax_right-corner.png" alt="" border="0" class="png" width="16px" id="ajaxContainer_c_2" /><div id="ajaxContainer_top" class="png"></div><div id="ajaxContainer_left" class="png"><div id="ajaxContentBox" class="png"><div id="ajaxContent" class="png" style="width:'+(ajaxWidth-30)+'px"></div></div></div><div id="ajaxContainer_bottom" class="png"></div><img src="images/ajax_left-corner-b.png" class="png" alt="" border="0" width="16px" id="ajaxContainer_c_3" /><img src="images/ajax_right-corner-b.png" alt="" border="0" class="png" width="16px" id="ajaxContainer_c_4" /><a href="javascript:" onclick="closeAjax();" id="ajaxClose_btn" title="close"><img src="images/ajax_close-big.png" border="0" alt="Close" class="png" width="48px" height="48px" /></a></div></div>');
				}
			}

	} else {

		if (showAnimation) {
			// show loading image
			destHight = ($('#'+destination).height())-2;
			$('#'+destination).empty();
			if(animation==1) {
				$('#'+destination).append('<div ID="ajaxLoader"><div ID=ajaxLoadIcon style="background:url(images/'+animationArray[animation]+') center center no-repeat;"></div></div><div style="clear:both"></div>');
			} else {
				$('#'+destination).append('<div ID=ajaxLoadIcon style="padding:0; height:'+destHight+'px; background:url(images/'+animationArray[animation]+') center center no-repeat;"></div><div style="clear:both"></div>');	
			}
			
		}
	}
	
	xmlhttp[i]=null
	if (functocall=="undefined") functocall = "";
	if (destination=="undefined") destination = "";
	if (window.XMLHttpRequest) {
		xmlhttp[i] = new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlhttp[i] = new ActiveXObject("Microsoft.XMLHTTP")
	}
	
	if (xmlhttp[i]!=null) {
		var currentTime = new Date();
		xmlhttp[i].onreadystatechange=new Function("loaded("+i+",'"+destination+"','"+functocall+"','"+action+"','"+loadTiny+"')")
		//xmlhttp[i].open("GET",baseurl+url,true)
		if (method == 'post') {
			xmlhttp[i].open("POST",url,true);
			xmlhttp[i].send(params);
		} else {
			xmlhttp[i].open("GET",url,true);
			xmlhttp[i].send(null);
		}
	} else {
		alert("Your browser does not support AJAX")
	}
	i=i+1;
	
}
					
function loaded(b,destination,functocall,action, loadTiny) {

	if (xmlhttp[b].readyState==4 || xmlhttp[b].readyState=="complete") {
		
		if (xmlhttp[b].status == 200) {
			if (destination != "undefined" && destination != "" && destination!="hidden" && destination != null && xmlhttp[b].responseText!=''){ 
				//document.getElementById(destination).innerHTML = xmlhttp[b].responseText;
				
				if(action=='replace') {
					$('#'+destination).html(xmlhttp[b].responseText);
				} else if(action=='append') {
					$('#'+destination).append(xmlhttp[b].responseText);
				} else if(action=='prepend') {
					$('#'+destination).prepend(xmlhttp[b].responseText);
				} else if(action=='before') {
					$('#'+destination).before(xmlhttp[b].responseText);
				} else if(action=='after') {
					$('#'+destination).after(xmlhttp[b].responseText);
				}
				
				adjustAjax();
				if (loadTiny) 
					tinyMCELoad();	

			}
			
			if (functocall!="undefined" && functocall!="") {
				
				if (functocall.indexOf('(') > -1)
					eval(functocall);
				else 
					eval(functocall+'()');
			}
		} else {
			//alert("Problem retrieving data")
			//alert(xmlhttp[b].status)
		}
	}
}
function adjustAjax() {
	
	winHeightD	= $(document).height(); 
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

	sWinHeight = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		sWinHeight = window.pageYOffset;
	} else if( document.body &&  document.body.scrollTop  ) {
		//DOM compliant
		sWinHeight = document.body.scrollTop;
	} else if( document.documentElement && document.documentElement.scrollTop  ) {
		//IE6 standards compliant mode
		sWinHeight = document.documentElement.scrollTop;
	} 
	
	acWidth		= $('#ajaxContainer').width();
	acHeight	= $('#ajaxContainer').height();

	pHeight = (winHeight/2)-(acHeight/2)+sWinHeight;
	pWidth = (winWidth/2)-(acWidth/2);
	
	addHeight = 0;
	
	if(pHeight<=0) { 
		pHeight = 50;
		$('#coverImage').height(acHeight+pHeight);
	}
	
	$('#ajaxContainer').css('top',(pHeight)+'px');
	$('#ajaxContainer').css('left',pWidth+'px');
	$('#ajaxContainer').css('z-index','100');
	
	$('#ajaxContainer').fadeIn("fast");		
}
function closeAjax() {
	$('#ajaxContainer').fadeOut("fast",function callback() {$('#ajaxContainer').remove()});
	$('#coverImage').fadeOut("fast",function callback() {$('#coverImage').remove()});
	$('#wrapper select').each(function(){ $(this).show(); });
}


function __loadThis(url, destination, functocall, ajaxWidth, loadTiny) {
	if(!ajaxWidth) ajaxWidth = 400;
	if(!loadTiny || loadTiny == null || loadTiny == '' || loadTiny == undefined || loadTiny == 'undefined') loadTiny = false;
	
	if (!destination) {
		destination = "ajaxContent";
		if(!document.getElementById("ajaxContainer")) {		
			
			//winWidth	= document.all?document.body.clientWidth:window.innerWidth; 
			//winHeight	= document.all?document.body.clientHeight:window.innerHeight; 
			//sWinHeight	= window.pageYOffset || document.documentElement.scrollTop 	|| 0;
			
			winHeightD	= $(document).height(); 
			
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				winWidth = window.innerWidth;
				winHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				winWidth = document.documentElement.clientWidth;
				winHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				winWidth = document.body.clientWidth;
				winHeight = document.body.clientHeight;
			}

			sWinHeight = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				sWinHeight = window.pageYOffset;
			} else if( document.body &&  document.body.scrollTop  ) {
				//DOM compliant
				sWinHeight = document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop  ) {
				//IE6 standards compliant mode
				sWinHeight = document.documentElement.scrollTop;
			} 

			$(document.body).append('<div id="coverImage" style="height:'+(winHeightD-3)+'px"></div>');
			//$(document).append('<img src="images/blank.gif" id="coverImage">');
			//$(document.body).append('<div id="ajaxContainer" style="display:none; z-index:20;"><div style="position:relative;"><div id="ajaxContainer_top" class="png"></div><div id="ajaxContainer_left" class="png"><div id="ajaxContentBox" class="png"><div id="ajaxContent"></div></div></div><div id="ajaxContainer_bottom" class="png"></div><div id="ajaxContainer_c_1"><img src="images/left-corner.png" class="png" alt="" border="0" /></div><div id="ajaxContainer_c_2"><img src="images/right-corner.png" class="png" alt="" border="0" /></div><div id="ajaxContainer_c_3"><img src="images/left-corner-b.png" class="png" alt="" border="0" /></div><div id="ajaxContainer_c_4"><img src="images/right-corner-b.png" class="png" alt="" border="0" /></div><a href="javascript:" onclick="closeAjax();" id="ajaxClose_btn" class="absolute" style="top:-18px; right: -18px; z-index:500;" title="close"><img src="images/close-big.png" border="0" alt="Close" class="png" /></a></div></div>');
			$(document.body).append('<div id="ajaxContainer" style="z-index:20; width:'+ajaxWidth+'px"><div style="position:relative;margin:0;padding:0"><div id="ajaxContainer_c_1"><img src="images/left-corner.png" alt="" border="0" /></div><div id="ajaxContainer_c_2"><img src="images/right-corner.png" alt="" border="0" /></div><div id="ajaxContainer_top"></div><div id="ajaxContainer_left"><div id="ajaxContentBox" style="margin:0"><div id="ajaxContent"></div></div></div><div id="ajaxContainer_bottom"></div><div id="ajaxContainer_c_3"><img src="images/left-corner-b.png" alt="" border="0" /></div><div id="ajaxContainer_c_4"><img src="images/right-corner-b.png" alt="" border="0" /></div><a href="javascript:" onclick="closeAjax();" id="ajaxClose_btn" class="absolute" style="top:-18px; right: -18px; z-index:2000;" title="close"><img src="images/close-big.png" border="0" alt="Close" class="png" /></a></div></div>');
			
					
			
			acWidth		= $('#ajaxContainer').width();
			acHeight	= $('#ajaxContainer').height();
			
			pHeight = (winHeight/2)-(acHeight/2)+sWinHeight-50;
			pWidth = (winWidth/2)-(acWidth/2);
			
			
			$('#ajaxContainer').css('top',pHeight+'px');
			$('#ajaxContainer').css('left',pWidth+'px');
			$('#ajaxContainer').css('z-index','100');
			
			$('#ajaxContainer').fadeIn("slow");
			
		}
	}
	
	xmlhttp[i]=null
	if (functocall=="undefined") functocall = "";
	if (destination=="undefined") destination = "";
	if (window.XMLHttpRequest) {
		xmlhttp[i] = new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlhttp[i] = new ActiveXObject("Microsoft.XMLHTTP")
	}

	if (xmlhttp[i]!=null) {
		var currentTime = new Date();
		xmlhttp[i].onreadystatechange=new Function("loaded("+i+",'"+destination+"',"+functocall+","+loadTiny+")")
		//xmlhttp[i].open("GET",baseurl+url,true)
		xmlhttp[i].open("GET",url,true)
		xmlhttp[i].send(null)
	} else {
		alert("Your browser does not support AJAX")
	}
	i=i+1
}

function __loaded(b,destination,functocall,loadTiny) {
	
	if (xmlhttp[b].readyState==4) {
		if (xmlhttp[b].status == 200) {
			if (destination != "undefined" && destination != ""){ 
				document.getElementById(destination).innerHTML = xmlhttp[b].responseText
			}
			if (typeof(functocall)!="undefined") functocall();
			
			if (loadTiny) setTimeout("tinyMCELoad()", 100);
			
		} else {
			//alert("Problem retrieving data")
			//alert(xmlhttp[b].status)
		}
	}
}

function closeAjax() {
	$('#ajaxContainer').fadeOut("slow",function callback() {$('#ajaxContainer').remove()});
	
	$('#coverImage').remove();
	
}

function MakeSizeAdjustment(oTextArea) {
	tAreaHeight = oTextArea.style.height;
	oTextArea.style.height = oTextArea.scrollHeight+'px';
}

function sizeAdjustAll() {

	theDivs = document.getElementsByTagName('textarea');

	for (div in theDivs) {
		if (theDivs[div].className == "MakeSizeAdjustment") {
			MakeSizeAdjustment(theDivs[div]);
		}
	}
}



function getGenInvite() {

	theRel = document.genForm.rel.value;
	
	for (i=0; i<document.genForm.thetype.length; i++) {
		if (document.genForm.thetype[i].checked)
			theType = document.genForm.thetype[i].value;
	}

	loadThis('user-area.php?utask=genInvite&save=yes&rel='+theRel+'&type='+theType, '', undefined, 500)
}


function tinyMCELoad() {

	$('textarea.tinymce').tinymce({
		// Location of TinyMCE script
		script_url : 'includes/tiny_mce/tiny_mce.js',

		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7",
		skin_variant : "silver",
	
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
	
		// Theme options
		theme_advanced_buttons1 :	"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect,forecolor,|,image,media,|,bullist,numlist,|,emotions",
		theme_advanced_buttons2 :	"",
		theme_advanced_buttons3 :	"",
		theme_advanced_buttons4 :	"",
		/*
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
		theme_advanced_buttons3 : "forecolor,backcolor,|,tablecontrols,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print",
		theme_advanced_buttons4 : "hr,removeformat,visualaid,|,ltr,rtl,|,fullscreen,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		*/
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false

		// Example content CSS (should be your site CSS)
		//content_css : "style.css",

	});
	
	
}

$(document).ready(function() {
	tinyMCELoad();
});


function cleanUp() {
 // closes any popup box and refreshes page
 closeAjax();
 window.location.reload();
}


function raitingAppend() {
	setTimeout('raitingAppendTimout()', 100);
}

function faidOutBe() {

	$('#behaviours').fadeOut("fast");

}

function raitingAppendTimout() {	
	$('.hover-star').rating({
	  focus: function(value, link){
		var tip = $('#hover-test');
		tip[0].data = tip[0].data || tip.html();
		tip.html(link.title || 'value: '+value);
	  },
	  blur: function(value, link){
		var tip = $('#hover-test');
		$('#hover-test').html(tip[0].data || '');
	  }
	});
	
	setTimeout($('#behaviours').fadeIn("fast"),500);
}

function exampleTxt(id, user,action) {

	if(action == 'show') {
		loadThis('characteristics.php?task=showExample&id='+id+'&u='+user,'hideContent',undefined);
	} else {
		loadThis('characteristics.php?task=defaultExample&u='+user,'hideContent',undefined);
	}
}


function findSWF(movieName) {
	// used for hooking javascript to swf functions
	if (navigator.appName.indexOf("Microsoft")!= -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}


function createNamedElement(type, name) {
   var element = null;
   // Try the IE way; this fails on standards-compliant browsers
   try {
      element = document.createElement('<'+type+' name="'+name+'">');
   } catch (e) {
   }
   if (!element || element.nodeName != type.toUpperCase()) {
      // Non-IE browser; use canonical method to create named element
      element = document.createElement(type);
      element.name = name;
   }
   return element;
}
