var reNumbers = /^[0-9]*$/;
var reNumbers = /^[0-9]*$/;

function only_numbers(string){
   return reNumbers.test(string);
}

var twoWords = /^.+\s+.+$/;

function has_two_words(string){
   return twoWords.test(string);
}

var reTextNumbers = /^[a-zA-Z0-9_.-]*$/;

function only_alphanumeric(string){
	return reTextNumbers.test(string);
}

var reEmail = /^[a-zA-Z\-\_\.0-9]+\@[a-zA-Z\-\_\.0-9]+[a-zA-Z0-9]\.[a-zA-Z]{2,4}$/;

function is_email(string){
   return reEmail.test(string);
}

function verify_username(element, message, only_img, id, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('username too small','username OK!');
	}
	
	if($("#"+element).val().length==0){
		if(only_img) document.getElementById(id).innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else document.getElementById(id).innerHTML = message;
	}
	else if($("#"+element).val().length<4){
		if(only_img) document.getElementById(id).innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else{
			document.getElementById(id).innerHTML = labels[0];
			$("#reg_verify_username_txt").addClass("red");
		}
	}
	else{
		$.get("/ax_verify_username.php", {username: $("#"+element).val(), only_img: only_img},
			function(data){
				if(data!='ok'){
					$("#"+id).html(data);
					$("#reg_verify_username_txt").addClass("red");
					$("#reg_verify_username_txt").removeClass("green");
				}else{
					$("#"+id).html(labels[1]);
					$("#reg_verify_username_txt").removeClass("red");
					$("#reg_verify_username_txt").addClass("green");
				}
		});
	}
}

function verify_email(element, message, only_img, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('email incorrect format','email OK!');
	}
	
	if($("#"+element).val().length==0){
		if(only_img) document.getElementById('reg_verify_email_txt').innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else document.getElementById('reg_verify_email_txt').innerHTML = message;
	}
	else if(!is_email($("#"+element).val())){
		if(only_img) document.getElementById('reg_verify_email_txt').innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else{
			document.getElementById('reg_verify_email_txt').innerHTML = labels[0];
			$("#reg_verify_email_txt").addClass("red").removeClass("green");
		}
	}
	else{
		$.get("/ax_verify_email.php", {email: $("#"+element).val(), only_img: only_img},
			function(data){
				if(data!='ok'){
					$("#reg_verify_email_txt").addClass("red")
								  .removeClass("green")
								  .html(data);
				}else{
					$("#reg_verify_email_txt").removeClass("red")
								  .addClass('green')
								  .html(labels[1]);
				}
		});
	}
}

function verify_pass(element, message, only_img, id,labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('password too small','password OK!');
	}
	
	if($("#"+element).val().length==0){
		if(only_img) document.getElementById(id).innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else document.getElementById(id).innerHTML = message;
	}
	else if($("#"+element).val().length<4){
		if(only_img) document.getElementById(id).innerHTML = "<img src='/images/icn_warning.gif' width='20' height='15'>";
		else{
			document.getElementById(id).innerHTML = labels[0];
			$("#"+id).removeClass('green');
			$("#"+id).addClass("red");
		}
	}
	else{
		//document.getElementById(id).innerHTML = "<img src='/images/icn_tick.gif' width='20' height='15'>";
		document.getElementById(id).innerHTML = labels[1];
		$("#"+id).removeClass("red").addClass('green');
	}
}

// JQUERY DROP DOWN MENU

var timeout         = 100;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open(){
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $('#jsddm_tool').find('ul').eq(0).css('visibility', 'visible');
}



function jsddm_dg_open(){
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $('#jsddm_tool_dg').find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_hd_open(){
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $('#jsddm_hd').find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close(){
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

///////////
function ddm_open(){
	ddm_canceltimer();
	ddm_close();
	ddmenuitem = $('#ddm_cog').show();
}
function ddm_close(){
	if(ddmenuitem) ddmenuitem.hide();
}
function ddm_timer(){
	closetimer = window.setTimeout(ddm_close, timeout);
}
function ddm_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
//////////////////
function toogle(element){
	$(element).toggle();
}

function show(element, popin){
	if(popin==null) popin = 0;

	if(popin) $('#main').prepend('<div class="popin_Darkener"></div>');

	$(element).show();
}

function hide(element, popin){
	if(popin==null) popin = 0;

	$(element).hide();
	if(popin) $('.popin_Darkener').remove();
}

function series_sel(car_id, series_id){
	/*$.get("/ax_car_save_series.php?series_id="+series_id+"&car_id="+car_id);
	$("#choose_series").hide();
	$("#choose_version").show();*/
	$.get("/ax_car_save_series.php", {series_id: series_id, car_id: car_id},
		function(data){
			$("#choose_series").hide();
			if(data!=""){
				$("#ncar_version").html(data);
				$("#choose_version").show();
			}
	});
}

function version_sel(car_id,reload_page, empty_message){
	versionid = $("#ncar_version").val();
	if(versionid==0){
		autoviva_alert(empty_message);
		return false;
	}
	else{
		document.location.href = "/ax_car_save_version.php?version_id="+versionid+"&car_id="+car_id;
	}
}

function toggle_change_class(element, item, style){
	var $element	= $(element);
	var $item	= $(item);
	$element.toggle();
		if ($item.hasClass(style)){
			$item.removeClass(style);
			if(style=="opened") $item.addClass('closed');
		}
		else{
			$item.addClass(style);
			if(style=="opened") $item.removeClass('closed');
		}
		console.timeEnd('test');
	return false;
}
function simple_change_class(item, style){
	var $item = $(item);
		if ($item.hasClass(style)){
			$item.removeClass(style).addClass(style+'_hover');
		}
		else{
			$item.removeClass(style+'_hover').addClass(style);
		}
	return false;
}
function changeSelections(num){
	if (document.getElementById('check_all').checked){
		for (var id = 0; id <= num; id++){
			if (document.getElementById('check_'+id) != null){
				document.getElementById('check_'+id).checked = true;
			}
		}
	}
	else{
		for (var id = 0; id <= num; id++){
			if (document.getElementById('check_'+id) != null){
				document.getElementById('check_'+id).checked = false;
			}
		}
	}
	return true;
}

function change_class(element, clicked){
	var $tools_element = $("#tools_"+element);
	if(clicked){
		if ($tools_element.hasClass("tools_"+element)){
			$tools_element.removeClass("tools_"+element)
				      .addClass("tools_"+element+"_sel");
		}
		else{
			$tools_element.removeClass("tools_"+element+"_sel")
				      .addClass("tools_"+element);
		}
	}
	else{
		$tools_element.removeClass("tools_"+element)
			      .addClass("tools_"+element+"_sel");
	}
}

function select_class(element, clicked){
	var $element = $("."+element);
	if(clicked){
		if ($element.hasClass(element)){
			$element.addClass(element+"_sel").removeClass(element);
		}
		else{
			$("."+element+"_sel").addClass(element).removeClass(element+"_sel");			
		}
	}
	else{
		$element.addClass(element+"_sel").removeClass(element);
	}
}

function fan(type, id, clicked, total, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('you are now a fan','This member is your buddy.','you don\'t have permission to access to this content');
	}
	
	$.getJSON("/ax_fan_"+type+".php", {id: id, clicked: clicked},
		function(data){
			if(data.status=="true"){
				select_class("gray_item_like", clicked);
				if(total==0) $("#become_fan_txt").html(labels[0]);
				/*if($('.white_item_bg_like_sel').length) $('.white_item_bg_like_sel').removeClass('white_item_bg_like_sel');
				else $('.white_item_bg_like').addClass('white_item_bg_like_sel');*/
			}
			else if(clicked && data.value=="already_buddy"){
				show('#pin_'+type+'_popin_fan');
				$("#pin_"+type+"_popin_fan_data").html('<div class="float_left"><img src="/images/popin_warning.png" width="55" height="55" alt="" title="" border="0" style="margin-right:10px;float:left"/><span style="float:left">' + labels[1] + '</span></div>');
			}
			else if(clicked && data.value=="no_perm"){
				show('#pin_'+type+'_popin_fan');
				$("#pin_"+type+"_popin_fan_data").html('<div class="float_left"><img src="/images/popin_warning.png" width="55" height="55" alt="" title="" border="0"/><br /><br /><span style="float:left">' + labels[2] + '</span></div>');
			}
			else if(clicked) show('#pin_'+type+'_popin_fan');
	});
	$('.tools_fan_sel').corner("3px");
	$('.tools_fan').corner("3px");
}

function buy_version(id, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('sell car','This version was bought and added your dream garage');
	}
	
	$.getJSON("/ax_add_dream_garage.php", {id: id},
		function(data){
			if(data.status=="true"){
				//$("#pin_version_key_data").html(data.message);
				//change_class("key", 1);
				$('#tools_key').html(labels[0]);
				createAndShowPopin('','default_form_success',labels[1]);
			}
	});
}

function remove_version(id){
	$.getJSON("/ax_add_dream_garage.php", {id: id},
		function(data){
			if(data.status=="true"){
				$("#pin_version_key_data").html(data.message);
				change_class("key", 1);
				setTimeout(function() {
					$('#pin_version_key').fadeOut('slow');
				}, 2000);
			}
	});
}

function key(type, id, clicked){
	if(clicked){
		//show('#pin_version_key');
		createAndShowPopin('ax_popin_buy_sell_car.php?car_id='+id,'');
	}
	else{
		$.get("/ax_check_dream_garage.php",
			function(data){
				if(data=="true"){
					change_class("key", 0);
				}
		});
	}
}

function give_car(id, isgift, hpverion, from_tools, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('This version was sent as an offer for your friends approval.');
	}
	
	buddy_id = $("#buddy_userid").val();
	if(!buddy_id) buddy_id = $("#gift_buddy_userid").val();
	$.getJSON("/ax_give_car.php", {id: id, buddy_userid: buddy_id, gift:isgift},
		function(data){
			if(data.status=="true"){
				$("#pin_version_give_data").html(data.message);
				if(hpverion==1 && isgift==1){
					//change_class("key", 1);
				}
				if(from_tools==1){
					createAndShowPopin('','default_form_success', labels[0]);
				}
			}
			else{
				$("#pin_version_give_data_warn").html(data.message);
				if(from_tools){
					createAndShowPopin('','default_form_error',data.message);
				}
			}
	});
}

function gift(type, id, clicked){
	//show('#pin_version_give');
	createAndShowPopin('ax_popin_give_car.php?car_id='+id,'');
}

function send(type, id, clicked){
	createAndShowPopin('ax_popin_send_pm.php?member_id='+id,'');
	//show('#pin_'+type+'_msg', 1);
	/*var settings = {
		tl: { radius: 5 },
		tr: { radius: 5 },
		bl: { radius: 5 },
		br: { radius: 5 },
		antiAlias: false
	}
	curvyCorners(settings, '#pin_'+type+'_msg');*/
}

