﻿function toggleTabBoxes(menuElement, display) {
    var childnodes = menuElement.getElementsByTagName("DIV");

    for (var i = 0; i < childnodes.length; i++) {
        if (display == 1) {
            childnodes[i].className = childnodes[i].className.replace(" displaynone", "");
        }
        else {
            childnodes[i].className = childnodes[i].className + " displaynone";
        }
    }
}

function toggleSelectedImage(menuElement) {
    $('.gallerytableitem').removeClass('gallerytableitemon');
    $(menuElement).parent().addClass('gallerytableitemon');
}

function Redirect(dataType, value) {
    if (value == "") {
        document.location = location.protocol + "//" + location.host + location.pathname + "#cinematek";
    }
    else {
        document.location = location.protocol + "//" + location.host + location.pathname + "?" + dataType + "=" + value + "#cinematek";
    }
}

function ToggleSummary(imageID, textID) {
    jQuery('#' + textID).toggle('fast');
    
    var image = jQuery('#' + imageID);
    if (jQuery(image).attr("src").match("_down") != null) {
        jQuery(image).attr("src", "/layouts/images/arrow_expand_up.gif");
        //console.log('up');
    }
    else {
        jQuery(image).attr("src", "/layouts/images/arrow_expand_down.gif");
        //console.log('down');
    }
}


function ShowAddedToMitProgramBox(e, title, text, date) {    
    $(".cinematek_add_box").toggle().css("z-index", "200").css("position", "absolute");
    var centerDiv = $(".cinematek_add_box");    
    if ((e.pageY == null && e.pageX == null) || (e.pageY == undefined && e.pageX == undefined))
    {
        var winH = $(window).height();
        var winW = $(window).width();
        centerDiv.css('top', winH / 2 - centerDiv.height() / 2);
        centerDiv.css('left', winW / 2 - centerDiv.width() / 2);        
    }
    else
    {
        centerDiv.css('top', e.pageY + 40);
        centerDiv.css('left', e.pageX);
    }
    $(".cinematek_add_title").html(title + " - " + date);    
    $(".cinematek_add_text").html(text);
    $(".cinematek_add_box").fadeTo(600, 1.00).fadeOut(600);
}

(function($) {
    $.fn.showtimetip = function(options) {
        var defaults = {};

        var options = $.extend({}, defaults, options);
        var $this = this;
        var tip = null;
        var activeShowtime = null;

        this.initialize = function() {
            $(this).click(function(e) {                
                var booking = GetBooking($(this).parent().attr('id').substring(3, $(this).parent().attr('id').length));
                //console.log(booking);
                ShowAddedToMitProgramBox(e, booking.title, booking.text, booking.date);
                Cinemateket.AddBookingToSession(booking.id);
                return false;
            });
        };

        return this.initialize();

    };

})(jQuery);

(function($) {
    $.fn.showtimeremovetip = function(options) {
        var defaults = {};

        var options = $.extend({}, defaults, options);
        var $this = this;
        var tip = null;
        var activeShowtime = null;

        this.initialize = function() {
            $(this).click(function(e) {
                var booking = GetBooking($(this).parent().attr('id').substring(3, $(this).parent().attr('id').length));                
                ShowAddedToMitProgramBox(e, booking.title, booking.rem, booking.date);
                Cinemateket.RemoveBookingFromSession(booking.id);
                return false;
            });
        };

        return this.initialize();

    };

})(jQuery);