


$.fn.exist = function(){
	return $(this).length>0; 
	return $(this)=obj;
}
$.fn.unexist = function(){
	return $(this).length==0;
	return $(this)!=obj;
}
 


// the tabs
$.tabs = function(containerId, start) {
    var ON_CLASS = 'active';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();
    $(id + '>ul>li:nth-child(' + i + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').animate({opacity:'hide'},200, function(){target.animate({opacity:'show'},200); });
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                //
            }
        }
        return false;
    });
};


$(document).ready(function(){
	var cbs = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera\s(\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();
    jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

      $("body").click(function(){
       if($(".dropBtn").hasClass("dropBtnHover")){}
       else{
          if($(".show_drop").exist()){
            $(".show_drop").removeClass("show_drop")
          }
       }

     });
$(".dropBtn").mouseover(function(){
    $(this).addClass("dropBtnHover");
});
$(".dropBtn").mouseout(function(){
    $(this).removeClass("dropBtnHover");
});


    //slider
    $("#bar").after("<div class='c'><!-- --></div>")
	var container = $('#slider');
	var ul = $('ul', container);
	var itemsWidth = ul.innerWidth() - container.outerWidth();
	$('.slider', container).slider({
	    minValue: 0,
	    maxValue: itemsWidth,
	    handle: '.handle',
	    stop: function (event, ui) {
	        ul.animate({'left' : ui.value* -1}, 500);
	         $("#topslider .handle").removeClass("handled");
	    },
	    slide: function (event, ui) {
	        ul.css('left',  ui.value* -1) , 500;
	        $("#slider .handle").addClass("handled");
	    }
	});

    //End of Slider


	var tabs = $(".tabs");
	for(var t=0;t<tabs.length; t++){
       tabs[t].setAttribute("id", "tab" + (t+1));
	}
    var select = $("select");
	for(var se=0;se<select.length; se++){
       select[se].setAttribute("id", "select" + (se+1));
	}
	//Form Tabs
	var search_engine = $.cookie("search_engine");
 	if(search_engine!=null){
       $("#search-nav a").removeClass("active");
	   $("#search-nav a[rel='" + search_engine + "']").addClass("active");
	}
	var tab_links = $("#search-nav a");
    tab_links.each(function(){
      	if($(this).hasClass("active")){
     		var form_id = $(this).attr("rel");
			$("#" + form_id).show();
     	}
    });
    tab_links.click(function(){
          tab_links.removeClass("active");
		  $("#search-form form").hide();
		  $(this).addClass("active");
          var form_id = $(this).attr("rel");
		  $("#" + form_id).show();
		  $.cookie("search_engine",form_id);
	});

    var drlist = $(".dropthis");
    var drbtn = $(".dropBtn");
	
	var drbtn1 = $("#dropBtn1_countries");
	
    var dr_active_html = $(".dropthis .active").html();
    $(".dropthis .active").parents(".relative").find(".dropBtn").html(dr_active_html);

    drbtn.each(function(){
        var dr_index = drbtn.index(this);
        $(this).attr("index", dr_index);
    });

    drbtn.click(function(){
       var drbtn_index =  $(this).attr("index");

       if($(this).hasClass("dropBtnHover")){}
       $(".show_drop").each(function(){
            if($(this).hasClass("dropBtnHover")){}
            else{
                 $(this).removeClass("show_drop");
            }
       });
       $(".dropthis:eq(" + drbtn_index + ")").toggleClass("show_drop");
       $(".ie6 .dropthis:eq(" + drbtn_index + 1 + ")").css("z-index", "-1");
       //alert(drbtn_index)
    });

    $(".ie6 .relative:eq(1)").css("z-index", "0")
    $(".ie6 .relative:eq(0)").click(function(){
         $(".ie6 .relative:eq(1)").css("z-index", "-1");
    });


    var richtables =  $(".richtext table, table.richtext");
    richtables.each(function(){
        var richcells = $(this).find("td");
        var richpadding = $(this).attr("cellpadding");
        richcells.css("padding", richpadding + "px");
    });


    $("#navigation-bar li:last-child a, .navs-bar li:last-child a").css("border", "none");
    $("#footer-navigation").css("marginLeft", $("#foot-wrap").width()/2 - $("#footer-navigation").width()/2)
    $("#footer-actions ul").css("marginLeft", $("#footer-actions").width()/2 - $("#footer-actions ul").width()/2)
    $(".more-countries").click(function(){
    	$(this).toggleClass("show-more-countries");
		if($(window).width()>1400){
          $(".more-countries ul").css("left", "-1px");
		}
		else if($(window).width()<1400){
           $(".more-countries ul").css("left", -$(".more-countries ul").width()+24);
		}
	});
    $(".more-countries ul").css("bottom", - $(".more-countries ul").height() - 6);
    $("#news-list li:odd").addClass("even");
    $("#search-types .bull:last").css("marginLeft", "25px");
    $(".tab-links li:last-child").css("border", "none");
	$(".tab-links").after("<span class='br'></span>");

	var tab1 = $("#tab1");if(tab1){$.tabs("tab1")}var tab2 = $("#tab2");if(tab2){$.tabs("tab2")}var tab3 = $("#tab3");if(tab3){$.tabs("tab3")}
    var tab4 = $("#tab4");if(tab4){$.tabs("tab4")}var tab5 = $("#tab4");if(tab5){$.tabs("tab5")}var tab6 = $("#tab6");if(tab6){$.tabs("tab6")}

	/*var select1 = $("#select1"); var select2 = $("#select2"); var select3 = $("#select3"); var select4 = $("#select4");
    var select5 = $("#select5"); var select6 = $("#select6"); var select7 = $("#select7"); var select8 = $("#select8");

    $("select").each(function(){
        if($(this).hasClass("noselect")){}
        else{
            $(this).selectbox();

        }
    });
    select1.selectbox();select2.selectbox(); select3.selectbox();
    select4.selectbox();select5.selectbox(); select6.selectbox();
    select7.selectbox();select8.selectbox(); */


		$("#main #news-container .new:nth-child(3n)").addClass("third_new");
        if($("#news-container").hasClass("nobr")){}
        else{
          $("#news-container .new:nth-child(4)").addClass("c");
        }



     $(".ie6 #comments-form input").before("<div style='height:0px;overflow:hidden;clear:both'><!-- --></div>");

    $("a[href='#']").attr('href', 'javascript:;');

    $(".category-nav li:first-child a:first").css("backgroundImage", "none");
	$(".category-nav:first").addClass("first-category-nav");
	$(".breadcrumb li:last-child").css("background", "none");
	var cat_height = $("#category-bar").height();
    var main_in_height = $("#inner-main").height();
	if(cat_height<main_in_height){
       $("#category-bar").height(main_in_height-25);
	}
	slogan = $("#logo-and-slogan a span").html();
	$(".c, #scroll").before("<div style='clear:both;height:1px;overflow:hidden'><!--  --></div>");



var fav = $("#add-to-favourites a");
var fav_title = "ИНТЕРНАЦИОНАЛЕН  ПОРТАЛ  ЗА  ИМОТИ";
var fav_url = "http://www.look-estates.com";

fav.click(function(){
	var html =  $("html");
	if(html.hasClass("gecko")){
       window.sidebar.addPanel(fav_title, fav_url, "");
	}
	else if(html.hasClass("ie")){
        window.external.AddFavorite(fav_title, fav_url);
	}
	else if(html.hasClass("opera")){
    	var elem = document.createElement('a');
		elem.setAttribute('href', fav_url);
		elem.setAttribute('title', fav_title);
		elem.setAttribute('rel', 'sidebar');
		elem.click();
	}
});

$("#English a").click(function(){
	curr_loc = window.location.href;
	en_url = "http://66.102.1.113/translate_c?hl=en&sl=bg&tl=en&u=" + curr_loc + "&prev=_t&usg=ALkJrhhw_oIa4MjGQgqA0wMv5l_5vMjfJg"
	window.location.href = en_url;




	
});


  $("#the_map_search").hover(function(){
      $("#search-types").addClass("search-types-red");
    }, function(){
      $("#search-types").removeClass("search-types-red");
  });





});








/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function makehomepage($addHomePage)
{
       theobj = document.anchors[0];  
       theobj.style.behavior='url(#default#homepage)';
       theobj.makehomepage($addHomePage);
}