function send_message(type, ref_id){
	title=$("#c_title").val();
	msg=$("#c_msg").val();
	$("#pin_"+type+"_msg_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_send_pm.php", {user_id: ref_id, pm_title: title, pm_text: msg},
		function(data){
			//if(data.status=="true"){
				//createAndShowPopin('','default_form_success','Your message has been sent');
				createAndShowPopin('ax_popin_generic_content.php?content='+data.message,'');
			//}else{
				//createAndShowPopin('','default_form_error','Message failed...');
			//}
	});
}

var send_comment_error=0;
function send_comment(type, req_id, unique_id, style, return_feed, from_wiki){
	if(!return_feed) return_feed = 0;
	if(!from_wiki) from_wiki = 0;
	old_html=$("#div_btn_comm_"+unique_id).html();
	$("#div_btn_comm_"+unique_id).html(img_loader(17));
	msg=$("#comm_msg_"+unique_id).val();
	$.getJSON("/ax_send_comment.php", {id: req_id, msg: msg, type: type, style: style, unique_id:unique_id, return_feed:return_feed, from_wiki:from_wiki, href:document.location.href},
		function(data){
			if(data.status>0){
				if(return_feed && !from_wiki) $("#feeds_list").prepend(data.message);
				$("#list_comm_"+unique_id).append("<div>"+data.message+"</div>");
				show("#add_comm_"+unique_id);
				$('#add_comm_inline_'+unique_id).show();
				$("#comm_msg_"+unique_id).val('');
				$("#error_comm_"+unique_id).html('');
				$("#error_comm_"+unique_id).removeClass("error_comm");
				$("#div_btn_comm_"+unique_id).html(old_html);
				if(style=='feed') hide('#form_comm_'+unique_id);
			}else if(data.status==0){
				createAndShowPopin('','default_form_error',data.message);
			}else if(data.status==-1){
				createAndShowPopin('register.php?ajax=true&hide_x=false'+data.message);
				$("#div_btn_comm_"+unique_id).html(old_html);
			}
		}
	);
}

function delete_comment(comment_id, container_id, unique_id){
	$.get("/ax_delete_comment.php", {comment_id: comment_id},
		function(data){
			if(data=='ok'){
				$("#"+container_id).remove();
				$('#add_comm_inline_'+unique_id).show();
				$("#add_comm_"+unique_id).hide();
			}
	});
}

function more_comments_list(req_id, type, unique_id, style){
	if(type!='photo' && type!='video') $("#all_comm_"+unique_id).html(img_loader(17));
	else $("#loading_comm_"+unique_id).html(img_loader(17));
	$.get("/ax_comments_more.php", {id: req_id, type: type, style: style},
		function(data){
			if(type!='photo' && type!='video') $("#all_comm_"+unique_id).hide();
			else{
				$("#loading_comm_"+unique_id).hide();
				$("#link_all_comm_"+unique_id).hide();
			}
			$("#list_comm_"+unique_id).prepend(data);
	});
}

function add(type, id, clicked, isbuddy){
	if(isbuddy==1){
		show('#pin_'+type+'_remove_buddy', 1);
	}
	else{
		show('#pin_'+type+'_buddy', 1);
	}
}

function confirm_add_friend(member_id){
	createAndShowPopin("ax_popin_confirm_send_friendship_request.php?id="+member_id,"","");
}

function add_friend_popin(member_id, element, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('request sent');
	}
	
	$("#"+element).html(img_loader(10));
	$.getJSON("/ax_send_friendship_request.php", {member_id: member_id},
		function(data){
			if(data.status==-1){
				createAndShowPopin("ax_popin_login.php","","#reg_username");
			}else if(data.status==0){
				$("#parent_"+element).html(data.ajax_message);
			}else if(data.status==1){
				$("#parent_"+element).html(labels[0]);
			}
	});
}

function add_friend(member_id){
	$("#pin_member_buddy_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_send_friendship_request.php", {member_id: member_id},
		function(data){
			if(data.status==-1){
				createAndShowPopin("ax_popin_login.php","","#reg_username");
			}else if(data.status==0){
				createAndShowPopin('','default_form_error',data.message);
			}else if(data.status==1){
				createAndShowPopin("ax_popin_send_friendship_success.php?id="+member_id,"","");
			}
	});
}

function remove_friend(member_id){
	$.getJSON("/ax_remove_friend.php", {member_id: member_id},
		function(data){
			if(data.status==-1){
				createAndShowPopin("ax_popin_login.php","","#reg_username");
			}else if(data.status==0){
				createAndShowPopin('','default_form_error',data.message);
			}else if(data.status==1){
				createAndShowPopin('','default_form_success',data.message);
			}
	});
}

function treat(type, id, clicked){
	/*toogle('#pin_'+type+'_treat');
	var settings = {
		tl: { radius: 5 },
		tr: { radius: 5 },
		bl: { radius: 5 },
		br: { radius: 5 },
		antiAlias: false
	}
	curvyCorners(settings, '#pin_'+type+'_treat');*/
	if(type=="member") createAndShowPopin('ax_popin_display_honks.php?member_id='+id, '');
	else createAndShowPopin('ax_popin_display_honks_car.php?car_id='+id, '');
}

function give_treat(id, treat_id, member){
	$("#pin_car_treat_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_give_treat.php", {req_id: id, treat_id: treat_id, is_member:member},
		function(data){
			/*if(data.status=="true"){
				createAndShowPopin('','default_form_success','Your honk has been sent');
			}else{
				createAndShowPopin('','default_form_error','Your honk failed...');
			}*/
			createAndShowPopin('ax_popin_generic_content.php?content='+data.message,'');
	});
}

function dg_get_space(){
	show('#pin_db_buy_spaces');
}

function dg_buy_spaces_recalc(vivas_garage, vivas_paddock, vivas_balance){
	if($("#packs_garage").val()<0) $("#packs_garage").val()=0;
	if($("#packs_paddock").val()<0) $("#packs_paddock").val()=0;
	total_costs_garage=vivas_garage*$("#packs_garage").val();
	total_costs_paddock=vivas_paddock*$("#packs_paddock").val();
	tcosts=total_costs_garage+total_costs_paddock;
	$("#total_costs").html(tcosts);
	$("#balance").html((vivas_balance-tcosts));
	if(tcosts>vivas_balance){
		$("#balance").css("color", "red");
		$("#submit").hide();
	}
}

function dg_buy_spaces_frm_old(num_garage_spaces, num_paddock_spaces, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('garage spaces','paddock spaces');
	}
	packs_garage_val = $("#packs_garage").val();
	packs_paddock_val = $("#packs_paddock").val()
	$("#pin_db_buy_spaces_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_buy_spaces.php", {packs_garage: packs_garage_val, packs_paddock: packs_paddock_val},
		function(data){
			$("#pin_db_buy_spaces_data").html(data.message);
			if(data.status=="true"){
				num_garage_spaces_val = num_garage_spaces + packs_garage_val * 4;
				num_paddock_spaces_val = num_paddock_spaces + packs_paddock_val * 2;
				$("#garage_spaces_txt").html(num_garage_spaces_val+' ' + labels[0]);
				$("#paddock_spaces_txt").html(num_paddock_spaces_val+' '+labels[1]);
				setTimeout(function() {
					$('#pin_db_buy_spaces').fadeOut('slow');
				}, 2000);
			}
	});
}

function dg_buy_spaces_frm(type, num_garage_spaces, num_paddock_spaces, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('garage spaces','paddock spaces');
	}
	
	packs_paddock_val=0;
	packs_garage_val=0;
	if(type=="paddock") packs_paddock_val=1;
	else packs_garage_val=1;
	$("#pin_db_buy_spaces_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_buy_spaces.php", {packs_garage: packs_garage_val, packs_paddock: packs_paddock_val},
		function(data){
			$("#pin_db_buy_spaces_data").html(data.message);
			if(data.status=="true"){
				num_garage_spaces_val = num_garage_spaces + packs_garage_val * 4;
				num_paddock_spaces_val = num_paddock_spaces + packs_paddock_val * 2;
				$("#garage_spaces_txt").html(num_garage_spaces_val+' ' + labels[0]);
				$("#paddock_spaces_txt").html(num_paddock_spaces_val+' ' + labels[1]);
				setTimeout(function() {
					$('#pin_db_buy_spaces').fadeOut('slow');
				}, 2000);
			}
	});
}

function welcome_dismiss(){
	$.get("/ax_dismiss_welcome.php",
		function(data){
			if(data=="true"){
				hide('#welcome');
				show('#hp_articles');
			}
	});
}

function welcome_shop_dismiss(){
	$.get("/ax_dismiss_welcome_shop.php",
		function(data){
			if(data=="true"){
				hide('#welcome_shop');
			}
	});
}

function welcome_wiki_dismiss(){
	$.get("/ax_dismiss_welcome_wk_contribute.php",
		function(data){
			if(data=="true"){
				hide('.wiki_contribute');
			}
	});
}

function switch_bio_member(){
	var $bio_member_title = $("#bio_member_title");
	if ($bio_member_title.hasClass("rightarrow")){
		$bio_member_title.removeClass("rightarrow").addClass("downarrow");
	}
	else{
		$bio_member_title.removeClass("downarrow").addClass("rightarrow");
	}
	toogle('#bio_member');
}

function switch_bio_car(){
	var $bio_car_title = $("#bio_car_title");
	if ($bio_car_title.hasClass("title_closed")){
		$bio_car_title.removeClass("title_closed").addClass("title_opened");
	}
	else{
		$bio_car_title.removeClass("title_opened").addClass("title_closed");
	}
	toogle('#bio_car');
}
function rb_makes_switch(){
	var $rb_make_browser = $("#rb_make_browser");
	if ($rb_make_browser.hasClass("closed")){
		$rb_make_browser.removeClass("closed").addClass("opened");
		//$("#rb_make_letters").show();
		$("#rb_make_display").show();
	}
	else{
		$rb_make_browser.removeClass("opened").addClass("closed");
		//$("#rb_make_letters").hide();
		$("#rb_make_display").hide();
		rb_makes_load_makes_first_run = true;
	}
}

function switch_open_close(element_title, element_block){
	var $element_title = $(element_title);
	if ($element_title.hasClass("closed")){
		$element_title.removeClass("closed").addClass("opened");
		$(element_block).show();
	}
	else{
		$element_title.removeClass("opened").addClass("closed");
		$(element_block).hide();
	}
}

