﻿(function(jQuery) {
	jQuery.fn.customFadeIn = function(speed, callback) {
		jQuery(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	jQuery.fn.customFadeOut = function(speed, callback) {
		jQuery(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

function FadeHouse() {
    jQuery(this).click(function() {
		jQuery("a.more").removeClass("active");
		jQuery(this).addClass("active");
		jQuery('div.more').hide();
        var e = "div." + jQuery(this).attr("title");
		jQuery(e).customFadeIn('slow', function() {});
        return false;
    });
}

function BackgroundImage() {
    jQuery(this).click(function() {
		var largePath = jQuery(this).attr("href");
		var largeAlt = jQuery(this).attr("title");
		jQuery(".LargeImage").attr({ src: largePath, alt: largeAlt });
		jQuery("div.TooltipRight p").html("" + largeAlt + ""); 
        return false;
    });
}

var popupStatus = 0;
function loadPopup(){
	if(popupStatus==0){
		jQuery('#Content').customFadeIn('slow', function() {});
		popupStatus = 1;
	}
}
function disablePopup(){
	if(popupStatus==1){
		jQuery('#Content').customFadeOut('slow', function() {});
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#Content").height();
	var popupWidth = jQuery("#Content").width();
	jQuery("#Content").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2
	});
	jQuery(".TooltipWrap").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+510
	});
}

jQuery(document).ready(function(){
	centerPopup();
	loadPopup();
	
	jQuery('a[rel="external"]').click( function() {
        window.open( jQuery(this).attr('href') );
        return false;
    });
	
	jQuery("div.CloseButton").click(function(){
		disablePopup();
		jQuery('div.TooltipWrap').customFadeIn('slow', function() {});
		jQuery('#ShowTab').customFadeIn('slow', function() {});
		return false;
	});
	
	jQuery("div#ShowTab a").click(function(){
		jQuerydiv.hide( { duration: 'slow'});								   
		centerPopup();
		loadPopup();
		jQuery('.TooltipWrap').customFadeOut('slow', function() {});
		jQuery('#ShowTab').customFadeOut('slow', function() {});
		jQuery('#FlickrTab').customFadeOut('slow', function() {});
		return false;
	});
	
	//Fade House & Grounds Sections
	jQuery("a.more").livequery(FadeHouse);
	
	jQuery('#MainMenu a').livequery('click', function(event) {
        jQuery("a.more").removeClass("active");
		jQuery('ul#SubMenu a.First').addClass("active");
		jQuery('div.more').hide();
		jQuery('div.First').show();
        return false;
    });
	
	jQuery("div#ImageGallery li a").livequery(BackgroundImage);
	
	//Image Gallery Slider	
	var jQuerydiv = jQuery('div#ImageGallery');
    var height = jQuerydiv.height();
    jQuerydiv.hide().css({ height : 0 });

    jQuery('div#GalleryTab a').click(function () {
        if (jQuerydiv.is(':visible')) {
            jQuerydiv.animate({ height: 0 }, { duration: 'slow', complete: function () {
                jQuerydiv.hide();
				centerPopup();
				loadPopup();
				jQuery('.TooltipWrap').customFadeOut('slow', function() {});
				jQuery('#ShowTab').customFadeOut('slow', function() {});
				jQuery('#FlickrTab').customFadeOut('slow', function() {});
            } });
        } else {
            jQuerydiv.show().animate({ height : height }, { duration: 'slow' });
			disablePopup();
			jQuery('div.TooltipWrap').customFadeIn('slow', function() {});
			jQuery('div#ShowTab').customFadeIn('slow', function() {});
			jQuery('div#FlickrTab').customFadeIn('slow', function() {});
			jQuery(function() {
				jQuery("div#Scroller").smoothDivScroll({scrollingSpeed:5, mouseDownSpeedBooster: 3, autoScroll: "", visibleHotSpots: ""});
			});
        }   
        return false;
    });
	
	jQuery("div#ImageGallery li img").fadeTo("fast", 0.6);
	jQuery("div#ImageGallery li img").hover(function(){
		jQuery(this).fadeTo("fast", 1.0);},function(){
		jQuery(this).fadeTo("fast", 0.6);
		return false;
	});

});