function preloadImages() {
	  var d=document; if(d.images){ if(!d.p) d.p=new Array();
	    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
	}
function slideSwitch() {
	$('.inactive').hide();
	$('#slideshow .img').removeClass('inactive');
	var $active = $('#slideshow .active');
   
    if ( $active.length == 0 ) $active = $('#slideshow .img:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow .img:first');


    
//    $active.addClass('last-active').hide();
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .fadeTo(1000,1,function() {
            $active.removeClass('active last-active');
        });
    $active.css({opacity: 1})
		   
		    .fadeTo(1000,0,function() {
		   
		    	
		    });
//        .show()
//        .animate({opacity: 1.0}, 1500, function() {
//            $active.removeClass('active last-active');
//        });
};


$(function() {
//	$(document).pngFix();
	
	/*equel columns*/
	//set the starting bigestHeight variable  
	var biggestHeight = 0;  
	//check each of them  
	$('.equal_height').each(function(){  
	   //if the height of the current element is  
	   //bigger then the current biggestHeight value  
	  if($(this).height() > biggestHeight){  
	       //update the biggestHeight with the  
	       //height of the current elements  
	       biggestHeight = $(this).height();  
	   }  
	});  
	//when checking for biggestHeight is done set that  
	//height to all the elements  
	$('.equal_height').height(biggestHeight);  
	/*end*/
	
	/*slideshow*/
	if (!$) return;
		$.fn.extend({
		    fixPNG: function(sizingMethod, forceBG) {
		            if (!($.browser.msie)) return this;
		            var emptyimg = "images/dot_alpha.gif"; //Path to empty 1x1px GIF goes here
		            sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
		            this.each(function() {
		                    var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
		                            imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
		                            src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
		                    this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
		                    if (isImg) this.src = emptyimg;
		                    else this.style.backgroundImage = "url(" + emptyimg + ")";
		            });
		            return this;
		    }
		});
	$('#slideshow .img').fixPNG();
	preloadImages(
			  "images/luxury.png", 
			  "images/luxury-select.png",
			  "images/just-selected.png",
			  "images/just.png",
			  "images/close-select.png",
			  "images/close.png",
			  "images/image/border-top-menu.png",
			  "images/image/border-content-menu.png",
			  "images/image/border-bottom-menu.png",
			  "images/line-menu.png",
			  "images/backgroundmenu.png"
			 );
	
	$(".mainMenuLi").live('mouseenter',function(){
		$(this).addClass('showSubmenu');
		var $link = $(this).find('.hrefpointer');
		var a = $link.width();
//		var b = $link.next();
//		b=b[0].offsetWidth;
		var c = $link.next().find('.sub_ul').length;
//		var total = 700/c;
//		alert(total);
//		$(".sub_ul").css ("width",315);
//		var real = $(".sub_ul").width();
//		alert($(".sub_ul").width());
		var sum = -317*c/2 + a/2;
		var $marginLeft =''+sum + 'px';
		//alert ('menu'+ a + 'submenu' + b + 'rez' + sum);
		$link.next().css({'margin-left': $marginLeft});
		$link.next().css({'zIndex': 10000});
	});
	
	$(".mainMenuLi").live('mouseleave',function(){
		$(this).removeClass('showSubmenu');
	});
	
	$(".nr").live('keydown', function(event) {
		if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 16 || event.keyCode == 45) {
		} else {
			if (event.keyCode < 95) {
				if (event.keyCode < 48 || event.keyCode > 57 ) {
					event.preventDefault();
				}
			} else {
				if (event.keyCode < 96 || event.keyCode > 105 ) {
					event.preventDefault();
				}
			}
		
		}
	});

	setInterval( "slideSwitch()", 9000 );
	
//	$('.allcommunities > .ulcommunities a').click(function() {
//			
//		var url = $(this).attr("href").split('#')[1];
////		alert (url);
//		var val=$(this).attr("href").split('/')[1];
////		alert (val);
////		if (val != 'ajax-index') {$('.contentslide,.contentfirst'). addClass('hover');$('.contentsecond').hide(); slideStop();}
////			else { window.location='/';}//$('.contentslide,.contentfirst').removeClass('hover');$('.contentsecond').show(); slideStart();}
//		$.post(url, {},function(data){
//			$("#content").html(data);
//		},"html");
//		return false;
//	});
	
	
	/*Feature Prop*/

	var homeSliderTimer=null;
	
	$('.content_prop a[href^="#left"]').live('mousedown',function (event) {
		
		if (homeSliderTimer)clearInterval(homeSliderTimer);
		homeSliderTimer= setInterval(function(){
			$('.allproperties').scrollTo( '-=10px', 0, { axis:'x' });
		},50);
	});
	$('#allprop a[href^="#right"]').live('mousedown',function (event) {

		if (homeSliderTimer)clearInterval(homeSliderTimer);
		
		homeSliderTimer = setInterval(function(){
			$('.allproperties').scrollTo( '+=10px', 0, { axis:'x' });
		},50);
	});

	$('.content_prop a[href^="#right"]').live("dragstart", function() {
	     return false;
	});
	$('.content_prop a[href^="#left"]').live("dragstart", function() {
	     return false;
	});

	$('.content_prop a[href^="#left"]').live('mouseup',function () {
		if (homeSliderTimer)clearInterval(homeSliderTimer);
		return false;
	});
	$('.content_prop a[href^="#right"]').live('mouseup',function () {
		if (homeSliderTimer)clearInterval(homeSliderTimer);
		return false;
	});
	$('.content_prop a[href^="#left"]').live('mouseleave',function () {
		if (homeSliderTimer)clearInterval(homeSliderTimer);
		return false;
	});
	$('.content_prop a[href^="#right"]').live('mouseleave',function () {
		if (homeSliderTimer)clearInterval(homeSliderTimer);
		return false;
	});
	$('.content_prop a[href^="#right"]').live('click',function () {
		return false;
	})
	$('.content_prop a[href^="#left"]').live('click',function () {
		return false;
	});
//	$('.content_prop a[href^="#right"]').live('focus',function () {
//		return false;
//	})
//	$('.content_prop a[href^="#left"]').live('focus',function () {
//		return false;
//	});
	

	/*end FP*/
	
	/*Zip Map*/
	$('.description a[href^="#mapzip"]').live('click',function() {
		$('.divStyle').show();
		$('.mapzip').hide();
		$('.zipclose').show();
		
		return false;
	});
	$('.divimg a[href^="#zipclose"]').live('click',function() {
		$('.divStyle').hide();
		$('.mapzip').show();
		$('.zipclose').hide();
		return false;
	});
	$('.divimg a[href^="#imgmap"]').live('click',function() {
		$('.divStyle').hide();
		$('.mapzip').show();
		$('.zipclose').hide();
		return false;
	});
	/*end zip*/
	
	/*detalii*/
	
	$(".smallImg a").live('click', function(event){
		$(".smallImg a").removeClass("selected");
		$(this).addClass("selected");
		var _this=this;
		$(".bigImg img").addClass("fadeout");
		$(".bigImg ").prepend($('<img class="first fadein" src="'+_this.href+'"/>').hide());
		$(".bigImg img.fadeout").fadeOut(2000);
		$(".bigImg img.fadein").fadeIn(2000);
		$(".bigImg img").removeClass("fadeout").removeClass("fadein");

		return false;  
	});
	/*end detalii*/
	
	$("#viewmap").fancybox({
		'width'				: '60%',
		'height'			: '100%',
		'autoScale'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'type'				: 'iframe'
	});
	
	$("#payment").fancybox({
		'width'				: '50%',
		'height'			: '60%',
		'autoScale'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
//		'type'				: 'iframe'
	});
	
	$("#req_info").fancybox({
		'width'				: '60%',
		'height'			: '80%',
		'autoScale'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
//		'type'				: 'iframe'
	});
	
	$("#req_showing").fancybox({
		'width'				: '50%',
		'height'			: '80%',
		'autoScale'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
//		'type'				: 'iframe'
	});
	
	
	/*Sort*/
	
	$("select[name=sort]").change(function(event){

		var stringul = $(".selectedPage").attr("href");
		if(stringul.indexOf("sort") != -1)
		{

			var pairs = stringul.split("&");
		    var i = pairs.length - 1;
		    for (; i > -1; i--) {
		    	if(pairs[i].indexOf("sort=") != -1) {
		    		pairs[i] = "sort="+$("#sort option:selected").val();
		    		break;
		    	}
		    }
		    url = pairs.join("&");
		}else
		{
			var url = $(".selectedPage").attr("href")+"&sort="+$("#sort option:selected").val();
		}

		window.location = url;
		return false;
	});
	/*endsort*/
	
	
	/*home*/
//	$('.title a[href^="#"]').each(function () {
//		var $this = $(this);
//		var url = $(this).attr("href").split('#')[1];
//		
//		$.post(url,{}, function (data) {
//			$('#'+$this.attr('id')+'_content').html(data);
//		},"html");
//	})
//	
	if ($('#sale_tab_content .allproperties').children().size() < 1)
	{
		$('#sale_tab_content .allproperties').append('<div id="tab-loader"></div>');
		$.post("index/ajax-sale-prop",{}, function (data) {
//			alert(data);
			$('#sale_tab_content .allproperties').html(data);
			updateArrowVisibility('#sale_tab_content');
		},"text");
	}
	$('.title a[href^="#"]').live('click',function () {
		$('.left_butt').hide();
		$('.right_butt').hide();
		$('.allproperties').removeClass('space');
		var $this = $(this);
		var url = $(this).attr("href").split('#')[1];
		
		if ($('#'+$this.attr('id')+'_content .allproperties').children().size() < 1 )
		{
			$('#'+$this.attr('id')+'_content .allproperties').append('<div id="tab-loader"></div>');
			$.post(url,{}, function (data) {
				$('#'+$this.attr('id')+'_content .allproperties').html(data);
				
				updateArrowVisibility('#'+$this.attr('id')+'_content');
			},"text");
		}
		else 
		{
			updateArrowVisibility('#'+$this.attr('id')+'_content');
		}
	})
	
	function updateArrowVisibility(id)
	{
		var nb = $(id+' .properties').length;
//		console.log(nb);
		if (nb>4) 
		{
			$('.left_butt').show();
			$('.right_butt').show();
			$('.allproperties').removeClass('space');
		} 
		else{
			$('.left_butt').hide();
			$('.right_butt').hide();
			$('.allproperties').addClass('space');
		}
	}
	
	$('.title a[href^="#index/ajax-sale-prop"]').live('click',function() {
		
		$(this).addClass('selected');
		$('#listed_tab').removeClass('selected');
		$('#sold_tab').removeClass('selected');
		$('#best_tab').removeClass('selected');
		$(".sale_prop").removeClass("sel");
		$(".list_prop").removeClass("sel");
		$(".sold_prop").removeClass("sel");
		$(".best_prop").removeClass("sel");
		$(".sale_prop").addClass("sel");
		$('.sale_prop').show();
		$('.sold_prop').hide();
		$('.list_prop').hide();
		$('.best_prop').hide();
		return false;
	});
	
	
	$('.title a[href^="#index/ajax-just-listed"]').live('click',function() {
			
		$(this).addClass('selected');
		$('#sale_tab').removeClass('selected');
		$('#sold_tab').removeClass('selected');
		$('#best_tab').removeClass('selected');
		$(".sale_prop").removeClass("sel");
		$(".list_prop").removeClass("sel");
		$(".sold_prop").removeClass("sel");
		$(".best_prop").removeClass("sel");
		$(".list_prop").addClass("sel");
		$('.list_prop').show();
		$('.sale_prop').hide();
		$('.sold_prop').hide();
		$('.best_prop').hide();
		return false;
	});
	
	$('.title a[href^="#index/ajax-sold-prop"]').live('click',function() {
		$(this).addClass('selected');
		$('#sale_tab').removeClass('selected');
		$('#listed_tab').removeClass('selected');
		$('#best_tab').removeClass('selected');
		$(".sale_prop").removeClass("sel");
		$(".list_prop").removeClass("sel");
		$(".sold_prop").removeClass("sel");
		$(".best_prop").removeClass("sel");
		$(".sold_prop").addClass("sel");
		$('.sold_prop').show();
		$('.sale_prop').hide();
		$('.list_prop').hide();
		$('.best_prop').hide();
		return false;
	});
	$('.title a[href^="#index/ajax-best-prop"]').live('click',function() {
		$(this).addClass('selected');
		$('#sale_tab').removeClass('selected');
		$('#listed_tab').removeClass('selected');
		$('#sold_tab').removeClass('selected');
		$(".sale_prop").removeClass("sel");
		$(".list_prop").removeClass("sel");
		$(".sold_prop").removeClass("sel");
		$(".best_prop").removeClass("sel");
		$(".best_prop").addClass("sel");
		$('.best_prop').show();
		$('.sold_prop').hide();
		$('.sale_prop').hide();
		$('.list_prop').hide();
		
		return false;
	});
	/**/
	$('.button a[href^="#reset_lot"]').live('click',function() {
		$('#waterfront').val('');
		$('#type').val('');
		$('#selectmls').val('');
		$('#selmaxacres').val('');
		$('#selminacres').val('');
		$('#development').val('');
		$('#selmaxprice').val('');
		$('#selminprice').val('');
		
		return false;
	});
	$('.button a[href^="#reset"]').live('click',function() {
		$('input[name="rdforeclosure"]:first').attr('checked', true);
		$('#rearexposure').val('');
		$('#selmaxflunit').val('');
		$('#selminflunit').val('');
		$('#pets').val('');
		$('#community').val('');
		$('#waterfront').val('');
		$('#development').val('');
		$('#zips').val('');
		$('#selectmls').val('');
		$('#view').val('');
        $('#furnished').val('');
        $('input[name="rdpvtpool"]:first').attr('checked', true);
        $('#amenities').val('');
        $('#selmaxlivarea').val('');
        $('#selminlivarea').val('');
        $('#num_baths').val('');
        $('#num_beds').val('');
        $('#selmaxprice').val('');
        $('#selminprice').val('');
        $('#yearbuilt').val('');
        $('input[name="building_design[]"]').attr('checked', false);
        $('input[name="area[]"]').attr('checked', false);
		return false;
	});
	$('.button a[href^="#search"]').live('click',function() {
		
		A25Core.__submitForm('#property_search', 'confirmSubmit',1);
		return false;
	});
	$('a[href^="#lotsearch"]').live('click',function() {
		
		A25Core.__submitForm('#search_lot', 'confirmSubmit',1);
		return false;
	});
	$('a[href^="#search_layout"]').live('click',function() {
//		alert('aici');
		A25Core.__submitForm('#search_layout', 'confirmSubmit',1);
		return false;
	});
	
	
	/*translate*/
	$('a[href^="#lg2"]').live('click',function() {
		alert('aici');
		return false;
	});
	
	/*language*/
	$('a[href^="#english"]').live('click',function() {
		$('a[href^="#english"]').removeClass('select');
		$('a[href^="#spanish"]').removeClass('select');
		$('a[href^="#french"]').removeClass('select');
		$('a[href^="#german"]').removeClass('select');
		$(this).addClass('select');
		return false;
	});
	
	$('a[href^="#spanish"]').live('click',function() {
		$('a[href^="#english"]').removeClass('select');
		$('a[href^="#spanish"]').removeClass('select');
		$('a[href^="#french"]').removeClass('select');
		$('a[href^="#german"]').removeClass('select');
		$(this).addClass('select');
		
		return false;
	});
	$('a[href^="#french"]').live('click',function() {
		$('a[href^="#english"]').removeClass('select');
		$('a[href^="#spanish"]').removeClass('select');
		$('a[href^="#french"]').removeClass('select');
		$('a[href^="#german"]').removeClass('select');
		$(this).addClass('select');
		return false;
	});
	$('a[href^="#german"]').live('click',function() {
		$('a[href^="#english"]').removeClass('select');
		$('a[href^="#spanish"]').removeClass('select');
		$('a[href^="#french"]').removeClass('select');
		$('a[href^="#german"]').removeClass('select');
		$(this).addClass('select');
		return false;
	});
	/**/
	
	
});