var rb_makes_load_makes_first_run = true;
function rb_makes_load_makes(letter, closed){
	$("#rb_make_browser").removeClass("closed");
	$("#rb_make_browser").addClass("opened");
	if(!rb_makes_load_makes_first_run) $("#rb_make_display").height($("#rb_make_display").height());
	$("#rb_make_display").html('<center>'+img_loader(17)+'</center>');
	$("#rb_make_letters .letter").removeClass("letter_sel");
	$("#letter_"+letter).addClass("letter_sel");		
	$.get("/ax_get_makes.php", {first_letter: letter},
		function(data){
			$("#rb_make_display").html(data);
			if(!rb_makes_load_makes_first_run){
				$("#rb_make_display table").hide();
				$("#rb_make_display").animate({
					height: $("#rb_make_display table").height()+15
					}, 150, function(){	
						$("#rb_make_display table").fadeIn('fast');
				});
			}else{
				$("#rb_make_display").css('height','');
				$("#rb_make_display").show();
			}
			rb_makes_load_makes_first_run = false;
			if(closed) rb_makes_switch();
	});
}


function change_html_element(element, type, id, url){
	$.get("/ax_change_html_element.php", {type: type, id: id, url:url},
		function(data){
			$(element).html(data);
	});
}

function select_element(name, id, img, title){
	document.getElementById(name).value=id;
	document.images['img_mycars_combo'].src = img;
	$("#txt_mycars_combo").html(title);
	hide('#pin_combo');
}

function tooltip(element, spikePosition, pointX, position, margin, bgColor, strokeColor, width, fontColor, fontSize, textAlign, spaceTop, padding, spikeLength, spikeGirth, trigger, fontWeight){

	if(bgColor==null) bgColor='#434343';
	if(strokeColor==null) strokeColor='#434343';
	if(margin==null) margin='40px';
	if(width==null) width='100px';
	if(fontSize==null) fontSize='12px';
	if(fontColor==null) fontColor='#fff';
	if(spikePosition==null) spikePosition='0.5';
	if(pointX==null) pointX='0.18';
	if(position==null) position='top';
	if(textAlign==null) textAlign='left';
	if(spaceTop==null) spaceTop=$(element).outerHeight();
	if(padding==null) padding=8;
	if(spikeLength==null) spikeLength=10;
	if(spikeGirth==null) spikeGirth=15;
	if(trigger==null) trigger='hover';
	if(fontWeight==null) fontWeight='bold';

	$(element).bt({
	  trigger:trigger,
	  width:width,
	  fill: bgColor,
	  spaceTop:spaceTop,
	  strokeStyle: strokeColor,
	  strokeWidth:1,
	  spikeLength: spikeLength,
	  spikeGirth: spikeGirth,
	  padding: padding,
	  cornerRadius: 0,
	  spikePosition:spikePosition,
	  centerPointX:pointX,
	  positions: [position],
	  cssStyles: {
	    fontFamily: '"verdana"',
	    fontWeight:fontWeight,
	    textAlign:textAlign,
	    fontSize: fontSize,
	    color:fontColor,
		marginLeft: margin
	  }
	});
}

function makes_feeds_list(){
	$("#feeds_list").show();
	$("#feeds_list").html("<center>"+img_loader(17)+"</center>");
	$.get("ax_get_feeds.php",
		function(data){
			$("#feeds_list").html(data);
	});
}

function feeds_list(tab, type, extra_id, default_text){
	$("#feeds_list").html("<center>"+img_loader(17)+"</center>");
	$.get("/ax_get_feeds.php", {tab:tab, type:type, extra_id: extra_id},
		function(data){
			$("#feeds_list").html(data);
	});
	$('#tabbar_'+current_tab).removeClass('on').addClass('normal');

	$('#tabbar_'+tab).removeClass('normal').addClass('on');

	$('#feed_sec').val(tab);
	if(type=="member"){
		$('#search_feed_sstr').val(default_text);
		$('#feed_sstr').val(0);
	}
	else $('#feed_sstr').val(default_text);

	current_tab=tab;
	feeds_page_count = 0;
}


function chg_to_view_all(element){
	$(element).hover(function() {
		$(element+'_link1').show();
		$(element+'_link').hide();
	}, function() {
		$(element+'_link').show();
		$(element+'_link1').hide();
  	});
}

function check_browser(){

	var browserName=navigator.appName;
	if (browserName=="Netscape")
	{
		 return "Netscape";
	}
	else
	{
	 if (browserName=="Microsoft Internet Explorer")
	 {
	  return "IE";
	 }
	}


}


function qtip(element, type, id){
	if(type=='event'){
  	 	mycontent= "<a href=\"#\"><img hspace=\"4\" vspace=\"4\" src=\"/images/icn_feed_option.gif\" width=\"17\" height=\"17\" alt=\"\" title=\"\" border=\"0\"/></a>";
  	 }
  	 else if(type=='event_add'){
  	 	mycontent= "<a href=\"#\"><img hspace=\"4\" vspace=\"4\" src=\"/images/icn_feed_option.gif\" width=\"17\" height=\"17\" alt=\"\" title=\"\" border=\"0\"/></a>";
  	 }
  	 else{
  	 	mycontent= "<a href=\"javascript:void(0);\" onclick=\"delete_fp('"+element+"','"+type+"','"+id+"');\"><img hspace=\"4\" vspace=\"4\" src=\"/images/close_sample.gif\" width=\"9\" height=\"9\" alt=\"delete\" title=\"delete\" border=\"0\"/></a>";
  	 }
	// Only create tooltips when document is ready
	//$(document).ready(function()
	//{
	   // Use the each() method to gain access to each of the elements attributes
	   //$(element).each(function()
	   //{
	      $(element).qtip(
	      {
	      	content: mycontent, // Give it some content
	    	position: {
         	target: false,
         	corner: {
            	target: 'topRight'
         	},
         	adjust: {
            x: -40, y: 1
         }
      }, // Set its position
	         hide: {
	            fixed: true // Make it fixed so it can be hovered over
	         },
	         style: {border:0, background: 'transparent'}
	      });
	  // });
	//});
}

function qtip_agenda(element, event_id, attending, following, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('attend','attending', 'follow', 'following');
	}
	if(attending){
		mycontent= "<a id='attending_"+event_id+"' style='float:left;color:#999;background-color:#fff;padding-top:2px;padding-bottom:2px;border:1px solid #ccc;font:bold 10px Verdana;width:72px;text-align:center;display:block;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='attend_event("+event_id+");'>" + labels[0] + "</a>";
		mycontent= mycontent+"<a id='attending_on_"+event_id+"' style='float:left;color:#fff;background-color:#ff5a00;background-image: url(\"/style/close_white2.gif\");background-repeat: no-repeat;background-position: right 5px;padding-left:7px;padding-right:21px;padding-top:3px;padding-bottom:3px;font:bold 10px Verdana;display:block;margin-right:4px;text-decoration:none;' href='javascript:void(0);' onclick='attend_event_delete("+event_id+");'>" + labels[1] + "</a>";
	}
	else{
		mycontent= "<a id='attending_"+event_id+"' style='float:left;color:#999;background-color:#fff;padding-top:2px;padding-bottom:2px;border:1px solid #ccc;font:bold 10px Verdana;width:72px;text-align:center;display:block;margin-right:4px;text-decoration:none;' href='javascript:void(0);' onclick='attend_event("+event_id+");'>" + labels[0] + "</a>";
		mycontent= mycontent+"<a id='attending_on_"+event_id+"' style='float:left;color:#fff;background-color:#ff5a00;background-image: url(\"/style/close_white2.gif\");background-repeat: no-repeat;background-position: right 5px;padding-left:7px;padding-right:21px;padding-top:3px;padding-bottom:3px;font:bold 10px Verdana;display:block;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='attend_event_delete("+event_id+");'>" + labels[1] + "</a>";
	}

	if(attending && following){
		mycontent= mycontent+"<a id='watching_"+event_id+"' style='float:left;color:#999;background-color:#fff;padding-top:2px;padding-bottom:2px;border:1px solid #ccc;font:bold 10px Verdana;width:72px;text-align:center;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='my_event_add("+event_id+", 1);'>" + labels[2] + "</a>";
		mycontent= mycontent+"<a id='watching_on_"+event_id+"' style='float:left;color:#fff;background-color:#ff5a00;background-image: url(\"/style/close_white2.gif\");background-repeat: no-repeat;background-position: right 5px;padding-left:7px;padding-right:21px;padding-top:3px;padding-bottom:3px;font:bold 10px Verdana;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='my_event_delete_list("+event_id+", 1);'>" + labels[3] + "</a>";
	}
	else if(following){
		mycontent= mycontent+"<a id='watching_"+event_id+"' style='float:left;color:#999;background-color:#fff;padding-top:2px;padding-bottom:2px;border:1px solid #ccc;font:bold 10px Verdana;width:72px;text-align:center;display:block;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='my_event_add("+event_id+", 1);'>" + labels[2] + "</a>";
		mycontent= mycontent+"<a id='watching_on_"+event_id+"' style='float:left;color:#fff;background-color:#ff5a00;background-image: url(\"/style/close_white2.gif\");background-repeat: no-repeat;background-position: right 5px;padding-left:7px;padding-right:21px;padding-top:3px;padding-bottom:3px;font:bold 10px Verdana;display:block;margin-right:4px;text-decoration:none;' href='javascript:void(0);' onclick='my_event_delete_list("+event_id+", 1);'>" + labels[3] + "</a>";
	}
	else{
		mycontent= mycontent+"<a id='watching_"+event_id+"' style='float:left;color:#999;background-color:#fff;padding-top:2px;padding-bottom:2px;border:1px solid #ccc;font:bold 10px Verdana;width:72px;text-align:center;display:block;margin-right:4px;text-decoration:none;' href='javascript:void(0);' onclick='my_event_add("+event_id+", 1);'>" + labels[2] + "</a>";
		mycontent= mycontent+"<a id='watching_on_"+event_id+"' style='float:left;color:#fff;background-color:#ff5a00;background-image: url(\"/style/close_white2.gif\");background-repeat: no-repeat;background-position: right 5px;padding-left:7px;padding-right:21px;padding-top:3px;padding-bottom:3px;font:bold 10px Verdana;display:block;margin-right:4px;text-decoration:none;display:none;' href='javascript:void(0);' onclick='my_event_delete_list("+event_id+", 1);'>" + labels[3] + "</a>";
	}

	$(element).qtip(
	   {
	    content: "<div style=\"width:300px;\">"+mycontent+"</div>", // Give it some content
	    position: {
         target: false,
         corner: {
            target: 'bottomLeft'
         },
         adjust: {
            x: 78, y: -25
         }
      }, // Set its position
	         hide: {
	            fixed: true // Make it fixed so it can be hovered over
	         },
	         style: {border:0, background: 'transparent'}
	      });
	  // });
	//});
}

function delete_fp(element,type,id){
	$.get("/ax_delete_fp.php", {type:type, id:id},
		function(data){
			if(data=="true"){
				$(element).hide("slow");
			}
	});
}

