 // JavaScript Document
// global vars
var Cat = 'Items';
var enEA = false;	// enable Eye and Arm on hover over btns, etc.,  this is disabled until after genie fully fades up
var enSH = false;	// enable at end of a genie show, hide - disabled while genie is fading in or out
var togSH = ''; 
// below is used for buttons - with top covers that slide    - uses JQuerry
/*	$(function() {
		$('.hover_div').hover(function(){
	//slide to left   use left   -n      slide to right use left n    slide to top   use top -n  slide to bottom, use top n
			$(this).find('img').stop(true, true) .animate({left:'-80px', opacity:0.3 },{queue:false,duration:1000});
//			$(this).find('img').stop(true, true) .animate({top:'-35px', opacity:0.3 },{queue:false,duration:1000});
		}, function(){
			$(this).find('img').stop(true, true) .animate({left:'0px', opacity:1 },{queue:false,duration:300});
//			$(this).find('img').stop(true, true) .animate({top:'0px', opacity:1 },{queue:false,duration:300});
		});
*/
/*function	toggleSearch()
{
//		$("#selectedsearch").click(function() {
			$("#advancedSearch").stop(true, true) .animate( { opacity:0.96, height:'toggle', width:'toggle' }, 400 ) ;
//		});	
}
*/

//	$("#menucontainer").css( 'z-index', '40');
//	$("#serviesBtn, #servicesBox").css( 'z-index', '1');

$(function() {      // this function makes a div dragable - used for select area   and search box   uses jquery plug in  ui
//	$("#selectArea").draggable({ handle: 'div.draghandle', containment: 'document' });
//	$("#draggable2").draggable({ cancel: "p.ui-widget-header" });
	$("#advancedSearch").draggable({ handle: 'div.draghandle', containment: 'document' });
	$("#sugLamp").draggable({ handle: 'div.draghandle', containment: 'document' });
	$("#loginBox").draggable({ handle: 'div.draghandle', containment: 'document' });
	$("div, p").disableSelection();
});

function maketop( top_id ) {
//	document.getElementById('selectArea').style.zIndex=1;
	document.getElementById('advancedSearch').style.zIndex=1;
	document.getElementById('sugLamp').style.zIndex=1;
	document.getElementById('loginBox').style.zIndex=1;

	document.getElementById( top_id ).style.zIndex=80;
}

// --- tool tip and hover boxes
$(document).ready(function(){
	
// animation for Genie to fade in on page enter
	// below is needed to set the image files so the animate command can work
	$("#geniebody_img").height(3).width(2);	
	$("#geniebody").css( {top:285, left:286, opacity: 0} );
	$("#geniebody").show();		// html sets the element as display:none,  then animate opacity cannot work
								// so after js loads, set opacity to 0, then show object, then we fade it in 
	$("#crossarms_img").height(1).width(1);
	$("#crossarms").css( {top:290, left:286, opacity: 0} );
	$("#crossarms").show();

// shrink the genie, hidden, and move to lamp opening
//	genieHide( 0, 0 );  // do this instantly
// call function for genie to come out
	genieShow( 2000, 6000);	// wait 2 sec,  then take 6 sec for genie to come up
	togSH='S';
// alert( "index = " + index+ "    showAreaNum="+showAreaNum );
//	showArea(showArea); 	// only for index file, show which area is selected
	hideServices(); 		// hide services 

	// fade out the loading div
	$("#loading").fadeOut(1500);
});  // end of document ready

/*	$("#carpet").mousemove(function() {
		$("#debug").text("enSH: "+enSH+"  |  enEA: "+enEA+"  |  togSH : "+togSH);
	});	
*/
	$("#carpet").click(function() {
		if( enSH ) {
			if( togSH == 'S' ) {
				genieHide( 0, 10000 );  // do this instantly
				togSH = 'H';
			} else {
				genieShow( 0, 10000);	// wait 2 sec,  then take 6 sec for genie to come up
				togSH = 'S';
			}
		}
	});	

	
	$('#srchHelpBtn').click(function() {
		 $('#srchHelpPop').show(800);
	});
	$('#srchHelpClose').click(function() {
		 $('#srchHelpPop').hide(800);
	});
	// --- display the help boxes
	
