function slideSwitch() {
    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');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
};

//var scrolling = false;
//
//function startScrolling(obj, param)
//{
////	alert('da');
//    obj.animate({"left": param}, "fast", function(){
//        if (scrolling)
//        {
//                startScrolling(obj, param);
//        }
//    });
//}



$(function() {
	
	$(".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();
				}
			}
		
		}
	});
	
	
	 
	var slideTimer=null;
	
	function slideStop(){
		
		$('#slideshow').hide();
		$('#imagecontent').show();
		if (slideTimer) clearInterval(slideTimer);
		$('#slideshow img').removeClass('active last-active');
		$('#slideshow img:first').addClass('active').css({opacity: 1.0});
	}
	function slideStart(){
		if ($('.contentslide').hasClass('hover')) return;
		$('#imagecontent').hide();
		$('#slideshow').show();
		slideTimer = setInterval( "slideSwitch()", 6000 );
	}
	$('.allcontent .title a[href^="#tab1"]').live('click',function() {
		$(".content_prop").removeClass("selected");
		$(".content_blog").removeClass("selected");
		$(".content_prop").addClass("selected");
		$('.content_prop').show();
		$('.content_blog').hide();
		return false;
	});
	
	$('.allcontent .title a[href^="#tab2"]').live('click',function() {
		$(".content_prop").removeClass("selected");
		$(".content_blog").removeClass("selected");
		$(".content_blog").addClass("selected");
		$('.content_blog').show();
		$('.content_prop').hide();
		return false;
	});
	
	

	$(".accordion").accordion({
		collapsible: true,
		active:false,
//		active: 1*$('#menu_active').val(), 
		animated: 'easeslide',
		changestart: function(event, ui) { 
			//window.location = $(ui.newHeader).find('a').attr('href');
			return true;
		}
	});
	$('#menu > .limenu a').click(function() {
		var accId = $(this).parents('.accordion').attr('id');
//		console.dir([accId]);
		$('.accordion').each(function(){
//			console.dir([$(this).attr('id')]);
			if ($(this).attr('id')!=accId)
				$(this).accordion('option','active',false);
		})
		//$( "#accordion" ).accordion( "activate" , false );
//		var url= this.href;
		var url = $(this).attr("href").split('#')[1];
//		alert (url);
		var val=$(this).attr("href").split('/')[1];
		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;
	});
	$('.accordion .limenu a').click(function() {
		var accId = $(this).parents('.accordion').attr('id');
//		console.dir([accId]);
		$('.accordion').each(function(){
//			console.dir([$(this).attr('id')]);
			if ($(this).attr('id')!=accId)
				$(this).accordion('option','active',false);
		})
	});
//	$('#accordion .limenu a').click(function() {
//		
//		var url= this.href;
//		var val=$(this).attr("href").split('/')[1];
//		if (val != 'ajax-index') {$('.contentslide,.contentfirst'). addClass('hover');$('.contentsecond').hide(); slideStop();}
//			else { $('.contentslide,.contentfirst').removeClass('hover');$('.contentsecond').show(); slideStart();}
//		$.post(url, {},function(data){
//			$("#content").html(data);
//		},"html");
//	});
	$('.accordion .ulmenu a').click(function() {
//		var url= this.href;
		var url=$(this).attr("href").split('#')[1];
		var val=$(this).attr("href").split('/')[1];
		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;
	});
	
	$('.ajaxLink').live('click',function(event) {
		event.preventDefault();
		var url=$(this).attr("href").split('#')[1];
		$('.contentslide,.contentfirst'). addClass('hover');$('.contentsecond').hide(); slideStop();
		$.post(url, {},function(data){
			$("#content").html(data);
		},"html");
		$("body").scrollTo(0,{ axis:'y' })
		return false;
	});

	$('.searchlink').click (function () {
		var url= this.href;
		
//		var url=$(this).attr("href").split('#')[1];
//		alert (url);
		$('.contentsecond').hide(); 
		slideStop();
		$.post(url, {},function(data){
			$("#content").html(data);
		},"html");
		return false;
	});

//	$('.searchbutton').live('click', function () {
//		var url= this.href;
//		$('.contentsecond').hide(); 
//		slideStop();
//		$.post(url, {},function(data){
//			$("#content").html(data);
//		},"html");
//		return false;
//	});
	
	$('select[name="selstatus"] option').live('click',function(){
		if ($(this).hasClass("show-input")){
			$('#satrtdate').show();
			$('#enddate').show();
//			console.dir($(".datepicker"));
			$( "#datepicker" ).datepicker();
			$( "#datepick" ).datepicker();

		}
		else{
			$('#satrtdate').hide();
			$('#enddate').hide();
		}
	});

	/*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*/
	
	/*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);
	});
	$('.content_prop 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('mousedown', function () {
//		
////		alert ('da');
//        scrolling = true;
//        startScrolling($(".allproperties"), "-=10px");
//    }).mouseup(function(){
//        scrolling = false;
//    });




	
	/*end FP*/
	
	/*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;  
	});
	

//	$('a[rel*=facebox]').facebox({
//		loadingImage : 'images/loading.gif',
//		closeImage   : 'images/closelabel.png'
//	  });
	


	$("#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'
	});


	
	slideStart();
});


