$(document).ready(function() {
    $(".expanded .text").show();
    $(".stats-accordion .title").click(function() {
        $(this).parent(".stats-accordion-box").nextAll(".stats-accordion-box").find(".text").slideUp();
        $(this).parent(".stats-accordion-box").prevAll(".stats-accordion-box").find(".text").slideUp();
        $(this).parent(".stats-accordion-box").nextAll(".stats-accordion-box").removeClass("expanded");
        $(this).parent(".stats-accordion-box").prevAll(".stats-accordion-box").removeClass("expanded");
        $(this).parent(".stats-accordion-box").toggleClass("expanded");
        $(this).next(".text").slideToggle()
		
    })
    $(".obj-nav .o4").hover(function() {
        $(this).parents(".obj-nav").find("ul").animate({
            left: "-285px"
        }, 500)
    }, function() {});
    $(".obj-nav .o2").hover(function() {
        $(this).parents(".obj-nav").find("ul").animate({
            left: "0px"
        }, 500)
    }, function() {});
	
    var colh = $('.current-arrow-line').parent(".col2of2").prev(".col1of2").height();
    var clh  = $('.current-arrow-line').height();
    if (colh>clh) {
        $('.current-arrow').css("height",colh)
    };
	
    // gallery slider
    if ($(".gallery-slider").is(":visible")) {
        $("#gallery-list").addClass("disabled")
    };
    $(".gallery a").click(function() {
        var linkAttr = $(this).attr("href");
        $(".gallery-detailed").addClass("gallery-detailed-invisible");
        $(linkAttr).addClass("gallery-detailed-visible");
        
        var adg = $(linkAttr+' .ad-gallery');
        if (adg.length>0) {
            $(linkAttr+' a.picrel').each(function(){
                el=$(this);
                $(this).attr('href',$(this).attr('rel'))
            });
            $(adg).adGallery({loader_image: '/a/i/loader.gif'});
        };
        $(".gallery-slider").hide();
        $("#gallery-list").removeClass("disabled");
        return false
    });
    $("#gallery-list").click(function() {
        if ($(".gallery-detailed").is(":visible")) {
            $(".gallery-detailed").removeClass("gallery-detailed-visible");
            $(".gallery-slider").fadeIn();
            $("#gallery-list").addClass("disabled")
        };
        return false
    });
	
    $("[name=faces] area, a.a-face").click(function() {
        var areaAttr = $(this).attr("href");
        $(".face-summary").hide();
        $(areaAttr).fadeIn();
        return false
    });
	
    /*if ($('.ad-gallery').length>0) {
        $('.ad-gallery').adGallery();
    };
    */
	
    
	
    jQuery('#exterior-gallery').jcarousel({
        scroll:1
    });
	
    jQuery('#interior-gallery').jcarousel({
        scroll:1
    });

    $('.modal-form').jqm();

    $('#a-form-show').click(function(){
        _gaq.push(['icTracker._trackPageview', '/virtual/goal/guideView']);

        jQuery('.modal-form').jqmShow();

    },function(){});


	
    jQuery('#gallery-carousel').jcarousel({
        scroll:1
    });
});
// object carousel
$(document).ready(function() {
    // object slider
    // var i = 0
    // $("#object-slider li").each(function(i) {
    // 	$(".control ul").append('<li><a href="#">'+i+'</a></li>')
    // 	i++;
    // });
	
	
    });

function object_carousel_initCallback(carousel) {
    // var index = 0
    // $("#object-slider li").each(function(index) {
    // 	$(".control ul").append('<li><a href="#">'+index+'</a></li>')
    // 	index++;
    // });
    var controlLiSum = 0;
    $(".object-slider .control ul li").each(function() {
        controlLiSum += $(this).outerWidth()
    });
    $(".object-slider .control ul").css("width",controlLiSum)
    $('.control li').bind('click', function() {
        carousel.scroll($.jcarousel.intval($(this).text()));
        $(".control li").removeClass("current");
        $(this).addClass("current")
        return false;
    });
};
function highlight(carousel, obejctli,liindex,listate){
    $('.control li:nth-child('+ liindex +')').attr("class","current");
};    
function removehighlight(carousel, obejctli,liindex,listate){
    $('.control li:nth-child('+ liindex +')').removeAttr("class","current");
};
$(document).ready(function() {
    jQuery('#object-slider').jcarousel({
        scroll:1,
        initCallback: object_carousel_initCallback,
        itemVisibleInCallback:  highlight,
        itemVisibleOutCallback: removehighlight
    });
//
});

function factscarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

	var h = jQuery('#facts-carousel').height();
	$("#header .facts table td").css("height",h)
	$("#header .facts .jcarousel-prev,#header .facts .jcarousel-next").css("top",h/2-10)
};

$(document).ready(function() {
	if ($("#facts-carousel").length>0) {
		jQuery('#facts-carousel').jcarousel({
			scroll:1,
			auto:3,
			wrap: 'last',
			initCallback: factscarousel_initCallback
	    });
	};
});