//	$("#srchHelpPop dd:not(:first)").hide();
	$("#srchHelpPop dd").hide();		// hides all dd help areas
	$("#srchHelpPop dt").click(function(){
		$("dd:visible").slideUp(800);			// hide, via slideUp, all dd's
		$("#srchHelpPop dt").animate( { color:'#fff', backgroundColor:'#39F' },1200);			// hide, via slideUp, all dd's
		$(this).next().slideDown(800);	// slide this one down,  showing it
		$(this).stop(true, true).animate( { color:'#cc0', backgroundColor:'#06c' },1200);
		return false;
	});
	
//--- select category type - search options
		$("div.btnOuter").hover(function() {
			$(this).find('.btnOv').fadeIn(400);
		}, function() {
			$(this).find('.btnOv').fadeOut(400);
		});

		$("#IteBtn").click(function() {
			$(".btnOuter").find('.btnDn').stop(true, true) .hide( 400 );  // turns all other btns off
			$(this).find('.btnDn').stop(true, true).fadeIn( 400 );
			setBox('1')
		});	
		$("#VehBtn").click(function() {
			$(".btnOuter").find('.btnDn').stop(true, true) .hide( 400 );  // turns all other btns off
			$(this).find('.btnDn').stop(true, true).fadeIn( 400 );
			setBox('2')
		});	
		$("#ReaBtn").click(function() {
			$(".btnOuter").find('.btnDn').stop(true, true) .hide( 400 );  // turns all other btns off
			$(this).find('.btnDn').stop(true, true).fadeIn( 400 );
			setBox('3')
		});	
		$("#JobBtn").click(function() {
			$(".btnOuter").find('.btnDn').stop(true, true) .hide( 400 );  // turns all other btns off
			$(this).find('.btnDn').stop(true, true).fadeIn( 400 );
			setBox('4')
		});	
		$("#EveBtn").click(function() {
			$(".btnOuter").find('.btnDn').stop(true, true) .hide( 400 );  // turns all other btns off
			$(this).find('.btnDn').stop(true, true).fadeIn( 400 );
			setBox('5')
		});	

	$("div.divFade8").hover(function() {
		$(this).stop(true,true).fadeTo(1000, 1);
	}, function() {
		$(this).stop(true,true).fadeTo(5000,0.5);
	});	

	$("#areaselected").hover(function() {
		$("#areahelp").stop(true, true) .animate( { opacity:0.9, height:'toggle', width:'toggle' }, 1000 ) ;
	}, function() {
		$("#areahelp").stop(true, true) .animate( { opacity:0.0, height:'toggle', width:'toggle' }, 300 );
	});	


	$("#selectedsearch").hover(function() {
		$("#advsearchhelp").stop(true, true) .animate( { opacity:0.9, height:'toggle', width:'toggle' }, 1000 ) ;
//		$("#advsearchhelp").stop(true, true) .show( 1000 );
	}, function() {
		$("#advsearchhelp").stop(true, true) .animate( { opacity:0.0, height:'toggle', width:'toggle' }, 300 );
//		$("#advsearchhelp").stop(true, true) .hide( 300 );
	});	

	$("#rtgenie_trigger").hover(function() {
		$("#rtgenie_content").stop(true, true) .show( 1000 );
		openEyes('r');
	}, function() {
		$("#rtgenie_content").stop(true, true) .hide( 300 );
		closeEyes('r');
	});	
	$("#lfgenie_trigger").hover(function() {
		$("#lfgenie_content").stop(true, true) .show( 1000 );
		openEyes('l');
	}, function() {
		$("#lfgenie_content").stop(true, true) .hide( 300 );
		closeEyes('l');
	});	
	$("#waiste_trigger").hover(function() {
		$("#waiste_content").stop(true, true) .show( 1000 );
		openEyes('b');
	}, function() {
		$("#waiste_content").stop(true, true) .hide( 300 );
		closeEyes('b');
	});	
	$("#glowinglamp").mouseenter(function() {
		$("#glowinglamp").stop(true, true).fadeTo( 800, 1);
		$("#lamp_content").stop(true, true).animate( { opacity:0.9, height:'toggle', width:'toggle' }, 1000 ) ;
		openEyes('b');
	});	
	$("#glowinglamp").mouseleave(function() {
		$("#glowinglamp").stop(true, true).fadeTo( 800, .05 );
		$("#lamp_content").stop(true, true).animate( { opacity:0.0, height:'toggle', width:'toggle' }, 800 );
		closeEyes('b');
	});	

	$("#majiccode").hover(function() {
		$("#codehelp").stop(true, true) .animate( { opacity:1, height:'toggle', width:'toggle' }, 1000 ) ;
	}, function() {
		$("#codehelp").stop(true, true) .animate( { opacity:0.0, height:'toggle', width:'toggle' }, 500 );
	});	

