function showItem(p_id, p_database, p_itemid)
{
	//Item in question
	var preview_item = jQuery("#preview_"+p_itemid+"_"+p_database+"_"+p_id);

	//Save bandwidth. If we already loaded it, we don't have to load it again
	if(preview_item.html() != "")
	{
		preview_item.show();
	}else{
		preview_item.html("Loading...");
		preview_item.show();

		jQuery.get("/ajax/get_item.php", { id: p_id, database: p_database },
		function(data){
			preview_item.html(data);
		});
	}
}

function hideItem(p_id, p_database, p_itemid)
{
	jQuery("#preview_"+p_itemid+"_"+p_database+"_"+p_id).hide();
}

function getComments(p_id, p_database)
{
	var comment_obj = jQuery("#comments_"+p_id);
	if(comment_obj.css('display') == "none")
	{
		jQuery.get("/ajax/get_comments.php", { id: p_id, database: p_database },
		function(data){
			comment_obj.html(data);
			comment_obj.slideDown(1000);
			tinyMCE.execCommand('mceAddControl', false, "comment-textarea"+p_id);
			showRecaptcha('recaptcha'+p_id, 'white');
		});
	}else{
		comment_obj.slideUp(1000);
		tinyMCE.execCommand('mceRemoveControl', false, "comment-textarea"+p_id);
	}

	return false;
}

function showRecaptcha(element, themeName) {
	Recaptcha.create("6LfLlgYAAAAAAPYcB6N8R0_kfvhlC8iF9zsDrrR_", element, {
		theme: themeName,
		tabindex: 0,
		callback: Recaptcha.focus_response_field
	});
}


function toggle( id )
{
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).className == "hide"){
			document.getElementById(id).className = 'show';
		} else {
			document.getElementById(id).className = 'hide';
		}
	} else {
		if (document.layers) {
			if (document.id.className == "hide"){
				document.id.className = 'show';
			} else {
				document.id.className = 'hide';
			}
		} else {
			if (document.all.id.className == "hide"){
				document.all.id.className = 'show';
			} else {
				document.all.id.className = 'hide';
			}
		}
	}
}
function activateSearch() {
	if ($('searchform')) {
		$('s').value = 'Start Your Search...'; // Default text in the search box
		var o = document.createElement('div'); // Old search results div
		var n = document.createElement('div'); // New search results div
		$('searchform').onsubmit = function() { doSearch();return false; };
		$('s').onfocus = focusS; // Function to clear the default search box text on focus
		var s = $('search-results');
		var f = $('searchform');
		o.id = 'old-search-results';
		n.id = 'current-search-results';
		s.appendChild(n);
		s.appendChild(o);
		o.style.display = 'none';
		n.style.display = 'none';
		is_searching = false;
	}
}

function doSearch() {
	// If we're already loading, don't do anything
	if (is_searching) return false;
	s = $F('s');
	// Same if the search is blank
	if (s == '' || s == 'Start Your Search...') return false;
	is_searching = true;
	c = $('current-search-results');
	o = $('old-search-results');
	b = $('searchbutton');
	b.value = 'Loading';
	b.disabled = true;
	o.innerHTML = c.innerHTML;
	c.style.display = 'none';
	o.style.display = 'block';
	// Setup the parameters and make the ajax call
	pars = 's=' + escape(s) + '&ajax';
	var myAjax = new Ajax.Request('http://server1.mapletip.com/',
	{method: 'get', parameters: pars, onComplete:doSearchResponse});
}

function doSearchResponse(response) {
	$('current-search-results').innerHTML = response.responseText;
	new Effect.BlindUp('old-search-results',{duration:.8});
	new Effect.BlindDown('current-search-results',{duration:.8, afterFinish:resetForm});
}

function resetForm() {
	s = $('searchbutton');
	s.value = 'Find It';
	s.disabled = false;
	is_searching = false;
}

function focusS() {
	if ($F('s') == 'Start Your Search...') $('s').value = '';
}

Event.observe(window, 'load', activateSearch, false);
/* MARKET FUNCTIONS */

function enable(id)
{
	target = document.getElementById(id);
	target.disabled = false;
}

function disable()
{
	var id = new Array(5)
	id[0] = "o1";
	id[1] = "o2";
	id[2] = "o3";
	id[3] = "o4";
	id[4] = "o5";

	for (var i=0;i < 5;i++)
	{
		target = document.getElementById(id[i]);

		if (target.disabled == false){	target.disabled = true; }
	}
}

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
		tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip

/***********************************************
* AnyLink Vertical Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1


var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width: 160px" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
	dropmenuobj.style.left=dropmenuobj.style.top=-500
	dropmenuobj.widthobj=dropmenuobj.style
	dropmenuobj.widthobj.width=menuwidth
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	obj.visibility=visible
	else if (e.type=="click")
	obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
			edgeoffset=dropmenuobj.y
		}
	}
	return edgeoffset
}

function populatemenu(what){
	if (ie4||ns6)
	dropmenuobj.innerHTML="<a "+what.join("</a><a ")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu()
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents)

	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
	}

	return clickreturnvalue()
}

function clickreturnvalue(){
	if (ie4||ns6) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
	delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
	delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
		dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){
	if (ie4||ns6)
	delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
	clearTimeout(delayhide)
}
/* MARKET FUNCTIONS */

function market_enable(id)
{
	target = document.getElementById(id);
	target.disabled = false;
}

function market_disable()
{
	var id = new Array(5)
	id[0] = "o1";
	id[1] = "o2";
	id[2] = "o3";
	id[3] = "o4";
	id[4] = "o5";

	for (var i=0;i < 5;i++)
	{
		target = document.getElementById(id[i]);

		if (target.disabled == false){	target.disabled = true; }
	}
}

var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

function openVideo(url, name)
{
	// open a welcome message as soon as the window loads
	Shadowbox.open({
		content:    "http://www.youtube.com/v/"+ url + "&autoplay=1&ap=%2526fmt%3D18",
		player:     "swf",
		title:      name,
		height:     385,
		width:      640
	});
}


