// FCK FUNCTIONS

var FCKeditorLoaded = false;
function FCKeditor_OnComplete(editorInstance) {
  FCKeditorLoaded = true;
}
function switchEditors(ID) {
  if(!FCKeditorLoaded) {
    setTimeout('switchEditors(\'' + ID + '\')', 500);
    return;
  }
  DoSwitchEditors(document.getElementById(ID));
}
function DoSwitchEditors(oNode) {
  var i;
  for (i = 0; i < oNode.childNodes.length;i++) {
    childNode = oNode.childNodes.item(i);
    editor = FCKeditorAPI.GetInstance(childNode.name);
    if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG) {
      editor.SwitchEditMode();
      editor.SwitchEditMode();
    }
    DoSwitchEditors(childNode);
  }
}

// SWAP IMAGES FUNCTIONS

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addBookmarkMV(url, title) {
        if (window.sidebar) { // firefox
              window.sidebar.addPanel(title, url,"");
        } else if( document.all ) { //MSIE
                window.external.AddFavorite( url, title);
        } else {
               alert("Sorry, your browser doesn't support this");
        }
}	

function toogle(element){
	$(element).toggle();
}

function show(element){
	$(element).show();
}

function hide(element){
	$(element).hide();
}

function swicth_sections_visibility(div){
	hide('#buy_sell_bar');
	hide('#community_bar');
	show('#'+div+"_bar");
}

function tellfriend(sending_message){
	var tell_name=$("#hmt_name").val();
	var tell_email=$("#hmt_email").val();
	var tell_fname=$("#hmt_fname").val();
	var tell_femail=$("#hmt_femail").val();
	var tell_text=$("#hmt_comments").val();
	
	$("#recommend_open").html("<div class='msg'><span class='sending'>"+sending_message+"</span></div>");
	
	$.get("/ax_hm_tell_friend.php", {tell_name: tell_name, tell_email: tell_email, tell_fname: tell_fname, tell_femail: tell_femail, tell_text: tell_text},
		function(data){
			$("#recommend_open").html(data);	
	});
}

function ins_tellfriend_wkhorse(wkhorse_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	$.get("/ax_wkhorse_tellfriend.php", {wkhorse_id: wkhorse_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#wkhorse_tellfriend").html(data);	
	});
}

function ins_tellfriend_voucher(voucher_id){
	var cm_name = $("#tf_name").val();
	var cm_email = $("#tf_email").val();
	var cm_fname = $("#tf_fname").val();
	var cm_femail = $("#tf_femail").val();
	var cm_text = $("#tf_text").val();
	$.get("/ax_voucher_tellfriend.php", {voucher_id: voucher_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#voucher_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_video(video_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	$.get("/ax_video_tellfriend.php", {video_id: video_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#video_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_ad(ad_id){
	var cm_name = $("#tf_name").val();
	var cm_email = $("#tf_email").val();
	var cm_fname = $("#tf_fname").val();
	var cm_femail = $("#tf_femail").val();
	var cm_text = $("#tf_text").val();
	
	$.get("/ax_ad_tellfriend.php", {ad_id: ad_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#ad_tellfriend").html(data);	
	});

	return false;
}

function ins_tellfriend_article(ref_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();

	$.get("/ax_article_tellfriend.php", {article_id: ref_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#article_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_race(ref_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	
	$.get("/ax_race_tellfriend.php", {ref_id: ref_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#race_tellfriend").html(data);	
	});
	return false;
}

function tell_friend(ref_id, sending_message){
	var tellhorse_name = $("#tell_name").val();
	var tellhorse_email = $("#tell_email").val();
	var tellhorse_text = $("#tell_text").val();
	
	$("#ctt_horse_tell").html(sending_message);	
	
	$.get("/ax_horse_tell_friend.php", {horse_id: ref_id, tellhorse_name: tellhorse_name, tellhorse_email: tellhorse_email, tellhorse_text: tellhorse_text, type: 'ins'},
		function(data){
			$("#ctt_horse_tell").html(data);	
	});
	
	return false;
}

function ins_favourite(type, req_id){
	$.get("/ax_"+type+"_fav.php", {req_id: req_id},
		function(data){
			$("#"+type+"_fav").html(data);	
	});
	return false;
}

function ins_comment(type, req_id, is_logged){
	var cm_text = $("#comm_text").val();
	var cm_name = "";
	var cm_email = "";
	
	if(is_logged==null) is_logged=1;
	
	if(!is_logged){
		cm_name = $("#comm_name").val();
		cm_email = $("#comm_email").val();
	}
	$.get("/ax_"+type+"_comment.php", {req_id: req_id, cm_name: cm_name, cm_email: cm_email, cm_text: cm_text, type: "ins"},
		function(data){
			$("#"+type+"_ins_comm").html(data);	
	});
	return false;
}

function add_testimonial(sending_message){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_text = $("#c_text").val();
	
	$("#testimonial").html(sending_message);	
	
	$.get("/ax_save_testimonial.php", {cm_text: cm_text, cm_name: cm_name, cm_email: cm_email},
		function(data){
			$("#testimonial").html(data);	
	});
	return false;
}

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);	
	});
	return false;
}