/*	$(".setArea").click(function(){
//		alert("GotIt");
		$("#selectArea").show(800);
		maketop("selectArea");
	});
*/
	$("#areaselected").hover(function(){
//		alert("GotIt");
		$("#areahelp").show(800);
	}, function() {
		$("#areahelp").hide(300);
	});

// majic genie services
	$("#servicesBtn").mouseenter(function() {
//		if( helpMenuOff == false) {
			$("#servicesBox").stop(true, true).show(800); //.animate( { opacity:1, height:'show' }, 800 ) ;
			$('#servU').stop(true, true).hide(800);
//		}
	});	
	$("#mainDiv").click(function() {
		$("#servicesBox").stop(true, true) .hide(800);
		$('#servU').stop(true, true).show(800);
	});	
	$(".closeSrvcBtn").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800);
		$(".rowBtn").stop(true, true).animate( { color:"#ccc" },0);
		$(".rowBtn").removeClass("selected");
	});	
// free services
	$("#srchPostAdsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800);
		$("#srchPostAdsBox").stop(true, true) .show(800);
		hilt2(this);
	});	
	$("#storeSalesAlertsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800);
		$("#storeSalesAlertsBox").stop(true, true) .show(800); 
		hilt2(this);
	});	
	$("#adAlertsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#adAlertsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#localEventsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#localEventsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#postEventsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#postEventsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#giftRegTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#giftRegBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#localAuctionTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#localAuctionBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#priceQuoteTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#priceQuoteBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#blogReviewsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#blogReviewsBox").stop(true, true).show(800);
		hilt2(this);
	});	
// paid services
	$("#postAdsCouponsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#paidAdsBox").stop(true, true).show(800); 
		hilt2(this);
	});	
	$("#emailListsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#emailListBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#alertInteractionsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#alertInteractBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#priceQuoteInteractTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#paidPriceReqBox").stop(true, true).show(800); 
		hilt2(this);
	});	
	$("#b2cB2bTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#b2cB2bBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#auctionsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#paidAuctionsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#additionalAdsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#addedPaidAdsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#busEventPostingTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#b2bEventsBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#freeBusListingTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#freeBusBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#fairDisplayTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#paidFairEqBox").stop(true, true).show(800);
		hilt2(this);
	});	
	$("#paidBlogsTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); // .animate( { opacity:0.0, height:0 }, 400 );
		$("#paidBlogsBox").stop(true, true).show(800); 
		hilt2(this);
	});	
	$("#adInfoTab").click(function() {
		$(".freeServicesBox, .paidServicesBox").stop(true, true).hide(800); 
		location.href = "adinfo.php";
		hilt2(this);
	});	
// for searchArea		
	$("#calcBtn").click(function(){
// alert("GotIt");
		updateZip();
	});

	$("input[name='zip1']").change( function() {
//alert("GotIt");
		updateZip();
	});
		
	$("input[name='radius']").change( function() {
//alert("GotIt");
		updateZip();
	});

function updateZip() {
	var zip_ = ($("input[name='zip1']").val());
	var radius_ = ($("input[name='radius']").val());
// todo
	var zipIn = ($("input[name='zipInMain']").val());
	var ip_ = ($("input[name='ip']").val());
	if( zipIn == "N" )
		$.post("_ajax/processSetIP2Zip.php", {zip:zip_, ip:ip_});
// alert("zip " + zip_ + "   radius " + radius_ ); 
	$("#zipResults").load("_php/search_area_selections/calcRadius.php?zip="+zip_+"&radius="+radius_ );
	$("#zipArrayResults-X").load("_php/search_area_selections/setZipArray.php" );
	$("#selectedAreaText").load("_php/search_area_selections/setSelectedAreaText.php" );
}

	$("#viewZips").click( function() {
		updateZip();
		$("#listZips").fadeIn(500, function() {
			$("#listZipsTxt").load("_php/search_area_selections/listZips.php" ); 
		} );
	});