function rating_star(type, ref, vote_value, active){
	$(function(){
		$('.'+type+'-star').rating({
		  callback: function(value, link){
			$.get("/ax_rate.php", {ref_id:ref, vote:value, type:type});
		     return false;
		  }
		}).rating('select', vote_value).rating('readOnly', active, active);
	});
}

function save_user_message(blank_text){
	msg = document.form_user_message.user_message.value;
	$.get("/ax_user_comment.php", {user_message: msg},
		function(data){
			$("#feeds_list").prepend(data);
			$(".new_feed_item").show("slow");
			document.form_user_message.user_message.value=blank_text;
			$('.area').ata();
			hide('.button_usermsg');
	});

}

function switch_login_save(){
	if($("#login_save").val()==1){
		$("#login_save_checkbox").removeClass("check").addClass("uncheck");
		$("#login_save").val(0);
	}
	else{
		$("#login_save_checkbox").removeClass("uncheck").addClass("check");
		$("#login_save").val(1);
	}
}


function wiki_add_oc(type){
	if(type=='open'){
		$('#wiki_add').hide();
		$('#wiki_add_form').show();
	}else{
		$('#wiki_add_form').hide();
		$('#wiki_add').show();
	}
}

function wiki_please_login(action,id){
	if(id==null) id='';
	if(action=='open'){
		$('#wiki_note'+id).show();
	}else{
		$('#wiki_note'+id).hide();
	}
}

function wiki_add_text(id, type, alert_text, ref_name){
	if(alert_text==null) alert_text='';
	/*if(alert_text!='' && $('#terms_'+ref_name+id+':checked').val()!=1){
		autoviva_alert(alert_text);
		return false;
	}*/
    var oEditor = FCKeditorAPI.GetInstance('add_editor_'+id+'');
    var msg = oEditor.GetXHTML();
    var section_title = "";
    /*if($('#wk_section').val()!="other") section_title=$('#wk_section').val();
    else section_title=$('#wk_new_title').val();*/
	section_title=$('#wk_new_title').val();
	$.post("/ax_wiki_text_add.php", {id: id, title:section_title, msg: msg, type: type},
		function(data){
			$('#wiki_return').html(data.message);
	}, "json");
	wiki_add_oc('close');
}

function wiki_save_oc(id, type){
	if(type=='open'){
		$('#wiki_block_'+id+'').hide();
		$('#wiki_edit_bt_'+id+'').hide();
		$('#wiki_text_block_'+id+'').show();
		$('#wiki_title_line_'+id+'').hide();
	}else{
		$('#wiki_block_'+id+'').show();
		$('#wiki_edit_bt_'+id+'').show();
		$('#wiki_text_block_'+id+'').hide();
		$('#wiki_title_line_'+id+'').show();
	}
}
function wiki_edit_text(id, type, ref_id, alert_text, description){
	if(alert_text==null) alert_text='';
	/*if(alert_text!='' && $('#terms'+id+':checked').val()!=1){
		autoviva_alert(alert_text);
		return false;
	}*/
    var oEditor = FCKeditorAPI.GetInstance('editor_'+id+'');
    var msg = oEditor.GetXHTML();
	$.post("/ax_wiki_text_edit.php", {id: id, type: type, ref_id: ref_id, msg: msg, desc: description},
		function(data){
		$('#wiki_return_'+id+'').html(data.message);
		//alert(id);
	}, "json");
	wiki_save_oc(id, 'close');
}

function wiki_add_photo_oc(type){
	if(type=='open'){
		$('.wiki_block_photo').hide();
		$('.no_content').hide();
		$('#specs_block').hide();
		$('#wiki_add_form_photo').show();
		$('.whitebg').hide();
		$('.white_bg').hide();
	}else{
		$('.wiki_block_photo').show();
		$('.no_content').show();
		$('#specs_block').show();
		$('#wiki_add_form_photo').hide();
		$('.whitebg').show();
		$('.white_bg').show();
	}
}


function wiki_add_video_oc(type){
	if(type=='open'){
		$('.wiki_block_video').hide();
		$('.no_content').hide();
		$('#wiki_add_form_video').show();
		$('.whitebg').hide();
		$('.white_bg').hide();
	}else{
		$('.wiki_block_video').show();
		$('.no_content').show();
		$('#wiki_add_form_video').hide();
		$('.whitebg').show();
		$('.white_bg').show();
	}
}

function wiki_add_photo(type){
	$.post("/ax_wiki_add_photo.php", {title: $('#title').val(), img: $('#file_user_photo').val(), type: type},
		function(data){
		//$('#wiki_block_photo').html(data.message);
		alert(data);
	});
	//wiki_add_photo_oc('close');
}

function get_uploaded_photos(code){
	$.get("/ax_get_uploaded_photos.php", {code: code},
		function(data){
			if(data!=''){
				$('#jpDiv_photos_body_uploaded').html(data);
				$('#jpDiv_photos_body_uploaded').append('<div class="clearer"></div>');
				$("#jpDiv_photos img[title]").tooltip();
			}else{
				$('#jpDiv_photos_body_uploaded').hide();
			}
		}
	);
}

function publisher_get_uploaded_photos(code){
	$.get("/ax_get_uploaded_photos.php", {code: code},
		function(data){
			if(data!=''){
				if(!$('#jpDiv_last_uploaded').length) $('#jpDiv_photos_body_uploaded').prepend('<div id="jpDiv_last_uploaded"></div>');
				$('#jpDiv_last_uploaded').html(data);
				$('jpDiv_last_uploaded').children('.clearer').remove();
				$('jpDiv_last_uploaded').append('<div class="clearer"></div>');
				$("#jpDiv_photos img[title]").tooltip();
			}else{
				$('#jpDiv_photos_body_uploaded').hide();
			}
		}
	);
}

function publisher_remove_uploaded_photo(id,code){
	$.get("/ax_remove_uploaded_photo.php", {id: id, code: code},
		function(data){
			$('#axJpDiv_enterDataImage'+id).hide(200,function(){
				$(this).remove();
				publisher_get_uploaded_photos(code);
			});
	});
}

function remove_uploaded_photo(id,code){
	$.get("/ax_remove_uploaded_photo.php", {id: id, code: code},
		function(data){
			$('#elementtoberemoved'+id).remove();
			get_uploaded_photos(code);
	});
}

function initAccordionMenu() {
	$('#accordion_menu div').hide();
	$('#accordion_menu li:last a').addClass("on");
	$('#accordion_menu li:last div').show();
	$('#accordion_menu li a').click(
	    function() {
	    	$('#accordion_menu li a').removeClass("on");
	    	$(this).addClass("on");
	    	var checkElement = $(this).next();
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				$('#accordion_menu div:visible').slideUp('normal');
				checkElement.slideDown('normal');
				$('#accordion_menu div:visible div').show();
				return false;
			}
	    }
  	);
}

function initAccordionMenu_hpbeta(menu_opened, div_closed) {
	$('#accordion_menu_beta div').hide();
	$('#'+menu_opened+'_link').hide();
	$('#'+menu_opened).show();
	$('#'+menu_opened+' div').show();
	$('#'+div_closed).hide();
	$('#accordion_menu_beta li a.title_beta').click(
	    function() {
			$('#accordion_menu_beta li a').show();
	    	$(this).hide();
	    	var checkElement = $(this).next();
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				$('#accordion_menu_beta div:visible').hide();
				checkElement.show();
				$('#accordion_menu_beta div:visible div').show();
				$('#recover_form').hide();
				return false;
			}
	    }
  	);
}

function show_news_mh(id_show, id_hide1, id_hide2){
	$('#block'+id_show).show();
	$('#block'+id_hide1).hide();
	$('#block'+id_hide2).hide();
	$('#th'+id_show).addClass('sel');
	$('#th'+id_hide1).removeClass('sel');
	$('#th'+id_hide2).removeClass('sel');
	$('#th'+id_hide1).addClass('link');
	$('#th'+id_hide2).addClass('link');
}

function autoviva_alert(message,success){
	if(!success) createAndShowPopin('', 'default_form_error', message);
	else createAndShowPopin('', 'default_form_success', message);
}

function switch_visibility(element, label){
	toogle(element);
	simple_change_class('#collapse','collapse1');

	if ($('#collapse').hasClass('collapse1')){
		$('#collapse').html('hide '+label);
	}
	else{
		$('#collapse').html('show '+label);
	}

	if(element=='.top_pics'){
		toogle('.top_pics_transparency');
		toogle('.top_pics_title');
	}
}

function switch_visibility_hp(element, label){
	$.get("/ax_switch_visibility_hp.php",
		function(data){
			if(data=="true"){
				switch_visibility(element, label);
			}
	});
}

function switch_visibility_cars(element, label){
	$.get("/ax_switch_visibility_cars.php",
		function(data){
			if(data=="true"){
				switch_visibility(element, label);
			}
	});
}

function teaser_nag(id){
	$.get("/ax_teaser_nag.php", {id:id},
		function(data){
			if(data=="true"){
				$('.teaser').hide("slow");
			}
	});
}

var slideMenu=function(){
	var sp,st,t,m,sa,l,w,sw,ot;
	var speed=1;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s;st=sw;t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length;w=m.offsetWidth;sw=w/l;
			ot=Math.floor((w-st)/(l-1));var i=0;
			for(i;i<l;i++){s=sa[i];s.style.width=sw+'px';this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}

		},
		timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t);}},
		slide:function(s){

			var cw=parseInt(s.style.width,'10');
			if(cw<st){
				var owt=0;var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow;var oi=0;o=sa[i];ow=parseInt(o.style.width,'10');
						if(ow>ot){oi=Math.floor((ow-ot)/speed);oi=(oi>0)?oi:1;o.style.width=(ow-oi)+'px'}
						owt=owt+(ow-oi)}}
				s.style.width=(w-owt)+'px';
				if(speed==1){
					speed=2;
					$('#sm div').hide();
					$('#first').show();
				}
				else{
					$('#sm div').hide();
					if((w-owt)>=417){
						$(s).children("div").show();
					}
				}
			}else{clearInterval(m.timer);}

		}
	};
}();

var tour_step=0;
function change_step(n, max, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('< go back');
	}
	
	hide('#step_'+tour_step);
	$('#lnk_'+tour_step).removeClass('sel');
	$('#lnk_'+tour_step).addClass('normal');

	$('#tabbar_light_'+tour_step).removeClass('on');
	$('#tabbar_light_'+tour_step).addClass('normal');
	if(n=='next'){
		tour_step=tour_step+1;
		if(tour_step==max) tour_step=0;
	}
	else{
		tour_step=tour_step-1;
		if(tour_step==-1) tour_step=(max-1);
	}
	show('#step_'+tour_step);
	$('#lnk_'+tour_step).removeClass('normal');
	$('#lnk_'+tour_step).addClass('sel');

	$('#tabbar_light_'+tour_step).removeClass('normal');
	$('#tabbar_light_'+tour_step).addClass('on');
	if(tour_step==0) $(".tour_link").html('&nbsp;');
	else $(".tour_link").html(labels[0]);
}