function ins_admsg(ad_id, logged, sending_message){
	var pm_text = $("#p_text").val();
	var pm_email = $("#p_email").val();
	var pm_phone = $("#p_phone").val();
	if(logged==1) var pm_captcha = "";
	else var pm_captcha = $("#ctc_captcha").val();
	
	$("#ad_msg").html(sending_message);	
	
	$.get("/ax_ad_send_email.php", {ad_id: ad_id, pm_text: pm_text, pm_email: pm_email, pm_phone: pm_phone, pm_captcha: pm_captcha},
		function(data){
			$("#ad_msg").html(data);	
	});
	return false;
}

function ins_ads_review(id, logged){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_phone = $("#c_phone").val();
	var cm_text = $("#c_text").val();
	var cm_rating = $("#c_rating").val();
	if(logged==1) var cm_captcha = "";
	else var cm_captcha = $("#c_captcha").val();
	
	$.get("/ax_ads_review.php", {id: id, cm_name: cm_name, cm_email: cm_email, cm_phone: cm_phone, cm_text: cm_text, cm_rating: cm_rating, cm_captcha: cm_captcha, type: "ins"},
		function(data){
			$("#ad_ins_rev").html(data);	
	});

	return false;
}

function chp_photo(id, img_path, img_width, img_height, img_id, progeny){
	document.images["ads_photo"].src = img_path;
	document.images["ads_photo"].width = img_width;
	document.images["ads_photo"].height = img_height;
	
	var js = "popin_photo("+img_id+", "+progeny+");";
	// create a function from the "js" string
    var newclick = new Function(js);
	
	$('#big_photo_link').attr('onclick', '').click(newclick);
	$('#big_photo_link1').attr('onclick', '').click(newclick);
	
	$.get("/ax_save_views_photo.php", {id: id});
}

function save_question(sending_message){
	var consult_sec = $("#consult_sec").val();
	var cm_text = $("#c_text").val();

	$("#question").html(sending_message);	
	
	$.get("/ax_save_question.php", {consult_id: consult_sec, cm_text: cm_text},
		function(data){
			$("#question").html(data);	
	});
	return false;
}

function clip_ad(ad_id, sending_message){
	$("#clip_ad_"+ad_id).html(sending_message);	
	
	$.get("/ax_ad_clip_list.php", {ad_id: ad_id},
		function(data){
			$("#clip_ad_"+ad_id).html(data);	
	});
	return false;
}

function show_awards(loading_message, award_id, horse_id){
	$("#award_details").html("<div style='margin:10px;'><span class='sending'>"+loading_message+"...</span></div>");
	
	open_popin2();
	
	$.get("/ax_award_details.php", {award_id: award_id, horse_id: horse_id},
		function(data){
			$("#award_details").html(data);	
	});
}

function ins_expert(race_id){
	var cm_name = $("#ce_name").val();
	var cm_email = $("#ce_email").val();
	var cm_bio = $("#ce_bio").val();
	
	$.get("/ax_race_expert.php", {race_id: race_id, cm_name: cm_name, cm_email: cm_email, cm_bio: cm_bio},
		function(data){
			$("#race_expert").html(data);	
	});

	return false;
}

function save_wiki(text_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_'+text_id+'_txt');
	var wiki_text = oEditor.GetXHTML(true);
	
	$.get("/ax_save_wiki_race.php", {text_id: text_id, wiki_text: wiki_text},
		function(data){
			$("#txt_"+text_id+"_edit").html(data);	
	});
	
	return false;
}

function new_wiki(race_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_text');
	var wiki_text = oEditor.GetXHTML(true);
	var wiki_title = $("#wiki_title").val();
	
	$.get("/ax_new_wiki_race_text.php", {wiki_title: wiki_title, wiki_text: wiki_text, wiki_race: race_id},
		function(data){
			$("#txt_0_edit").html(data);	
	});

	return false;
}