/*			
	$("input:radio[id='a1']").change( function() { $("#setType").load("/_php/search_area_selections/setType.php?type=City" );	} );
	$("input:radio[id='a2']").change( function() { $("#setType").load("/_php/search_area_selections/setType.php?type=County" );	} );
	$("input:radio[id='a3']").change( function() { $("#setType").load("/_php/search_area_selections/setType.php?type=Zip" );	} );
*/
	$(".closeZipList").click( function() {
		$("#listZips").fadeOut(400);
	});
	
/*	$("input:radio[name='buyrent1']").change( function() { 
alert( "GotIt  value = " + ($(this).val()) );
		if( ($(this).val()) == "rent" )
			$('#condoAptCB1').parent().find( 'label' ).text( 'Apt&nbsp;&nbsp;' );
		else
			$('#condoAptCB1').parent().find( 'label' ).text( 'Condo' );
	});
*/

/*	$("#Select").click(function(){
//			alert("GotIt");
		var	zip = ($("input[name='zip1']").val());
		var radius = ($("input[name='radius']").val());
		$("#zipResults").load("/_php/search_area_selections/calcRadius.php?zip="+zip+"&radius="+radius );
		$("#zipArrayResults").load("/_php/search_area_selections/setZipArray.php" );
//		var searchAreaType = ($("input:radio[name='areaType1']:checked").val());
//		$("#selectedAreaText").load("/_php/search_area_selections/setSelectedAreaText.php?areaType="+searchAreaType );
		$("#selectedAreaText").load("/_php/search_area_selections/setSelectedAreaText.php" );
//		$("#selectArea").hide(300);
	});
*/
// function used by searchArea.php

	$("#searchBtn").click(function() {
		var srchArea = $("#selectedAreaText").text(); // search uses locatioin and optipno sessions data
		if(srchArea.substr(0,3) == 'UNK' || srchArea == '' || srchArea.substr(0,3) == "Not" ) {
			$('#searchErr').html('Area To Search is not set - select area to search');
			$('#searchErr').fadeTo(800,0.95).delay(5000).fadeOut(1200);
			return false;
		}
		var searchFor = ($("input[name='searchFor']").val());
//alert('searchArea: '+srchArea+'  searchFor: '+searchFor);
		var datastr = "page=home&searchFor="+searchFor;
//		alert( datastr );  exit;
		$.ajax({
			type: "GET",
			url: "_ajax/preProcessSearch.php",
			data: datastr,
			success: function(msg){  
				if( msg.substr(0,3) == "ERR" )
				{
					var errNo = msg.substr(3,1);
					var msg2 = msg.substr(5);
				//	if( errNo == 1 )
				//	{	// user name err
						$('#searchErr').html(msg2);
						$('#searchErr').fadeTo(800,0.95).delay(5000).fadeOut(1200);
						return false;
				//	}
				}
				// no error, means the subdir exists, so go display
				var url = "http://majicgenie.com"+ msg;
				location.href = url;
			}  
		});
	});	

	$("#searchBtn2").click(function() {
		var srchArea = $("#zipResults").text(); // search uses locatioin and optipno sessions data
		if(srchArea.substr(0,3) == 'UNK' || srchArea == '' || srchArea.substr(0,3) == "Not" ) {
			$('#searchErr2').html('Area To Search is not set - select area to search');
			$('#searchErr2').fadeTo(800,0.95).delay(5000).fadeOut(1200);
			return false;
		}
		var searchFor = ($("input[name='searchFor2']").val());
		
		// determine which category is selected
/*		if(Cat == 'Items' ) {
			// read newused  read auction
		}
		if(Cat == 'Vehicles' ) {
			// read vehicle inputs
			var makemodel_ = ($("#makemodel").val());
			var earliestyear_ = ($("#earliestyear").val());
			var latestyear_ = ($("#latestyear").val());
			var maxmiles_ = ($("#maxmiles").val());
			var minprice_ = ($("#minprice").val());
			var maxprice_ = ($("#maxprice").val());
			var newu = ($("input:radio[name='Vseller']:checked").val());
			$.post("processSetVehicle.php", {makemodel:makemodel_, earliestyear:earliestyear_, latestyear:latestyear_, maxmiles:maxmiles_, mminmiles:minmiles_ });
		}
		if(Cat == 'Real Estate' ) {
			// read re inputs
			var acreageCB_ = "N";
			if( $('#acreageCB').attr('checked') )	acreageCB_ = "Y";
			
			var pricemin_ = "";
			var pricemax_ = "";
			var acreagemin_ = "";
			if( acreageCB_ == "Y" ) {
				pricemin_ = ($("#apricemin").val());
				pricemax_ = ($("#apricemax").val());
				acreagemin_ = ($("#aacreagemin").val());
			} else {
			
				var sfrCB_ = "N";
				if( $('#sfrCB').attr('checked') )	sfrCB_ = "Y";
				var condoAptCB_ = "N";
				if( $('#condoAptCB').attr('checked') )	condoAptCB_ = "Y";
				var duplexCB_ = "N";
				if( $('duplexCB').attr('checked') )	duplexCB_ = "Y";
				var townhouseCB_ = "N";
				if( $('townhouseCB').attr('checked') )	townhouseCB_ = "Y";
				var mobilehomeCB_ = "N";
				if( $('mobilehomeCB').attr('checked') )	mobilehomeCB_ = "Y";
				var officeCB_ = "N";
				if( $('officeCB').attr('checked') )	officeCB_ = "Y";

				var buyrent_ = ($("input:radio[name='buyrent']:checked").val());

//				var _ = "N";
//				if( $('').attr('checked') )	_ = "Y";
				var ownercarryCB_ = "N";
				if( $('ownercarryCB').attr('checked') )	ownercarryCB_ = "Y";

				var REseller_ = ($("input:radio[name='REseller']:checked").val());

				var br_ = ($("#br").val());
				var ba_ = ($("#ba").val());
				var sf_ = ($("#sf").val());

				pricemin_ = ($("#pricemin").val());
				pricemax_ = ($("#pricemax").val());
				acreagemin_ = ($("#acreagemin").val());
			}
			$.post("processSetRealEstate.php", {acreageCB:acreageCB_, pricemin:pricemin_, pricemax:pricemax_, acreagemin:acreagemin_, 
				sfrCB:sfrCB_, condoAptCB:condoAptCB_, duplexCB:duplexCB_, townhouseCB:townhouseCB_, mobilehomeCB:mobilehomeCB_,
				officeCB:officeCB_,	buyrent:buyrent_, ownercarryCB:ownercarryCB_, REseller:REseller_, br:br_, ba:ba_, sf:sf_});
		}
		if(Cat == 'Events' ) {
		}
//		if(Cat == 'Jobs' ) {
//		}
		
//	var url = "http://majicgenie.com/search.php";
//	location.href = url;
		
		var datastr = "page=search&searchFor="+searchFor;
//		alert( datastr );  exit;
		$.ajax({
			type: "GET",
			url: "preProcessSearch.php",
			data: datastr,
			success: function(msg){  
				if( msg.substr(0,3) == "ERR" )
				{
					var errNo = msg.substr(3,1);
					var msg2 = msg.substr(5);
				//	if( errNo == 1 )
				//	{	// user name err
						$('#searchErr').html(msg2);
						$('#searchErr').fadeTo(800,0.95).delay(4000).fadeOut(1200);
						return false;
				//	}
				}
				// no error, means the subdir exists, so go display
				var url = "http://majicgenie.com"+ msg;
				location.href = url;
			}  
		});
*/	});	