function select_step(step){
	if (typeof(labels) == "undefined"){
			labels = new Array('< go back');
	}
	
	hide('#step_'+tour_step);
	$('#lnk_'+tour_step).removeClass('sel');
	$('#lnk_'+tour_step).addClass('normal');
	$('#tabbar_light_'+tour_step).removeClass('on');
	$('#tabbar_light_'+tour_step).addClass('normal');
	tour_step=step;
	show('#step_'+tour_step);
	$('#lnk_'+tour_step).removeClass('normal');
	$('#lnk_'+tour_step).addClass('sel');

	$('#tabbar_light_'+tour_step).removeClass('normal');
	$('#tabbar_light_'+tour_step).addClass('on');

	if(tour_step==0) $(".tour_link").html('&nbsp;');
	else $(".tour_link").html(labels[0]);
}

function my_event_add(event_id, list){
	$.getJSON("/ax_my_event_add.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				hide("#watching_"+event_id);
				show("#watching_on_"+event_id);
				if(list==0) show('#alert');
			}
	});
}

function my_event_delete(event_id){
	element = '#event'+event_id;
	$.getJSON("/ax_my_event_delete.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				$(element).hide("slow");
			}
	});
}

function my_event_delete_list(event_id, list){
	$.getJSON("/ax_my_event_delete.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				hide("#watching_on_"+event_id);
				show("#watching_"+event_id);
				if(list==0){
					hide('#alert');
					hide('#alert_on');
				}
			}
	});
}

function attend_event(event_id){
	$.getJSON("/ax_attend_event.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				hide("#attending_"+event_id);
				show("#attending_on_"+event_id);
				hide("#watching_"+event_id);
				hide("#watching_on_"+event_id);
				if(data.alert=="true") show('#alert_on');
				else show('#alert')
			}
	});
}

function attend_event_delete(event_id){
	$.getJSON("/ax_attend_event_delete.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				hide("#attending_on_"+event_id);
				show("#attending_"+event_id);
				show("#watching_"+event_id);
				hide('#alert');
				hide('#alert_on');
			}
	});
}

function save_event_alert(labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('before');
	}
	
	var value = parseInt($("#alert_num").val());
	if(value>0){
		alarm=$('#alert_num').val()+' '+$('#alert_sel').val();
		$.getJSON("/ax_event_alert.php", {id: $('#event_id').val(), alarm_value:alarm},
			function(data){
				if(data.status=="true"){
					hide('#alert');
					$('#pin_agenda_alert').hide();
					$("#alert_on a#txt_alert").html(alarm+" " + labels[0]);
					show('#alert_on');
				}
		});
	}else{
		$("#alert_num").focus();
	}
}

function delete_event_alert(event_id){
	$.getJSON("/ax_event_alert_delete.php", {id: event_id},
		function(data){
			if(data.status=="true"){
				hide('#alert_on');
				show('#alert');
			}
	});
}

function refresh_help_tip(){
	$.post("/ax_refresh_tip.php", {},
		function(data){
		//$('.rb_main').hide("slow");
		$('.rb_main').html(data.message);
		//$('.rb_main').show("slow");
	}, "json");
}


function toogle_display_class(element, last, new_class, old_class, key_item, key_class){
	if(key_item==null) key_item='item';
	if(key_class==null) key_class='class';
	for (var i = 0; i <= last; i++){
		if(i==element){
			$("#"+key_class+i).removeClass(old_class);
			$("#"+key_class+i).addClass(new_class);

		}
		else{
			$("#"+key_class+i).removeClass(new_class);
			$("#"+key_class+i).addClass(old_class);
		}

		$("#"+key_item+i).hide();
	}
	$("#"+key_item+element).show();
}
function addcar_tip_dismiss(){
	$.get("/ax_addcar_tip.php",
		function(data){
			if(data=="true"){
				hide('#add_car_tip');
			}
	});
}

function accept_buddy_request(member_id, feed_id, grid_layout, notify, account){
	if(account==null) account=0;
	if(notify==null) notify=0;

	if(!notify){
		if(grid_layout) send_grid_layout = 1;
		else send_grid_layout = 0;
		$.getJSON("/ax_accept_buddy_request.php", {id: member_id, grid_layout: send_grid_layout,notify:false},
			function(data){
				if(data.status=="true"){
					$("#feed_item"+feed_id).remove();
					$.get("/ax_get_feed_buddy_accepted.php", {member_id:member_id, grid_layout: send_grid_layout},
						function(data){
							if(grid_layout){
								$('#feeds_list_stream').prepend(data);
								realTimeAdjustment();
								setMouseOvers();
							}
							else{
								$(data).hide().prependTo("#feeds_list_stream").fadeIn("slow");
							}
					});


					/*$("#feed_item"+feed_id).show("slow",function(){realTimeAdjustment();});*/
				}
		});
		realTimeAdjustment();
	}else{
		$("#"+feed_id).html(img_loader(14));
		$.getJSON("/ax_accept_buddy_request.php", {id: member_id,notify: true, account: account},
			function(data){
				if(data.status=="true"){
					$("#"+feed_id).hide("slow",function(){
						$("#"+feed_id).css('cursor','pointer');
						$("#"+feed_id).click(function() {document.location.href=data.href;});
						$("#"+feed_id).html(data.message);
						$("#"+feed_id).show("slow");
					});
	
					if($('.nostate_invitation').length<=0){
						$('.links').fadeOut('slow');
					}
				}
		});
	}
}

function reject_buddy_request(member_id, feed_id,notify){

	$.get("/ax_reject_buddy_request.php", {id: member_id, notify:notify},
		function(data){
			if(data=="true"){
				if(!notify) $("#feed_item"+feed_id).hide("slow");
				else $("#"+feed_id).hide("slow");
			}
	});
}

function display_give_gift(version_id, hpversion){
	$("#pin_give_gift .popupInner").html('<center>'+img_loader(17)+'</center>');
	show("#pin_give_gift", 0);
	$.get("/ax_give_gift_display.php", {id: version_id, versionhp: hpversion},
		function(data){
			$("#pin_give_gift .popupInner").html(data);
	});
}

function display_sell_car(version_id){
	$("#pin_sell_car .popupInner").html('<center>'+img_loader(17)+'</center>');
	show("#pin_sell_car", 0);
	$.get("/ax_display_sell_car.php", {id: version_id},
		function(data){
			$("#pin_sell_car .popupInner").html(data);
	});
}

function sell_car(id, hpversion, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('buy car', 'This version was sold and removed from your dream garage.');
	}
	
	$.getJSON("/ax_sell_car.php", {id: id},
		function(data){
			if(data.status=="true"){
				$("#pin_version_key_data").html(data.message);
				if(hpversion){
					//change_class("key", 1);
					$('#tools_key').html(labels[0]);
					createAndShowPopin('','default_form_success',labels[1]);
				}else location.reload();
			}
			else{
				//$("#pin_version_key_data_warn").html(data.message);
				createAndShowPopin('','default_form_error',data.message);
			}
	});
}

function switch_tabs(step, class_name){
	$('#'+class_name+'_'+current_content).removeClass('on').addClass('normal');

	$('#'+class_name+'_'+step).removeClass('normal').addClass('on');

	hide('#txt_'+current_content);
	show('#txt_'+step);
	current_content=step;
	if(class_name == "cars_tabbar"){
		adjustImageToFrame();
		$('.item_data').css('width',($('#member_wrapper').width()-30));
	}
}



function select_treat(id){
	if($("#treat_id").val()!='') $('#treat_'+$("#treat_id").val()).removeClass('selected');
	$("#treat_id").val(id);
	$('#treat_'+id).addClass('selected');
}

function honks_search_string(){
	sstring=$("#honk_string").val();
	list_items_searched=$("#list_items_searched").html();
	$.get("/ax_honks_search_string.php", {sstring: sstring, items_sel:$("#items_selected").val()},
		function(data){
			$("#honk_search_go").hide();
			$("#honk_search_clear").show();
			$("#list_items_searched").html(data);
	});
}

function honks_search_string_clear(default_text){
	$("#list_items_searched").html(list_items_searched);
	$("#honk_string").val(default_text);
	$("#honk_search_go").show();
	$("#honk_search_clear").hide();
}

function honks_select_item(car_id){
	if($("#list_items_selected").html()!='') $("#items_selected").val($("#items_selected").val()+'|');
	$("#items_selected").val($("#items_selected").val()+car_id);
	$("#list_items_selected").append('<div id=\"clear_car_'+car_id+'\" onclick=\"honks_clear_item(\''+car_id+'\')\">'+$("#sel_car_"+car_id).html()+'</div>');
	$("#sel_car_"+car_id).remove();
}

function honks_clear_item(car_id){
	$("#list_items_searched").append('<div id=\"sel_car_'+car_id+'\" onclick=\"honks_select_item(\''+car_id+'\')\">'+$("#clear_car_"+car_id).html()+'</div>');
	$("#clear_car_"+car_id).remove();
	$("#items_selected").val($("#items_selected").val().replace(car_id,''));
	$("#items_selected").val($("#items_selected").val().replace('||','|'));
}

current_content=0;
function change_honks_display(cat,page){
	$(".honks_display").html('<center>'+img_loader(17)+'</center>');
	$.get("/ax_change_honks_display.php", {cat: cat, page:page},
		function(data){
			$(".honks_display").html(data);
	});
	$('#honks_tabbar_'+current_content).removeClass('on').addClass('normal');

	$('#honks_tabbar_'+cat).removeClass('normal').addClass('on');
	current_content=cat;
}

function hide_nag_car(element, id){
	$.get("/ax_hide_nag_car.php", {element: element, car_id: id},
		function(data){
			if(data=="true") hide(element);
	});
}

function switch_spec_cats(type){
	for(var i=0; i < spec_cats.length; i++){
		if(type=="expand"){
			$('#show_specs_cat_'+spec_cats[i]).show();
			$('#link_specs_cat_'+spec_cats[i]).removeClass('closed');
			$('#link_specs_cat_'+spec_cats[i]).addClass('opened');
			$('[id^="switch_spec_cats_collapse"]').show();
			$('[id^="switch_spec_cats_expand"]').hide();
		}
		else{
			$('#show_specs_cat_'+spec_cats[i]).hide();
			$('#link_specs_cat_'+spec_cats[i]).addClass('closed');
			$('#link_specs_cat_'+spec_cats[i]).removeClass('opened');
			$('[id^="switch_spec_cats_collapse"]').hide();
			$('[id^="switch_spec_cats_expand"]').show();
		}
	}
}