function inse_link(race_id, sending_message){
	var cm_text = $("#c_text").val();
	var cm_title = $("#c_ltitle").val();
	var cm_url = $("#c_lurl").val();
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();

	$("#race_link").html(sending_message);	
	
	$.get("/ax_race_link.php", {race_id: race_id, cm_text: cm_text, cm_title: cm_title, cm_url: cm_url, cm_name: cm_name, cm_email: cm_email},
		function(data){
			$("#race_link").html(data);	
	});
	return false;
}


function send_message_horse(horse_id, sending_message){
	var pm_title = $("#msg_title").val();
	var pm_text = $("#msg_text").val();	
	
	$("#ctt_horse_msg").html(sending_message);
	
	$.get("/ax_send_pm.php", {horse_id: horse_id, pm_title: pm_title, pm_text: pm_text},
		function(data){
			$("#ctt_horse_msg").html(data);	
	});
	return false;
}

function send_message_member(user_id, sending_message){
	var pm_title = $("#c_title").val();
	var pm_text = $("#c_text").val();	
	
	$("#ctt_user_msg").html(sending_message);
	
	$.get("/ax_send_pm.php", {user_id: user_id, pm_title: pm_title, pm_text: pm_text},
		function(data){
			$("#ctt_user_msg").html(data);	
	});
	return false;
}

function give_treat(horse_id, treat_id, sending_message){
	$("#ctt_horse_treat").html(sending_message);
	
	$.get("/ax_give_treat.php", {horse_id: horse_id, treat_id: treat_id},
		function(data){
			$("#ctt_horse_treat").html(data);	
	});
	return false;
}

function give_award(horse_id, award_id, sending_message){
	$("#ctt_horse_award").html(sending_message);
	
	$.get("/ax_give_award.php", {horse_id: horse_id, award_id: award_id},
		function(data){
			$("#ctt_horse_award").html(data);	
	});
	return false;
}

function add_favourite(horse_id){
	$.get("/ax_fav_horse.php", {horse_id: horse_id},
		function(data){
			$("#ctt_horse_fav").html(data);	
	});
	return false;
}

function remove_favourite(horse_id){
	$.get("/ax_fav_horse_remove.php", {horse_id: horse_id},
		function(data){
			$("#ctt_horse_fav").html(data);	
	});
	return false;
}

function make_buddy_horse(horse_id, sending_message){
	var horsebuddy_id = $("#buddy_horse").val();
	var horsebuddy_text = $("#buddy_text").val();	
	
	$("#ctt_horse_buddy").html(sending_message);
	
	$.get("/ax_add_buddy.php", {horse_id: horse_id, horsebuddy_id: horsebuddy_id, horsebuddy_text: horsebuddy_text, type: 'ins'},
		function(data){
			$("#ctt_horse_buddy").html(data);	
	});
	return false;
}

function make_buddy_member(user_id, sending_message){
	var userbuddy_text = $("#buddy_text").val();
	
	$("#ctt_user_buddy").html(sending_message);
	
	$.get("/ax_add_user_buddy.php", {user_id: user_id, userbuddy_text: userbuddy_text, type: 'ins'},
		function(data){
			$("#ctt_user_buddy").html(data);	
	});
	return false;
}

function send_comment(horse_id, sending_message){
	var cm_text = $("#c_text").val();	
	
	$("#ctt_horse_comm").html(sending_message);
	
	$.get("/ax_horse_comment.php", {horse_id: horse_id, cm_text: cm_text},
		function(data){
			$("#ctt_horse_comm").html(data);	
	});
	return false;
}

function block_user(user_id){
	$.get("/ax_block_user.php", {user_id: user_id},
		function(data){
			$("#ctt_user_block").html(data);	
	});
	return false;
}

function unblock_user(user_id){
	$.get("/ax_unblock_user.php", {user_id: user_id},
		function(data){
			$("#ctt_user_block").html(data);	
	});
	return false;
}

var step_featured_ads=1;
function more_featured_ads(p){
	step_featured_ads=step_featured_ads+p;
	
	$.get("/ax_more_featured_ads.php", {page: step_featured_ads},
		function(data){
			$(".items_featured").html(data);	
	});
	return false;
}

function more_featured_ads_b(p){
	step_featured_ads=step_featured_ads+p;
	
	$.get("/ax_more_featured_ads_b.php", {page: step_featured_ads},
		function(data){
			$(".items_featured").html(data);	
	});
	return false;
}

function offer_like(id){
	$.get("/ax_offer_like.php", {offer_id: id},
		function(data){
			if(data!='') $("#nr_likes_"+id).html(data);	
	});
	return false;
}