// - majic code btn
	$("#goBtn").click(function() {
// alert('me');
		var majicCode = ($("input[name='mCode']").val());
		if( majicCode.length <1 )
			return false;
		var datastr = "majic="+majicCode;
//	alert( datastr );  //  exit;
		$.ajax({
			type: "GET",
			url: "_ajax/processMajic.php",
			data: datastr,
			success: function(msg){  
				if( msg.substr(0,3) == "ERR" )
				{
					var errNo = msg.substr(3,1);
					var msg2 = msg.substr(5);
				//	if( errNo == 1 )
				//	{	// user name err
						$('#codeErrTxt').html(msg2);
						$('#codeErr').fadeTo(800,0.95);//.delay(4000).fadeOut(1200);
						return false;
				//	}
				}
				// no error, means the subdir exists, so go display
				var url = "http://majicgenie.com"+ msg;
				location.href = url;
			}  
		});
	});	
	
	$("#closeBox").click(function(){
		$('#codeErr').fadeOut(800);
	});
	
	$("#mygenieA").click(function() {
		var user_ = $.cookie('user').split(";"); // get cookie 'user' where data is all in one line, sep by ';', read into array
		var url = user_[3] + "/mygenie.php";   // user_[3] = accDir 
		location.href = url;
	});

// -- pre-process suggestionLamp
/*	$('#sugPG').keypress(function(e) {
		code = e.keyCode ? e.keyCode : e.which;
		if(code.toString() == 13) {
			sendSug();		// process form if hit key, or enter
		}
	});
*/
	$("#sendSugBtn").click(function(){
		sendSug();
	});
