// JavaScript Document// JavaScript Document

// Abington Functions 

							
$(document).ready(function() {


//$('.slideshow').cycle('fade');

//Needed to fix hidden cycle element issue in IE
var mapFrame = '';

function setPhotoBox() {
	
	$('.photobox').cycle({    
	fx:'scrollHorz',
	timeout: 0, 
	speed:600,
	delay:2000,
	next:'#next_btn',
	prev:'#prev_btn',
	after: onAfter
	});
	
	mapFrame = $('#google-map').html();
}


function onAfter(curr,next,opts) {
	var caption = 'Image ' + (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('#counter').html(caption);
		
	if( (opts.currSlide + 1) == opts.slideCount ) {
		$('#google-map').html(mapFrame); 
	}
}


$('.photobox-home').cycle('fade');

//setPhotoBox();

function setThumbs() {

	$(".thumbs").slideToggle(2);

	$(".btn-slide").click(function(){
	  $(".thumbs").slideToggle(300);
	  $(this).toggleClass("active");
	});

	$(".thumbs img").hover(
	  function(){
		$(this).fadeTo("fast", 0.65);
		//$(this).find("div.landing-caption").fadeIn(400);
	  },
	  function(){
		   $(this).fadeTo("fast", 1);
		//$(this).find("div.landing-caption").fadeOut(400);
	  }
	);

}

//setThumbs();

$('#cssdropdown li.headlink').hover(
        function() { $('ul', this).css('display', 'block'); },
        function() { $('ul', this).css('display', 'none'); });
	

$("a.scroll-search").click(function(){ 
		$.scrollTo( $('#search-results'), 600, {offset: {top:600, left:0} });
		return false;
}); 



$('#output').ajaxComplete(function(e, xhr, settings) {
								   
	//setThumbs();							
	setPhotoBox();
	
	$("a.add-apt-btn").click(function(){ 
	
	$.post($(this).attr("href"), {"apt": $(this).attr("id")});	
		//$("#myList").load('../apartments/myApartments/', function() { 
        //alert('loaded');		
		// }); 
		$(this).fadeOut(1300);
		$('.window').fadeIn(2000);

		return false;
}); 
	
	
	//if close button is clicked
$('.window .close').click(function (e) {
	//Cancel the link behavior
	e.preventDefault();
	//$('#reviews').jScrollPaneRemove();
	$('.window, a.add-apt-btn').hide();	
});		

	
$("a#map-btn").click(function(){ 										
		$('#apt-slides').cycle($('#apt-slides').children().size()-1); 
   		 return false; 			
});

	
$("a.scroll-search").click(function(){ 
		$.scrollTo( $('#search-results'), 600, {offset: {top:600, left:0} });
		return false;
	}); 
		return false;
});


//THIS MUST COME BEFORE TABLESORTER 

//var aptURL = 'http://localhost:8888/abington/index.php/apartments/apartment-details/'
var aptURL = 'http://www.abingtonproperties.com/index.php/apartments/apartment-details/'


 $("a.apt-btn").click(function(){ 
							   
	$(this).parent().parent().fadeTo("slow", 0.45);			
	$(this).parent().siblings().css({'background-color' : '#8dbdd8'});
	$(this).parent().css({'background-color' : '#8dbdd8'});
					
     window.location.hash = $(this).attr("href");		
		
	 var urlLoad =	aptURL + $(this).attr("href"); 
	
	// slide up the div to hide the swap 
      // load the second template with AJAX 
     
	  $("#output").load(urlLoad, function() { 
        // once the load is complete, slide back down 
		$('html, body').animate({scrollTop:0}, 'slow');
      }); 
        return false;
 });
    
	
$(window).bind('hashchange', function(){
    
    newHash = window.location.hash.substring(1);    
  	urlLoad = aptURL + newHash;

	if (newHash) {
	 $("#output").load(urlLoad, function() { 									  
        // once the load is complete, slide back down 
		$('html, body').animate({scrollTop:0}, 'slow');
      }); 
     return false;		
 	 	};
		
    });
    
 $(window).trigger('hashchange');	


//MODAL Windows
//select all the a tag with name equal to modal
	

/*
  // extend the default setting to always include the zebra widget. 
    $.tablesorter.defaults.widgets = ['zebra']; 
    // extend the default setting to always sort on the first column 
    $.tablesorter.defaults.sortList = [[0,0]]; 
    // call the tablesorter plugin 
    $("table").tablesorter(); 

*/

//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

	
	$("table").tablesorter({widthFixed: true, widgets: ['zebra'],
													  //sortList: [[0,0]], 																			
		headers: { 
            // assign the secound column (we start counting zero) 
            3: { sorter: false  }, 
            7: { sorter: false } , 
			8: {sorter: false} 
       		 } 
																			
		})
			//.tablesorterPager({container: $("#pager"), positionFixed: false});
						
   		var newHash = "",
        $mainContent = $("#output"),
        $el;
        
});