function like(type, id){
	$.get("/ax_like.php", {type: type, ref_id: id},
		function(data){
			if(data!='') $("#nr_likes").html(data);	
	});
	return false;
}

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 popin_photo(photo_id, progeny){	
	var window_dimentsions = get_window_dimentsions();	
	var x, y;
	
	x=Math.round(window_dimentsions.Width / 2);
	y=Math.round(window_dimentsions.Height / 2)+$(window).scrollTop();
	
	$.getJSON("/ax_popin_photo.php", {id: photo_id, progeny: progeny},
		function(data){
			if(data.message!=''){
				$("#html_popin_photo").html(data.message);	
				$("#global_div").addClass("opac_div");	
				
				x = x-Math.round((parseInt(data.width)+40) / 2);
				y = y-Math.round((parseInt(data.height)+110) / 2);
				if(y<35) y=35;	
				
				$("#html_popin_photo").css('left', x + 'px');
				$("#html_popin_photo").css('top', y + 'px');
				show("#html_popin_photo");
			}
	});
	
	return false;
}

function close_popin_photo(){
	$("#global_div").removeClass("opac_div");	
	$("#html_popin_photo").css('display', 'none');
}

function add_dream_stable(ad_id){
	$.get("/ax_add_dream_stable.php", {ad_id: ad_id},
		function(data){
			if(data!='') $("#popin_dream_html").html(data);	
	});
	return false;
}

function remove_dream_stable(id){
	$.get("/ax_remove_dream_stable.php", {id: id},
		function(data){
			if(data=="true"){
				$("#stable_"+id).remove();	
				$("#num_horses").html((parseInt($("#num_horses").html())-1));
			}
	});
	return false;
}

function add_form_vote(entry_id){
	$.get("/ax_add_form_vote.php", {entry_id: entry_id},
		function(data){
			if(data!=''){
				$('.vote').removeClass('vote_sel');
				$("#vote_"+entry_id).addClass("vote_sel");
				$("#vote_"+entry_id).btOn();
			}
	});
	return false;
}

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);
				}
		});
	}, 2000);
}

function get_ads_uploaded_photos(objid,acode){
	$.get("/ax_get_temp_uploaded_photos.php", { scode: acode },
		function(data){
			$('#'+objid).html(data);
		}
	);
}

var oldId='';
function setMainUploadedImage(id){
	$.ajax({
		type: "GET",
		url: "ax_uploaded_image_setmain.php",
		data: "id=" + id+"&oldId=" + oldId,
		success: function(msg){
			if(msg=='success'){
				$('.mainUploadedImage').removeClass('mainUploadedImage');
				
				$("div[id^='uploadedImage']").css('background-color','#F2F2F2');
				$("div[id^='uploadedImage']").css('border','2px solid #F2F2F2');
				$("img[class^='removeUploadedImage']").hide();
				
				$('#uploadedImage'+id).css('background-color','#09C');
				$('#uploadedImage'+id).css('border','2px solid #09C');
				$('.removeUploadedImage'+id).show();
				
				oldId = id;
			}else{
				alert(msg);
			}
		}
	});
}

function removeUploadedImage(id){
	$.ajax({
		type: "GET",
		url: "ax_uploaded_image_remove.php",
		data: "id=" + id,
		success: function(msg){
			if(msg=='success'){
				$('#uploadedImage'+id).fadeOut(200,function(){
					$(this).remove();
				});
			}else{
				alert(msg);
			}
		}
	});
}

function ads_set_main_image(id){
	$.get("/ax_ads_set_main_image.php", {id: id},
		function(msg){
			if(msg=='success'){
				$('.mainUploadedImage').removeClass('mainUploadedImage');
				
				$("div[id^='uploadedImage']").css('background-color','#F2F2F2');
				$("div[id^='uploadedImage']").css('border','2px solid #F2F2F2');
				$("img[class^='removeUploadedImage']").hide();
				
				$('#uploadedImage'+id).css('background-color','#09C');
				$('#uploadedImage'+id).css('border','2px solid #09C');
				$('.removeUploadedImage'+id).show();
				
				$('.uploaded_photo').show();
				$('#remove_img_'+id).hide();
			}else{
				alert(msg);
			}
	});
}