function sendSug() {
//			alert("GotIt");
		$("#errCap").hide();	// reset any error

	// get data from form
		if( captcha == '' ){
			$("#errCap").show();	// no btn selected, report error and return
			refreshCap();
			return false;
		}
		var	sugbus = ($("input:radio[name='sugtype']:checked").val());
		var eml = ($("input[name='email']").val());
		var busname = ($("input[name='busname']").val());
		var msg = ($("textarea[name='msg']").val());
//		var captcha = ($("input:radio[name='s3capcha']:checked").val());
//alert("captcha = "+captcha);
		var datastr = "sugbus="+sugbus+"&eml="+eml+"&busname="+busname+"&msg="+msg+"&captcha="+captcha+"&refresh=0";
//	alert( datastr );
//exit;			//show the loading sign  
//			$('#loading').show();	// hidden div w/ animated gif to show loading...  
			//start the ajax  - have php ck captcha
		$.ajax({
			type: "GET",
			url: "_ajax/suggestion.php",
			data: datastr,
			success: function(msg){  
//				  $("#note").ajaxComplete(function(event, request, settings){ 
				var msg2 = msg.substr(0,2); 
				if( msg2 == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
				{
//alert("("+msg+") ok - for test we do nothing");
//return false;
					refreshCap();		// in case the user sends, then comes back to send again, a new captcha is setup 
					$("#sugPG").hide(800).delay(5200);
					$("#sentmsg").show(800).delay(5200);		// after fades in, wait for 4 seconds (fadeTo ?) then fade out the suggestionLamp div al together
					$("#sugLamp").delay(4100).fadeOut(2000);
				}else{
// alert("("+msg+") ERROR");
					$("#errCap").show();
					refreshCap();
					return false;
				}
//					$(this).html(result);
//				  });
				}  
			});
//			$("#sugResults").load("/_php/ajax-processes/suggestion.php?sugbus="+sugbus+"&email="+eml+"&busname="+busname+"&msg="+msg+"&captch="+captcha );
		}

/*	$("#bkgnd).click(function() {
		if
	});
*/		

function hideServices()
{
	$("#servicesBox").hide(); // .animate( { opacity:0.0, height:'toggle' }, 0 );
}
		
function setBox( typeCat )
{
	var newu = ($("input:radio[name='newused']:checked").val());
	var auc = ($("input:radio[name='auction']:checked").val());
	if( typeCat == 1 )
	{
		$("#items").show(1000);
		$("#vehicle").hide(1000);
		$("#realestate").hide(1000);
		$("#jobs").hide(1000);
		$("#events").hide(1000);
		$("#nuauc").show(1000);
		$("#refurb_div").show(1000);
		Cat = "Items";
	}
	if( typeCat == 2 )
	{
		$("#items").hide(1000);
		$("#vehicle").show(1000);
		$("#realestate").hide(1000);
		$("#jobs").hide(1000);
		$("#events").hide(1000);
		$("#nuauc").show(1000);
		$("#refurb_div").hide(1000);
		Cat = "Vehicles";
	}
	if( typeCat == 3 )
	{
		$("#items").hide(1000);
		$("#vehicle").hide(1000);
		$("#realestate").show(1000);
		$("#jobs").hide(1000);
		$("#events").hide(1000);
		$("#nuauc").show(1000);
		$("#refurb_div").hide(1000);
		Cat = "Real Estate";
	}
	if( typeCat == 4 )
	{
		$("#items").hide(1000);
		$("#vehicle").hide(1000);
		$("#realestate").hide(1000);
		$("#jobs").show(1000);
		$("#events").hide(1000);
		$("#nuauc").hide(1000);
		$("#refurb_div").hide(1000);
		Cat = "Jobs";
		newu = 'none';
		auc = 'none';
	}
	if( typeCat == 5 )
	{
		$("#items").hide(1000);
		$("#vehicle").hide(1000);
		$("#realestate").hide(1000);
		$("#jobs").hide(1000);
		$("#events").show(1000);
		$("#nuauc").hide(1000);
		$("#refurb_div").hide(1000);
		Cat = "Events";
		newu = 'none';
		auc = 'none';
	}
	$.post("_ajax/processSetCategory.php", {category:Cat, newused:newu, auction:auc });
}

// animation for Genie to fade in on page enter
function genieHide( delay_, duration_ ) {
	// open eyes (hide the closed eye imgs)
	enSH= false;
	$("#lfEyeCls, #rtEyeCls").fadeOut(0);
	// hide genie in the lamp
	enEA = false;		// disables displaying folded arms and eyes when over an action button (showing genie will enable)
	$("#geniebody").delay(delay_).animate( {top:285, left:286, opacity:0}, duration_, function(){enSH=true;} );
	$("#geniebody_img").delay(delay_).animate( {width:2, height:3}, duration_ );		

	$("#crossarms").delay(delay_).animate( {top:290, left:286, opacity:0}, duration_ );
	$("#crossarms_img").delay(delay_).animate( {height:1, width:1}, duration_ );
}
function genieShow( delay_, duration_ ) {
	enSH= false;
	$("#geniebody").delay(delay_).animate( {top:-3, left:186, opacity:1}, duration_, function(){enEA=true; enSH=true;} );
	$("#geniebody_img").delay(delay_).animate( {width:156, height:288}, duration_ );		

	$("#crossarms").delay(delay_).animate( {top:71, left:200, opacity:1}, {duration: duration_} ); // .delay(4000).fadeOut(1000);
	$("#crossarms_img").delay(delay_).animate( {height:81, width:121}, duration_ );

	// blink the eyes   and then go to sleep after delay
	$("#lfEyeCls").delay(delay_+duration_).fadeIn(200).delay(100).fadeOut(200).delay(2000).fadeIn(200).delay(200).fadeOut(200).delay(1000).fadeIn(200).delay(300).fadeOut(200).delay(500).fadeIn(200);
	$("#rtEyeCls").delay(delay_+duration_).fadeIn(200).delay(100).fadeOut(200).delay(2000).fadeIn(200).delay(200).fadeOut(200).delay(1000).fadeIn(200).delay(300).fadeOut(200).delay(500).fadeIn(200);
}

function showSuggestion( typeSug )
{
	if( typeSug == 1 )
	{
		$(".sug").show(1000);
		$(".biz").hide(1000).removeClass('divFade8');
	}else{
		$(".sug").hide(1000);
		$(".biz").addClass('divFade8').show(1000);
	}
}

	$("#searchBtn, #goBtn").mouseenter( function() {
		openEyes('b');
		arms('folded');	
	});
	$("#searchBtn, #goBtn").mouseleave( function() {
		closeEyes('b');
		arms('crossed');	
	});
	
function openEyes( eye ) {
	if( (eye == "l" || eye == 'b') && enEA )
		$("#lfEyeCls").stop(true, true).fadeOut(200);//.delay(24000).fadeIn(200);
	if( (eye == "r" || eye == 'b') && enEA )
		$("#rtEyeCls").stop(true, true).fadeOut(200);//.delay(24000).fadeIn(200);
}
function closeEyes( eye ) {
	if( (eye == "l" || eye == 'b') && enEA )
		$("#lfEyeCls").stop(true, true).fadeIn(200);
	if( (eye == "r" || eye == 'b') && enEA )
		$("#rtEyeCls").stop(true, true).fadeIn(200);
}
function arms( arms_ ) {
	if( enEA ) {
		if( arms_ == "folded" ) {
			$("#foldedarms").stop(true, true).fadeIn(1000);
			$("#crossarms").stop(true, true).fadeOut(1000);
		}else{
			$("#foldedarms").stop(true, true).fadeOut(1000);
			$("#crossarms").stop(true, true).fadeIn(1000);
		}
	}
}