var compare_new_cars = 1;
function switch_tabs_compare(step, default_text, labels){
	compare_new_cars = step;

	if (typeof(labels) == "undefined"){
			labels = new Array('model', 'version');
	}
	
	switch_tabs(step, "compare_tabbar")
	update_make_combo(default_text);
	$("#compare_make").val(0);
	$('#compare_model_parent').css('background-color','#959595');
	$('#compare_version_parent').css('background-color','#959595');
	$("#id_compare_model").html(labels[0]);
	$("#id_compare_version").html("<input name='add_version' id='add_version' type='hidden' value='0' />" + labels[1]);
	document.images['img_version'].src = '/images/blanks/compare_car_112.jpg';
}

function update_make_combo(default_text){
	$('#loader').show();
	$.get("/ax_update_make_combo.php", {default_text:default_text, new_car: current_content},
		function(data){
			if(data!=""){
				$("#compare_make").html(data);
				$('#loader').hide();
			}else{
				$('#loader').hide();
			}
			//$("#compare_make").resetSS();
	});
}

function update_model_combo(default_text, type, selected, default_text2, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('model','version','select...');
	}
	
	if(type==null){
		type="compare";
		new_car=current_content;
	}
	else new_car=0;

	if(selected==null) selected=0;

	if(default_text2==null) default_text2=0;

	make_selected = $("#"+type+"_make").val();
	if(make_selected!=0){
		$('#loader').show();
		$.get("/ax_update_model_combo.php", {default_text:default_text, make_id: make_selected, new_car: new_car, type: type, selected: selected, default_text2: default_text2, new_car: compare_new_cars},
			function(data){
				if(data!=""){
					$('#loader').hide();
					$("#id_"+type+"_model").html(data);
					if(type=="compare"){
						$('#compare_model_parent').css('background-color','#fff');
						//$("#compare_model").sSelect();
						$("#id_compare_version").html("<input name='add_version' id='add_version' type='hidden' value='0' />version");
						document.images['img_version'].src = '/images/blanks/compare_car_112.jpg';
						document.images['img_version'].alt = '';
						document.images['img_version'].title = '';
					}
				}else{
					$('#loader').hide();
				}
		});
	}else{
		$("#id_compare_model").html(labels[0]);
		$("#id_compare_version").html(labels[1]);
		$('#compare_model_parent').css('background-color','#959595');
		$('#compare_version_parent').css('background-color','#959595');
		$('#submit_cmp').addClass('button_disabled');
		$('#submit_cmp').attr('disabled','disabled');
		$('#submit_cmp').val(labels[2]);
	}

	if(type=="ad"){
		$("#ad_model").val(selected);
		$("#ad_version").val(0);
		$("#id_ad_version").html(default_text2);
	}
}

function update_version_combo(default_text, type, selected, default_text2, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('version','select...');
	}
	
	if(type=="compare") new_car=current_content;
	else new_car=0

	if(selected==null) selected=0;

	model_selected = $("#"+type+"_model").val();
	if(model_selected==0){
		if(type=="compare"){
			document.images['img_version'].src = '/images/blanks/compare_car_112.jpg';
			document.images['img_version'].alt = '';
			document.images['img_version'].title = '';
		}
		$('#submit_cmp').addClass('button_disabled');
		$('#submit_cmp').attr('disabled','disabled');
		$('#submit_cmp').val(labels[1]);
		$("#id_compare_version").html(labels[0]);
		$('#compare_version_parent').css('background-color','#959595');
	}
	else{
		$('#loader').show();
		$.ajaxSetup({cache: false});
		$.getJSON("/ax_update_version_combo.php", {default_text:default_text, model_id: model_selected, new_car: compare_new_cars, type: type, selected: selected},
			function(data){
				if(data.select!=""){
					$('#loader').hide();
					$("#id_"+type+"_version").html(data.select);
					$("#version_selected").html(data.img_version_selected);
					$('#compare_version_parent').css('background-color','#fff');
				}else{
					$('#loader').hide();
				}
		});
	}
}
var version_selected = 0;
function update_version_selected(type , labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('compare','select...');
	}
	
	if(type==null) type="compare";
	if(type=="compare"){
		version_selected = $("#add_version").val();
	}else{
		version_selected = $("#"+type+"_version").val();
	}
	if(type=="compare"){
		model_selected = $("#compare_model").val();


		if(version_selected!=0){
			$('#submit_cmp').removeClass('button_disabled');
			$('#submit_cmp').removeAttr('disabled');
			$('#submit_cmp').val(labels[0]);
		}else{
			$('#submit_cmp').addClass('button_disabled');
			$('#submit_cmp').attr('disabled','disabled');
			$('#submit_cmp').val(labels[1]);
		}
		$('#loader').show();
		$.get("/ax_update_version_selected.php", {version_id: version_selected, model_id:model_selected},
			function(data){
				if(data!=""){
					$('#loader').hide();
					$("#version_selected").html(data);
				}else{
					$('#loader').hide();
				}
			});
	}
	else{
		$("#ad_version").val(version_selected);

	}
}

function add2compare(warn){
	version_sel = $("#add_version").val();
	if(version_sel==0){
		autoviva_alert(warn);
		return false;
	}
}

function switch_compare_highlight(){
	if($("#compare_highlight").val()==1){
		$(".class_like_id").removeClass("check").addClass("uncheck");
		$("#compare_highlight").val(0);
		$(".highlight_item").removeClass("highlight");
	}
	else{
		$(".class_like_id").removeClass("uncheck").addClass("check");
		$("#compare_highlight").val(1);
		$(".highlight_item").addClass("highlight");
	}
}

function show_notification(){
	setTimeout(function() {
		$.get("/ax_get_tip.php",
			function(data){
				if(data!=""){
					$("#notifications .float_left").html(data);
					$("#notifications").show();
					setTimeout(function() {
						$("#notifications").hide();
					}, 12000);
				}
		});
	}, 20000);
}

var oldtags="";
var oldHeight=0;
function display_edit_tags(type, ref_id){
	//oldHeight = $('#photos_bottom_blocks_stretch').height();
	//$('#photos_bottom_blocks_stretch').css('height','');
	oldtags=$("#display_tags").html();
	$("#display_tags").html('');
	$("#display_edit_tags").html(img_loader(17));
	$.get("/ax_display_edit_tags.php", {type: type, ref_id: ref_id},
		function(data){
			$("#display_edit_tags").html(data);
			$('textarea').ata();
			$('#tags_'+type+'_'+ref_id).focus();
			//$("[class^='photos_bottom']").equalHeights();
	});
}

function cancel_edit_tags(){
	//$("[class^='photos_bottom']").css('height',oldHeight+'px');
	$("#display_edit_tags").html('');
	$("#display_tags").html(oldtags);

}

function save_tags(type, ref_id){
	req_tags=$("#tags_"+type+"_"+ref_id).val();
	$("#display_edit_tags").html(img_loader(17));
	$.get("/ax_save_edited_tags.php", {type: type, ref_id: ref_id, req_tags:req_tags},
		function(data){
			$("#display_edit_tags").html('');
			$("#display_tags").html(data);
			//$("[class^='photos_bottom']").css('height',oldHeight+'px');
	});
}

function add_ctag(new_tag, element) {
	curvalue = $("#"+element).val();
	if (curvalue == "") $("#"+element).val(new_tag);
	else $("#"+element).val(curvalue + ", " + new_tag);
}

function start_addcontent(selected){
	for(i=0;i<4;i++){
		hide('#addcontent_'+i);
	}
	show('#addcontent_'+selected)
}

function send_tellfriend(type, ref_id, is_logged){
	name=$("#c_name").val();
	email=$("#c_email").val();
	fname=$("#c_fname").val();

	femail=$("#c_femail").val();
	femail1=$("#search_c_femail").val();
	if(femail1!="") femail=femail1;

	cmsg=$("#c_text").val();
	$("#pin_tellfriend_data").hide();
	$("#pin_tellfriend_data_resp").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_send_tellfriend.php", {type:type, ref_id: ref_id, tellfriend_name: name, tellfriend_email: email, tellfriend_fname: fname, tellfriend_femail: femail, tellfriend_msg: cmsg},
		function(data){
			$("#pin_tellfriend_data_resp").html(data.message);
			if(data.status=="true"){
				setTimeout(function() {
					$('#pin_tellfriend').fadeOut('slow', function() {
					    $("#pin_tellfriend_data_resp").html('');
						$("#c_name").val('');
						$("#c_email").val('');
						if(is_logged){
							$("#c_name").val(name);
							$("#c_email").val(email);
						}
						$("#c_fname").val('');
						$("#c_femail").val('');
						$("#search_c_femail").val('')
						$("#c_text").val('');
						$("#pin_tellfriend_data").show();
					});
				}, 5000);
			}
	});
}

function recomend_page(labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('You have successfuly recommended this page to your friend','Something went wrong when recommending this page to your friend');
	}
	
	name=$("#c_name").val();
	email=$("#c_email").val();
	fname=$("#c_fname").val();

	femail=$("#c_femail").val();
	femail1=$("#search_c_femail").val();
	if(femail1!="") femail=femail1;

	cmsg=$("#c_text").val();

	cpage=$("#c_page").val();
	$("#pin_tellfriend_data").hide();
	$("#pin_tellfriend_data_resp").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_recomend_page.php", {tellfriend_name: name, tellfriend_email: email, tellfriend_fname: fname, tellfriend_femail: femail, tellfriend_msg: cmsg, tellfriend_page: cpage},
		function(data){
			if(data.status=="true"){
				createAndShowPopin('','default_form_success', labels[0]);
			}else{
				createAndShowPopin('','default_form_error', labels[1]);
			}
	});
}

function send_tellfriend_old(type, ref_id){
	name=$("#c_name").val();
	email=$("#c_email").val();
	fname=$("#c_fname").val();

	femail=$("#c_femail").val();
	femail1=$("#search_c_femail").val();
	if(femail1!="") femail=femail1;

	cmsg=$("#c_text").val();
	$("#pin_tellfriend_data").html('<center>'+img_loader(17)+'</center>');
	$.getJSON("/ax_send_tellfriend.php", {type:type, ref_id: ref_id, tellfriend_name: name, tellfriend_email: email, tellfriend_fname: fname, tellfriend_femail: femail, tellfriend_msg: cmsg},
		function(data){
			$("#pin_tellfriend_data").html(data.message);
			if(data.status=="true"){
				setTimeout(function() {
					$('#pin_tellfriend').fadeOut('slow');
				}, 2000);
			}
	});
}

tops_dest_step=1;
function tops_dest_nav(step){
	$.getJSON("/ax_tops_dest_nav.php", {tops_dest_step: tops_dest_step, step:step},
		function(data){
			$(".left a").html(data.left);
			$(".middle").html(data.middle);
			$(".right a").html(data.right);
			$(".details").html(data.details);
			$('.tops_dest a.more').attr('href', data.moreurl);
			tops_dest_step=data.pos;
			realTimeAdjustmentTops();
	});
}