function ads_remove_image(id){
	$.get("/ax_ads_remove_image.php", {id: id},
		function(msg){
			if(msg=='success'){
				$('#uploadedImage'+id).fadeOut(200,function(){
					$(this).remove();
				});
			}else{
				alert(msg);
			}
	});
}

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({
	  titleSelector: "sss",
	  trigger:trigger,
	  width:width,	
	  fill: bgColor,
	  spaceTop:spaceTop, 
	  strokeStyle: strokeColor, 
	  strokeWidth:1,
	  spikeLength: spikeLength, 
	  spikeGirth: spikeGirth, 
	  padding: padding, 
	  cornerRadius: 5, 
	  spikePosition:spikePosition,
	  centerPointX:pointX,
	  shadow:           true,
	  shadowOffsetX:    0,                     // shadow offset x (px)
	  shadowOffsetY:    2,                     // shadow offset y (px)
	  shadowBlur:       3,                     // shadow blur (px)
	  shadowColor:      "#aaa",
	  positions: [position],
	  cssStyles: {
	    fontFamily: '"verdana"', 
	    fontWeight:fontWeight,
	    textAlign:textAlign,
	    fontSize: fontSize,
	    color:fontColor,
		marginLeft: margin
	  }
	});
}

function take_over_effect(bgcolor, bgimg, bgrepeat, transparency_level){
	if(bgcolor=='') bgcolor="#fff";
	
	$("#take_over_wrapper").addClass('take_over_wrapper');
	
	var page_offset = $('#take_over_wrapper').offset();
	
	var left = page_offset.left - $('.to_left_skyscrapper').width() - 9;
	
	$(".to_left_skyscrapper").css('left', left + 'px');
	$(".to_right_skyscrapper").css('right', left + 'px');
	$(".to_left_skyscrapper").css('top', $('.hd_top').height() + 'px');
	$(".to_right_skyscrapper").css('top', $('.hd_top').height() + 'px');
	
	if($("body").width()<$('#page').width()){
		$("body").css("width", $('#page').width()+"px");
		$("html").css("width", $('#page').width()+"px");
	}
	else{
		$("body").css("overflow-x", "hidden");
	}
	
	if(bgcolor!=''){
		$(".hd_top").css("background-image", "none");
		$("body").css("background-color", bgcolor);
		if(bgimg!=''){
			$("body").css("background-image", "url('/img/take_over/"+bgimg+"')");
			if(bgrepeat!="no-repeat") $("body").css("background-position", "center");
			$("body").css("background-repeat", bgrepeat);
		}
		$(".hd_top .in").addClass("in_transparency"+transparency_level);
	}
}

function switch_usermenu_visibility(){
	toogle('.usermenu');
	if($('.usermenu_top').hasClass('usermenu_top_sel')) $('.usermenu_top').removeClass('usermenu_top_sel');
	else $('.usermenu_top').addClass('usermenu_top_sel');
}

function focus_hd_search(default_text){
	if($('#search_string').val(default_text)) $('#search_string').val('');

	$(".search_bar .in").addClass("in_focus");	
	hide($(".search_bar .tools"));
	show('#hd_other_filters');	
}

function blur_hd_search(default_text){
	if($('#search_string').val()=='') $('#search_string').val(default_text);
	/*$(".search_bar .in").removeClass("in_focus");
	hide('#hd_other_filters');	
	show($(".search_bar .tools"));*/
}

var map_opened_global=0;
function switch_map_visibility(show_label, hide_label, host, mapwhere, map_opened){
	if($('.iframe_map').hasClass('iframe_map_opened')){
		$('.iframe_map').removeClass('iframe_map_opened');
		$('.iframe_map').addClass('iframe_map_closed');
		$('.ads_list_map a').removeClass('opened');
		$('.ads_list_map a').addClass('closed');
		$('.ads_list_map a span').html(show_label);
	}
	else{
		$('.iframe_map').removeClass('iframe_map_closed');
		$('.iframe_map').addClass('iframe_map_opened');
		$('.ads_list_map a').removeClass('closed');
		$('.ads_list_map a').addClass('opened');
		$('.ads_list_map a span').html(hide_label);
		if(map_opened==0 && map_opened_global==0) $('.iframe_map').html("<iframe id=\"iframe_map\" src=\"http://"+host+"/ads_map_list.php?wheremap="+mapwhere+"\" width=\"665\" height=\"450\" frameborder=\"0\" scrolling=\"no\"></iframe>");
		map_opened=1;
		map_opened_global=1;
	}
}

function ad_show_phone_mobile(ad_id, field){
	$.get("/ax_ad_show_phone_mobile.php", {ad_id: ad_id, field: field});
	hide('#ad_'+field+'_label');
	show('#ad_'+field+'_number');
}
