var currentImage = 0;
$(document).ready(function () {
    if ($('.ad-gallery').length > 0) {
        $('.ad-gallery').css("visibility", "hidden");
    }
    $(".overlay").hide();
    $(".images_popup").hide();
    $(".movie_popup_landingURL1").hide();
    $(".movie_popup_landingURL2").hide();
    $(".movie_popup_landingURL3").hide();
    $(".movie_popup_landingURL4").hide();

    $('.close').click(function () {
        if ($('.ad-gallery').length > 0) {
            $('.ad-gallery').css("visibility", "hidden");
        }
        $('.images_popup').hide();
        $('.overlay').hide();
        $('.movie_popup_landingURL1').hide();
        $('.movie_popup_landingURL2').hide();
        $('.movie_popup_landingURL3').hide();
        $('.movie_popup_landingURL4').hide();
        return false;
    });

    $('.gallery-images img').click(function () {
        currentImage = $(this).index();
        $(".ad-gallery ul.ad-thumb-list li a").removeClass("ad-active");
        $($(".ad-gallery ul.ad-thumb-list li")[currentImage]).find("a").addClass("ad-active");
        $('div.ad-image img').attr("src", $($(".ad-gallery ul.ad-thumb-list li")[currentImage]).find("a").attr("href"));
        $('p.ad-image-description').html("<strong class='ad-description-title'>" + $($(".ad-gallery ul.ad-thumb-list li")[currentImage]).find("img").attr("title") + "</strong><span>" + $($(".ad-gallery ul.ad-thumb-list li")[currentImage]).find("img").attr("alt") + "</span>");
        $('.ad-gallery').center();
        $(".overlay").fadeIn("slow", function () {
            $('.ad-gallery').css("visibility", "visible");
        })
        return false;
    });
    $('.content-rotator-movieicon a').click(function () {
        $('.images_popup').center();
        $(".overlay").fadeIn("slow", function () {
            $('.images_popup').show();
        })
        return false;
    });

    $('.guider .tooltip a').click(function () {
        $('.movie_popup_landingURL1').center();
        $(".overlay").fadeIn("slow", function () {
            $('.movie_popup_landingURL1').show();
        })
        return false;
    });

    $('.column a.arrowleftbox').click(function () {
        $('.movie_popup_landingURL2').center();
        $(".overlay").fadeIn("slow", function () {
            $('.movie_popup_landingURL2').show();
        })
        return false;
    });

    $('.column a.arrowmiddlebox').click(function () {
        $('.movie_popup_landingURL3').center();
        $(".overlay").fadeIn("slow", function () {
            $('.movie_popup_landingURL3').show();
        })
        return false;
    });

    $('.column a.arrowrightbox').click(function () {
        $('.movie_popup_landingURL4').center();
        $(".overlay").fadeIn("slow", function () {
            $('.movie_popup_landingURL4').show();
        })
        return false;
    });



});

jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function showGallery() {
    $('.ad-gallery').center();
    $(".overlay").fadeIn("slow", function () {
        $('.ad-gallery').css("visibility", "visible");
    })
}

function showVideo() {
    $('.images_popup').center();
    $(".overlay").fadeIn("slow", function () {
        $('.images_popup').show();
    })
}