green_tops_dest_step=1;
function green_tops_dest_nav(step){
	$.getJSON("/ax_green_tops_dest_nav.php", {tops_dest_step: tops_dest_step, step:step},
		function(data){
			$(".left a").html(data.left);
			$(".middle").html(data.middle);
			$(".right a").html(data.right);
			$(".details").html(data.details);
			tops_dest_step=data.pos;
			realTimeAdjustmentTops();
	});
}

function change_list_bg(obj, div, color){
	if(div!=null && color!=null){
		if($(obj).is(':checked')){
			$(div).css('background-color',color);
		}else{
			$(div).css('background-color','');
		}
	}
}
function mng_ads_select_all(chkid,trname,color)
{
	var idcheck=$("#"+chkid).attr('checked');
	$('input[id^="check_"]').attr('checked',idcheck);
	if(idcheck==true)$('tr[id^="'+trname+'"]').css('background-color',color);
	else $('tr[id^="'+trname+'"]').css('background-color','');
}
function remove_submit_check(id_check, id_bg_color){
	$(':checkbox').attr('checked', '');
	$(id_check).attr('checked','true');
	change_list_bg('#check_all', '.acc_search_result', '#FAFAFA');
	change_list_bg(id_check, id_bg_color, '#FAFAFA');
	$('form').submit();
}

function ads_calculate_nresults(){
	$.get("/ax_ads_calculate_nresults.php", {make_id: $('#ads_mk').val(), model_id: $('#ads_mo').val(), fuel_type_id: $('#ads_ft').val(), price_id: $('#ads_p').val(), mileage_id: $('#ads_ma').val(), year_id: $('#ads_y').val()},
		function(data){
			$('#ads_nresults').html(data);
	});
}

function ads_change_make(){
	$.get("/ax_ads_change_make.php", {make_id: $('#ads_mk').val()},
		function(data){
			$('#ads_mo').html(data);
			//ads_calculate_nresults();
	});
}

function publish_ad(feed_id, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('ad published on your public profiles.');
	}
	
	$.get("/ax_publish_ad.php", {feed_id: feed_id},
		function(data){
			//$('#feed_answer_'+feed_id).append(data);
			hide('#feed_flag1_'+feed_id);
			//show('#feed_answer_'+feed_id);
			autoviva_alert(labels[0],true);
	});
}

function share_ad(feed_id, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('ad sent to your buddy network');
	}
	
	$.get("/ax_share_ad.php", {feed_id: feed_id},
		function(data){
			//$('#feed_answer_'+feed_id).append(data);
			hide('#feed_flag2_'+feed_id);
			//show('#feed_answer_'+feed_id);
			autoviva_alert(labels[0],true);
	});
}

function switch_radio_class(obj, div, hidden_field, value, color){
	if(color==null) color='#edfaff';
	$(div).css('background-color', '');
	$(obj).css('background-color', color);
	$(".radio").css('background-image', 'none');
	$("#radio"+value).css('background-image', 'url("/style/selected.gif")');
	$(hidden_field).val(value);
	//$(obj).parents(div).css('background-color', color);
}

function no_perms(labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('you don\'t have permission to access to this content');
	}
	
	//$('#pin_noperm').html('<div class="float_right" onclick="hide(\'#pin_noperm\');" style=\"cursor:pointer;\"><img src="/images/close.gif" width="10" height="10" alt="close" title="close" border="0"/></div><div class="float_left"><img src="/images/popin_warning.gif" width="55" height="55" alt="" title="" border="0"/><br /><br /><span>you don\'t have permission to access to this content</span></div>');
	$('.popupInner').html('<div class="float_left" style="width:400px"><img align="absmiddle" style="margin-right:20px" src="/images/popin_warning.png" width="55" height="55" alt="" title="" border="0"/>' + labels[0] +'</div><div class="float_right"><a style="background:none" href="javascript:void(0);" onclick="hide(\'#pin_noperm\', 1);"><img src="/images/close.png" width="10" height="10" alt="close" title="close" border="0"/></a></div><div class="clearer"></div>');
	$('#pin_noperm').show();
}

type_ad=0;
function place_ad_select_type(type){
	$.getJSON("/ax_place_ad_select_type.php", {ad_type: type, ad_top: $("#ad_top").val()},
		function(data){
			if(data.status=="true"){
				$("#type_"+type_ad).removeClass("item_sel");
				$("#type_"+type).addClass("item_sel");
				document.images['img_type_'+type_ad].src = "/images/placead_unselect.gif";
				document.images['img_type_'+type].src = "/images/placead_select.gif";
				$("#ad_type").val(type);
				type_ad=type;
				$('.results').html(data.result);
			}
			else autoviva_alert(data.result);
	});
}

function place_ad_select_top(){
	if ($("#type_top").hasClass("item_sel")){
		$.getJSON("/ax_place_ad_select_type.php", {ad_top: 0, ad_type: $("#ad_type").val()},
			function(data){
				if(data.status=="true"){
					$("#type_top").removeClass("item_sel");
					document.images['img_top'].src = "/images/placead_unselect.gif";
					$("#ad_top").val(0);
					$('.results').html(data.result);
				}
				else autoviva_alert(data.result);
		});
	}
	else{
		$.getJSON("/ax_place_ad_select_type.php", {ad_top: 1, ad_type: $("#ad_type").val()},
			function(data){
				if(data.status=="true"){
					$("#type_top").addClass("item_sel");
					document.images['img_top'].src = "/images/placead_select.gif";
					$("#ad_top").val(1);
					$('.results').html(data.result);
				}
				else autoviva_alert(data.result);
		});
	}
}

function toogle_class(obj_show, obj_hide, link_show, style){
	show(obj_show);
	hide(obj_hide);
	$('a').removeClass(style);
	$(link_show).addClass(style);
}

function track_ad(ad_id,add_class){
	$.getJSON("/ax_track_ad.php", {id: ad_id},
		function(data){
			if(data.status=="true"){
				$('#track_'+ad_id).html(data.message);
				if(add_class) $('#track_'+ad_id).addClass(add_class);
			}
	});
}

function ad_remove(ad_id, page, extra_id, labels){
	if (typeof(labels) == "undefined"){
			labels = new Array('No Ads here');
	}
	
	$.get("/ax_ad_remove.php", {id: ad_id, page: page, extra_id: extra_id},
		function(data){
			if(data=="true"){
				$('#item_ad_'+ad_id).hide("slow");
			}else if(data=="noads"){
				$('.ads_list').html('<div><div class="no_activity_left"></div><div class="no_activity_center">' + labels[0] +'</div><div class="no_activity_right"></div><div class="clearer"></div></div>');
			}
	});
}

function align_popin(){
	var iw; // Set inner width and height
	if (window.innerWidth == null) {
		iw = document.body.clientWidth;
	}
	else {
		iw = window.innerWidth;
	}

	iw = document.body.clientWidth;

	var x;
	x=Math.round(iw / 2);
	x= x-284;
	$('.popin').css("left", x+'px');
}

function predict_search_layout(row) {
	return "<div class=\"wiki_predict\">" + row[0] + "&nbsp;<span class=\"small\">" + row[2] + "</span></div>";
}

function wallpaper_feature(next){
	$.post("/ax_wallpaper.php", {next: next},
		function(data){
		if(data.message!="") $("#feature").html(data.message);
	}, "json");
}

