$(document).ready(function() {
    
	$(".realestatetabnav li a,.tabulation li a").click(function(){

		$(".tab-contained").hide();
		$("hr,br").hide();
		var anchor = $(this).attr('href').replace('#','');
		$('.' + anchor).show();
		return false;
//		var block = $('.' + anchor).html();
//		$(".tab-container").prepend(block);	
	});

	
    // search form features
	
	$('.propsearchsubmit').click(function(){
		$('#search_input').submit();
	});   
	$('.handler .tabs-nav-blue a').click(function(){	
		var viewtype = $(this).text().toLowerCase();
		$('#search_input').attr("action","realestate/search/"+viewtype);
		$('#search_input').submit();
	});  
	
/*	$('.searchwrapper ul.itemlist li a').click(function(){	
		var stuff = $(this).attr("href").split('/');
		var type = stuff[stuff.length-3];
		var id = stuff[stuff.length-1];
		if(type == "neighborhood"){
			$.post(
					"realestate/searchResult/", 
					{ neigh: id, formsearch: 1 } 
					);
		}
		if(type == "community"){
			$.post(
					"realestate/searchResult/", 
					{ community: id, formsearch: 1 } 
					);
		}
		if(type == "type"){
			$.load(
					"realestate/searchResult/"
					);
		}
		return false;
	});  
	*/
	
	
 
    /* highlight navigation */
    var loc = window.location;
    $("#navigation li a[href=\""+loc+"\"]").addClass("selected");

    /* highlight submenu */
    $(".itemlist li a[href=\""+loc+"\"]").addClass("selected");   



	// ALTERNATE ROW COLORS FOR TABLE #ALTERNATE_COLORS
	$("tr:even").css("background-color", "#FFF");
  	$("tr:odd").css("background-color", "#FFF");
	$("tr").hover(function(){
	   $(this).css("background","#EEE");
	 },function(){
	   	$("tr:even").css("background-color", "#FFF");
	   	$("tr:odd").css("background-color", "#FFF");
	 });
	

	// contact form submit 
	$("#contactform").submit(function(){
		
		// check the form values
		var name = $('#contactform #name').val();
		var email = $('#contactform #email').val();
		var message = $('#contactform #message').val();
		if(name == ""){ alert('please enter a name'); $('#contactform #name').css('border','1px solid red');return false;}
		if(email == ""){ alert('please enter a valid email'); $('#contactform #email').css('border','1px solid red');return false;}
		if(message == ""){ alert('please enter a message'); $('#contactform #message').css('border','1px solid red');return false;}
		
		$('#contact-wrapper').html('<h1 style="padding-top:100px"><center>Sending your message</center></h1>');
		$('#contact-wrapper').css('background-image','url(/loader.gif)');
		$('#contact-wrapper').css('backgroundPosition','center center');
		$('#contact-wrapper').css('background-repeat','no-repeat');
		// ajax
		var str = $(this).serialize();
		$.post("homesite/sendContactEmail/",str,function(data) {
			$('#contact-wrapper').html('<center><h1 style="padding-top:100px">Your message has been sent !</h1><p><center>We will get back to you very shortly.</center></p></center>');
			$('#contact-wrapper').css('background-image','').pause(5000);
			$('#contact-wrapper').fadeOut();
			parent.location.reload(); 
	 	});
		// load result
		return false;
	});
	 $('#slideshow_container').cycle({
			fx: 'fade',
			speed:  2500 , 
			timeout: 4000, 
			autostop:4,
			before: onBefore1 ,
			after: onAfter1,
			end:onAfter2
	 	});

		function onAfter1(curr,next,opts) {
				var title = $(this).attr('alt');
				$('.goto'+ opts.currSlide).css("background-image","url('sites/coronadocoastalliving.com/css/pt_black_60.png')");
				$('.goto'+ opts.currSlide).append('<div class="slideshow_pager"></div>');
				$('.image_title').fadeIn("slow").html(title);	
	    	}
		function onAfter2(curr,next,opts) {
			$('.image_title').hide();
			$('.slideshow_action').animate({width:'toggle'},320);
	        
		}
		function onBefore1(curr,next,opts){
				$('.slideshow_pager').hide();
				$('.image_title').fadeOut();
				$('.goto'+ opts.currSlide).css("background-image","url('')");
				
				}
				
	 	function pagerFactory(idx, slide) {
			var s = idx > 2 ? ' style="display:none"' : '';
			return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
		}; 
		
		$('.goto0').hover(function() {
			$('#slideshow_container').cycle(0).cycle('pause'); 
		    return false; 
		},function(){$('#slideshow_container').cycle('resume')});
		 
		$('.goto1').hover(function() { 
			$('#slideshow_container').cycle(1).cycle('pause'); 
		    return false; 
		},function(){$('#slideshow_container').cycle('resume')});
		 
		$('.goto2').hover(function() { 
			$('#slideshow_container').cycle(2).cycle('pause'); 
		    return false; 
		},function(){$('#slideshow_container').cycle('resume')}); 
		
		$('.goto3').hover(function() { 
		    $('#slideshow_container').cycle(3).cycle('pause'); 
		    return false; 
		},function(){$('#slideshow_container').cycle('resume')}); 
		

		$('.goto0').click(function() {
			window.location = 'http://www.coronadocoastalliving.com/'; 
		});
		$('.goto1').click(function() {
			window.location= 'http://www.coronadocoastalliving.com/realestate'; 
		});
		$('.goto2').click(function() {
			window.location = 'http://www.coronadocoastalliving.com/page/coronado_living'; 
		});
		$('.goto3').click(function() {
			window.location = 'http://www.coronadocoastalliving.com/page/about_us'; 
		});



		$('.slideshow_goto').hover(function(){
			$(this).css("background-image","http://www.coronadocoastalliving.com/sites/coronadocoastalliving.com/css/pt_black_60.png");
		});    
		
// expandable //
		$('#expandable .itemlist li:not(.title):not([href=\''+loc+'\'])').hide();
		$('.sidebarsubnav').hide();

		$('#expandable .itemlist .title').toggle(function(){
			$(this).nextAll().not('.sidebarsubnav').each(function() {
			      if ($(this).hasClass('title')) {
			        return false; // stop execution
			      } else {
			    	  $(this).slideDown(); 
			      }
			});
			
		},function(){
			$(this).nextAll().each(function() {
			      if ($(this).hasClass('title')) {
			        return false; // stop execution
			      } else {
			    	  $(this).slideUp(); 
			      }
			});
			
		}).css('cursor','pointer');

		// show submenu
		
		$('#expandable .itemlist .submenuitem').toggle(function(){
			var foo = $(this).attr('id');
			var exploded = foo.split('_');
			var idneigh = exploded['1'];
			$(this).html('[-]');
			$('.menuitemcomplex_' + idneigh).slideDown();			
			return false;
		},function(){
			var foo = $(this).attr('id');
			var exploded = foo.split('_');
			var idneigh = exploded['1'];
			$(this).html('[+]');
			$('.menuitemcomplex_' + idneigh).slideUp();			
			return false;
		});
		
		var itemclass = $("#expandable .itemlist li a[href=\""+loc+"\"]").parent('li').attr("class");
		if(typeof itemclass == "undefined") {
			}
		else{
				if (itemclass != ''){
					$('[class=' + itemclass + ']').show();
				}
				if(itemclass.indexOf( "sidebarsubnav" ) !== -1 ){
					$('.menuitem_neigh').show();
					$(this).css('background','#F2F2F2').addClass("selected");
				}
				if(itemclass.indexOf( "menuitem_neigh" ) !== -1 ){
					$("#expandable .itemlist li a[href=\""+loc+"\"]").parent('li').nextAll().each(function() {
						if ($(this).hasClass('menuitem_neigh')) {
					        return false; // stop execution
					      } else {
					    	  $(this).show(); 
					      }
					});
				}				
				
				
			}
	// property detail page : show pictures
		$('.sccl li img').hover(function(){
			$('img.imgfirst').fadeIn().get(0).src = this.src;
		});
		
	// refine search
		$('#search_form_refine select').each().hide();
		
});  
	
