var _currentImage= "";

$(document).ready(function(){
    $("body").removeClass("loading");

    $(".clickable").each(function(){
        MakeItemClickable($(this), true);
    });

    $(".clickablenohide").each(function(){
        MakeItemClickable($(this), false);
    });

    $(".hoverable").each(function(){
	MakeHoverable($(this), "hover");
    });

    $("a.iframeContent").each(function(){
	$(this).fancybox({
		'frameWidth': 630,
		'frameHeight': 550,
		'hideOnContentClick': false
	});
    });

    $(".findOnMap").click(function(e){
	e.preventDefault();
	$(window).scrollTo(0,500);
    });

    $(".bigButton").each(function(){
	$(this).wrap("<div class=\"bigButtonWrap\">","</div>");
	$(this).click(function(e){
		$("#ExtraInfo").toggle("slide");
	});
    });

    $(".clearer").each(function(){
	$(this).append("<div class=\"clear\">.</div>");
    });

    $("#ExtraInfo").hide();

    $("#Bottom #Locations").append("<div id=\"QuickView\"><div id=\"QuickViewInner\"></div></div>");
    $("#Bottom #Locations").find("#QuickView").hide();

    $("#Bottom #Locations .locationTag").bind("mouseenter", function(){
	var QuickView = $("#Bottom #Locations").find("#QuickView");
	var QuickViewInner = QuickView.find("#QuickViewInner");

	QuickViewInner.html($(this).html());
	$("#Bottom #Locations").css("position","relative");
	QuickView.css("left",$(this).position().left+$(this).outerWidth()-30);
	QuickView.css("top",$(this).position().top-QuickView.outerHeight());
	QuickView.fadeTo(0,0.95);
	QuickView.show();
	
	$(this).click(function(){
		window.location = $(this).find("a.more").attr("href");
	});
    });

    $("#Bottom #Locations .locationTag").bind("mouseleave", function(){
	$("#Bottom #Locations").find("#QuickViewInner").html("");
	$("#Bottom #Locations").find("#QuickView").hide();	
    });

    $(".contactUsPullDown").fancybox({
	'frameWidth': 960,
	'frameHeight': 550,
	'hideOnContentClick': false	
    });
    /*
    $(".contactUsPullDown").bind("click", function(){
	if($("#ContactPage").is(":hidden"))
	{
		$("#ContactPage").slideDown("1000");
	}
	else
	{
		$("#ContactPage").slideUp("1000");
	}
    });
    */

    $(".hideContact").click(function(e){
	$("#ContactPage").slideUp("1000");
    });

    $("#HomePageBottom .blogItem").each(function(){
	MakeItemClickable($(this), true);
	MakeHoverable($(this), "hover");
    });

    //default fancybox
    $("#PageGallery .image a").fancybox();

    // Using custom configuration
    if($("#HomeSections ul.pageSummaries").length > 0)
    {

    $("#HomeSections ul.pageSummaries").carouFredSel({
	items : 3,
	prev : "#HomeSections .prev",
	next : "#HomeSections .next",
	scroll : {
		items: 3,
		duration: 1000,
		pauseOnHover: true
	},
	circular: false
    });

    };
    
});

//Gets an internal link and makes the whole item clickable
function MakeItemClickable(item, hideLink)
{
    var link = item.find("a").attr("href");
    item.bind("click", function(){window.location = link;});
    
    if(hideLink)
    {
        item.find("a").hide();
    }
}

//append/removes class on hover
function MakeHoverable(item, mouseOverClass)
{
    item.bind("mouseenter", function(){$(item).addClass(mouseOverClass)});
    item.bind("mouseleave", function(){$(item).removeClass(mouseOverClass)});
}