function get_window_dimentsions(){
	var window_dimentsions = {Width: 0, Height: 0};

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

function open_popin_video(key, domain){
	var window_dimentsions = get_window_dimentsions();
	var x, y;
	x=Math.round(window_dimentsions.Width / 2);
	x= x-362;

	y=Math.round(window_dimentsions.Height / 2);
	y=y-176;
	if(y<35) y=35;

	$("#global_div").addClass("opac_div");
	$(key).css('left', x + 'px');
	$(key).css('top', y + 'px');
	$(key).css('display', 'block');

	play_video(domain);
}

function close_popin_video(key){
	swfobject.getObjectById('videoPlayer').stopVideo();
	$("#global_div").removeClass("opac_div");
	$(key).css('display', 'none');
}

function play_video(domain){
	var flashvars = {
	  htmlPage: document.location,
	  currVideo: swfobject.getQueryParamValue("currVideo"),
	  settingsFile: "settings_"+domain+".xml"
	};
	var params = {
	  allowFullScreen: "true",
	  wmode: "transparent",
	  allowScriptAccess: "always"
	};
	var attributes = {
	  id:"videoPlayer",
	  name:"videoPlayer"
	};
	swfobject.embedSWF("external/videoplayer/videoPlayer.swf", "videoPlayer", "684", "299", "9.0.115", "videoplayer/swfobject/expressInstall.swf", flashvars, params, attributes);
	swfmacmousewheel.registerObject(attributes.id);
}

var selected_treat_id='';
function select_honk(hnk,selected_treat)
{
	$('[id^="shonk"]').children('.item_honk_image').css('background-color','');
	$('#'+hnk).children('.item_honk_image').css('background-color','#EFEFEF');
	selected_treat_id=selected_treat;
	return false;
}

var honk_page=0;
function next6honks(total,memberid)
{
	actual=((honk_page+1)*6);
	if(actual<total)
	{
		$('#next6honks').show();
		$(".honk_holder").html("<center>"+img_loader(17)+"</center>");
		honk_page++;
		$.get("/ax_navigate_honks.php", {page_count: honk_page, member_id: memberid},
			function(data){
				$(".honk_holder").html(data);
		});
	}
	else
	{
		$('#next6honks').hide();
	}
}
function previous6honks(total,memberid)
{
	if(honk_page>0)
	{
		$('#previous6honks').show();
		$(".honk_holder").append("<center>"+img_loader(17)+"</center>");
		honk_page--;
		$.get("/ax_navigate_honks.php", {page_count: honk_page, member_id: memberid},
			function(data){
				$(".honk_holder").html(data);
		});
	}
	else
	{
		$('#previous6honks').hide();
	}
}


function changeTopNews(element_id,new_image,url,pos){
	for(i=0;i<4;i++){
		if(i!=element_id){
			$('#topNewsBlock'+i).removeClass();
			$('#topNewsBlock'+i).addClass('element');
		}else{
			$('#topNewsBlock'+i).removeClass();
			$('#topNewsBlock'+i).addClass('selected_element'+pos);
		}

	}

	$('#photo_frame').html('<a href="'+url+'"><img src="'+new_image+'" border="0" class="imageautoadjust"></a>');
	adjustImageToFrame();
}

function my_getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function compensateImage($img){
	var melement='.imageautoadjust';
	var mparent='.parentautoadjust';
	var msibling='.siblingautoadjust';
	var $parent =  $img.parents(mparent);
	
	//siblingheight = $(this).siblings(msibling).outerHeight();
	var siblingheight = $(msibling).outerHeight();
	var centering_compensation = $img.attr('rel');
	//if(console) console.log(centering_compensation);
	//reset styles
	$img.removeAttr('style');
	//measure both image and parent container
	var th = $img.height();
	var tw = $img.width();
	var ph = $parent.height();
	var pw = $parent.width();

	var pp, tp, adjust = 0;

	if(ph>0) pp = pw/ph;
	else pp = 0;

	if(th>0) tp = tw/th;
	else tp = 0;
	
	if(centering_compensation <  -20)	centering_compensation = -2;
	if(centering_compensation >   20)	centering_compensation =  2;
	if(centering_compensation == -20)	centering_compensation = -2;
	if(centering_compensation ==  20)	centering_compensation =  2;
	if(centering_compensation == -10)	centering_compensation = -1;
	if(centering_compensation ==  10)	centering_compensation =  1;

	if(centering_compensation == null){
		centering_compensation = 0;
	}
	
	if(pp>tp){
		$img.css('width','100%');
		adjust = (Math.abs($img.height()-$parent.height()))+siblingheight;
		
		var margin_top = -adjust;
		switch(Number(centering_compensation)){
			case -2:
				margin_top = 0;
				break;
			case -1:
				margin_top = -adjust*0.25;
				break;
			case 0:
				margin_top = -adjust*0.5;
				break;
			case 1:
				margin_top = -adjust*0.75;
				break;
			case 2:
				margin_top = -adjust;
				break;
		}
		if($parent.find('.left').length >= 1){
			margin_top -= 25;
		}
		if(centering_compensation!=undefined) adjust = 1*adjust + 1*centering_compensation;
		$img.css('margin-top', margin_top+'px');
	}else{
		$img.css('height','100%');
		
		adjust = (Math.abs($img.width()-$parent.width()));
		
		var margin_left = -adjust;
		switch(Number(centering_compensation)){
			case -2:
				margin_left = 0;
				break;
			case -1:
				margin_left = -adjust*0.25;
				break;
			case 0:
				margin_left = -adjust*0.5;
				break;
			case 1:
				margin_left = -adjust*0.75;
				break;
			case 2:
				margin_left = -adjust;
				break;
		}
		if($parent.find('.left').length >= 1){
			margin_left -= 25;
		}
		
		
		$img.css('margin-left',margin_left+'px');
	}
}

function compensateImage_BACKUP($img){
	
	/*
	var c = my_getCookie('devmode');
	if( c === null || typeof c == 'undefined'){
		return;
	} 
	*/
	
	var $parent	= $img.parents('.parentautoadjust');
	var rel		= Number($img.attr('rel'));
	if(isNaN(rel)){
		rel = 0;
	}
	
	$img.css({
		position	: 'absolute',
		margin		: 0,
		width		: 'auto',
		height		: 'auto'
	});
	$parent.css({ position	: 'relative' });

	var th = $img.height();
	var tw = $img.width();
	var ph = $parent.height();
	var pw = $parent.width();
	
	/*
	if(tw == 0 || th == 0){
		tw = $img.attr('data-width');
		th = $img.attr('data-height');
	}
	*/
	
	var pp, tp, adjust, siblingheight = 0;
	siblingheight = $('.siblingautoadjust').outerHeight();

	if(ph>0) pp = pw/ph;
	if(th>0) tp = tw/th;

	// tmp convert px to type
	if(rel <  -20)	rel = -2;
	if(rel >   20)	rel =  2;
	if(rel == -20)	rel = -2;
	if(rel ==  20)	rel =  2;
	if(rel == -10)	rel = -1;
	if(rel ==  10)	rel =  1;

	if(pp>tp || true){
		$img.css('width','100%').css('left', 0).css('right', 0);
		adjust = (Math.abs($img.height()-$parent.height())/2)+siblingheight;
		switch(parseInt(rel)){
			// Move down
			case -2:
				$img.css({ top	: 0,			bottom	: 'auto' });
				break;
			case -1:
				$img.css({ top	: -(adjust/2)+'px',	bottom	: 'auto'});
				break;
			// Move up
			case 1:
				$img.css({ top	: 'auto',		bottom	: -(adjust/2)+'px' });
				break;
			case 2:
				$img.css({ top	: 'auto',		bottom	: 0	});
				break;
			// Center
			case 0	:
			default :
				$img.css({ top	: -(adjust)+'px',	bottom	: 'auto'	});
				break;

		}
	}else{
		$img.css('height','100%').css('top', 0).css('bottom', 0);
		adjust = (Math.abs($img.width()-$parent.width())/2);
		
		switch(parseInt(rel)){
			// Move left
			case -2:
				$img.css({ left	: 0,			right	: 'auto' });
				break;
			case -1:
				$img.css({ left	: -(adjust/2)+'px',	right	: 'auto'});
				break;
			// Move Right
			case  1	:
				$img.css({ left	: 'auto',		right	: -(adjust/2)+'px' });
				break;
			case  2	:
				$img.css({ left	: 'auto',		right	: 0	});
				break;
			// Center
			case 0	:
			default	:
				$img.css({ left	: -(adjust)+'px',	right	: 'auto'	});
				break;

		}
	}
}

//use imageautoadjust class in every image meant to be adjusted
function adjustImageToFrame(){
	
//	if(my_getCookie('devmode')){
		$('.imageautoadjust').each(function(){
			compensateImage($(this));
		});
		return;
//	}

	melement='.imageautoadjust';
	mparent='.parentautoadjust';
	msibling='.siblingautoadjust';
	$.each($(melement),function(){
		//siblingheight = $(this).siblings(msibling).outerHeight();
		siblingheight = $(msibling).outerHeight();
		centering_compensation = $(this).attr('rel');
		//if(console) console.log(centering_compensation);
		//reset styles
		$(this).removeAttr('style');
		//measure both image and parent container
		th = $(this).height();
		tw = $(this).width();
		ph = $(this).parents(mparent).height();
		pw = $(this).parents(mparent).width();

		if(ph>0) pp = pw/ph;
		else pp = 0;

		if(th>0) tp = tw/th;
		else tp = 0;

		if(pp>tp){
			$(this).css('width','100%');
			adjust = (Math.abs($(this).height()-$(this).parents(mparent).height())/2)+siblingheight;
			if(centering_compensation!=undefined) adjust = 1*adjust + 1*centering_compensation;
			$(this).css('margin-top','-'+adjust+'px');
		}else{
			$(this).css('height','100%');
			adjust = (Math.abs($(this).width()-$(this).parents(mparent).width())/2);
			$(this).css('margin-left','-'+adjust+'px');
		}
	});
}


function toggleMakeAbout(){
	var $blockhide = $('.block2hide');
	
	if($blockhide.css('display')=='none'){
		$blockhide.show();
		//$('.leftbar_new').css('height','');
		$('#make_about_toggle').removeClass().addClass('make_about_toggle_show');
	}else{
		$blockhide.hide();
		//$('.leftbar_new').css('height','0px');
		$('#make_about_toggle').removeClass().addClass('make_about_toggle_hide');
	}
	adjustFooter();
}


var lastOpenedMain;
function showMain(id){
	if(lastOpenedMain!=id){
		showSecondChild('0');
		//selectFCLink('0');
	}
	$('#main'+id).addClass('main_hover');
	$('#amain'+id).removeClass('main').addClass('main_hover');
	$('#menu_shadow'+id).show();
	$('#fc'+id).show();
	lastOpenedMain = id;
}

function hideMain(id){
	$('#amain'+id).removeClass('main_hover').addClass('main');
	$('#fc'+lastOpenedMain).hide();
	$('#menu_shadow'+lastOpenedMain).hide();
}

var lastSC = '#sc0';
function showSecondChild(id){
	if(id!='-1'){
		$(lastSC).hide();
		$('#sc'+id).show();
		lastSC = '#sc'+id;
	}else{
		$(lastSC).hide();
	}
}

var lastFCLink = 'fclink0';
function selectFCLink(id){
	$(lastFCLink).addClass('first_child');
	$(lastFCLink).removeClass('first_child_hover');
	$('#fclink'+id).removeClass('first_child');
	$('#fclink'+id).addClass('first_child_hover');
	lastFCLink = '#fclink'+id;
}

function doRegister(u,e,p,t){
	p = p.replace('#', '{CARDINAL}');
	p = p.replace('?', '{QUESTION_MARK}');
	p = p.replace('&', '{AND}');
	p = p.replace("'", '{APOSTROPHE}');
	createAndShowPopin('register.php?ajax=true&reg_username='+u+'&reg_email='+e+'&reg_pass='+p+'&reg_terms='+t+'&submit=true','');
}

function displayMoreOptions(){
	var $a_more_options = $('#a_more_options');
	if($a_more_options.hasClass('more_options')){
		$a_more_options.removeClass().addClass('more_options_on');
	}else{
		$a_more_options.removeClass().addClass('more_options');
	}

}

function save_search(s_url){
	var s_title = $("#search_title").val();

	$.get("/ax_save_search.php", {s_url: s_url, s_title: s_title},
		function(data){
			$("#save_search").html(data);
			setTimeout(function() {
				$('#save_search').fadeOut('slow');
			}, 5000);
	});
	return false;
}

function acc_comm_read(id){
	$.get("/ax_acc_comm_read.php", {comm_id: id},
		function(data){
			if(data!='') $("#link_comm_"+id).html(data);
	});
	return false;
}

function acc_comm_view(id){
	$.get("/ax_acc_comm_view.php", {comm_id: id},
		function(data){
			if(data!='') $("#view_comm_"+id).html(data);
	});
	return false;
}

function accept_all_buddy_requests(limit){
	for(i=0;i<limit;i++){
		accept_buddy_request(accBuddy[i], 'notification'+i,false,true,true);
	}
	$("#link_accept_decline").html('');
}

function reject_all_buddy_requests(limit){
	for(i=0;i<limit;i++){
		reject_buddy_request(accBuddy[i], 'notification_reject'+i,true);
	}
}

function img_loader(size, margin_top, margin_left){
	var extra = '';
	if(margin_top) extra = 'margin-top:'+margin_top+'px';
	if(margin_left) extra = 'margin-left:'+margin_left+'px';
	return '<img src="/images/loader_48.gif" width="'+size+'" height="'+size+'" border="0" id="img_loader" style="'+extra+'"/>';
}

/*function update_notify_menu_icon(){
	$.get("/ax_update_notify_menu_count.php",
		function(data){
			if(data!=""){
				if(data>0){
					$('.hd_logged .updates').css('display','block');
					$('.hd_logged .updates').html(data);
				}else{
					$('.hd_logged .updates').remove();
				}
			}
		}
	);
}
setInterval("update_notify_menu_icon();", 10000);
*/

function delete_panorama_element(id){
	var r = confirm("Really delete panorama item?");
	if(r){
		$.get("/ax_delete_panorama_element.php", {id: id},
			function(data){
				$("#panorama_"+id).hide('slow',function(){
					$(this).remove();
				});
		});
	}
	return false;
}

