$(function()
{
        $("#top-images .photo-tour").mouseenter(function() {
                        $(this).animate({"height": "100px"}, 1000);
                }).mouseleave(
                function() {
                        $(this).animate({ "height": "27px"}, 1000);
                }
        );

        $("#top-images .photo-tour ul li a, a[name='omni_gallery_nav'], a[name='btn_photo-tour'], a[name='omni_gallery_footer'], a.subnav-a2, a.photo-tour-sub, a.image-button.play-video").click(function(evt){
		return lightbox( evt, $(this) );
	});
	function lightbox(evt, link) {
                var slideshowURL = "/dev/layout/set/slideshow_images/photo-tour/hotel";
				if( $(link).hasClass('subnav-a2')||$(link).hasClass('photo-tour-sub') ){
					//slideshowURL = $(this).attr("href");
					slideshowURL = $(link).attr("href");
				}
                
                evt.preventDefault();
                $("#top-images .slides").cycle("stop");
                $("#modal-layer").fadeIn(function(){
                        //ie 6 specific. To hide the form elements of the quick-res
                        if ($.browser.msie == true && $.browser.version.substring(0,1) == "6") {
                                var iFrame = document.createElement("iframe");
                                $(iFrame).attr({
                                        "name": "i_hate_ie_6",
                                        "id": "i_hate_ie_6"
                                }).css({
                                        "width":$("#quick-res").width()+"px",
                                        "height": $("#quick-res").height()+"px",
                                        "position": "absolute",
                                        "zIndex": "998"
                                }).appendTo("body");
                                var iFramePos = $("#quick-res").offset();
                                $("#i_hate_ie_6").css({
                                        top: iFramePos.top+"px",
                                        left: iFramePos.left+"px"
                                })
                        }
                        $("#slideshow-modal").show();
                        loadSlideshow(slideshowURL);
			if ( $(link).attr('class').indexOf('play-video') != -1 )
				$('.btn2 a').trigger('click');

                        $("a.btn_close").click(function(){
                                $("#slideshow-modal").hide();
                                $("#modal-layer").fadeOut();
                                $("#i_hate_ie_6").remove();
                                $("#interactive-map, #video").hide();
                                $("#slideshow").show();
                                $('#toolbar').show();
                                return false;
                        });
                        
			$("a.photo-tour-logo").click(function(){
                                $("#slideshow-modal").hide();
                                $("#modal-layer").fadeOut();
                                $("#i_hate_ie_6").remove();
                                $("#interactive-map, #video").hide();
                                $("#slideshow").show();
                                $('#toolbar').show();
                                return false;
                        });

			$("div.modal-layer").click(function(){
                                $("#slideshow-modal").hide();
                                $("#modal-layer").fadeOut();
                                $("#i_hate_ie_6").remove();
                                $("#interactive-map, #video").hide();
                                $("#slideshow").show();
                                $('#toolbar').show();
                                return false;
                        });
                });
                return false;
	}

        $("a.btn_pause").click(function()
        {
                $("#slideshow").cycle("pause");
                $(this).hide();
                $("a.btn_play").show();
                return false;
        });
        $("a.btn_play").click(function(){
                $("#slideshow").cycle("resume");
                $(this).hide();
                $("a.btn_pause").show();
                return false;
        });
        $("ul.nav-tabs li").mouseenter(function()
        {
                $(this).addClass("active");
                $("ul", $(this)).slideDown(300);
        });
        $("ul.nav-tabs li").mouseleave(function()
        {
                $(this).removeClass("active");
                $("ul", $(this)).slideUp(300);
        });
        
        $("ul.galleries a").click(function()
        {
                $("ul", $("ul.nav-tabs li.active")).slideUp(300);
                $("ul.nav-tabs li.active").removeClass("active");
                loadSlideshow($(this).attr("href"));
                return false;
        });
});

function changeCaption()
{
        $("p.progress span").html(($("#slideshow img").index(this)+1));
        $("p.caption").text(this.alt);
}

function loadSlideshow(url)
{		
        $("#slideshow").html("<p style='text-align:center;height:400px;line-height:400px;color:#000;'>LOADING IMAGES...</p>");
        $("#slideshow").css({"background-color":"white"});
        $("#slideshow").load(url, function()
        {
                $ss = $("#slideshow");
                $ss.cycle(
                {
                        fx: "fade",
                        timeout: 6000,
                        speed: 500,
                        next: $("a.btn_next"),
                        prev: $("a.btn_prev"),
                        after: changeCaption
                });
                $("p.caption").text($("#slideshow img:eq(0)").attr("alt"));
                $("p.progress").html("Image <span>1</span> of "+$("#slideshow img").length);
        });
}


