﻿/// <reference path="../jquery/jquery-1.4.1-vsdoc.js" />
/**************************************************/
/* Cinemateket */
/* Produced by: Valtech AB, www.valtech.se */
/* Javascript: default.js */
/****************************************************/

var Cinemateket = {};

Cinemateket.base = function() {
    return {
        init:
            function() {
                $('.facebook').attr('href', ('http://www.facebook.com/sharer.php?u=' + escape(window.location) + '&t=' + escape(window.document.title)));
                $('.facebook').click(Cinemateket.base.shareWithFacebook);
                $('.ePost').click(Cinemateket.base.shareWithEmail);
            },
        shareWithFacebook:
            function() {
                window.open($(this).attr('href'), 'facebook', 'height=370,width=500');
                return false;
            },
        shareWithEmail:
            function() {
                window.open($(this).attr('href'), 'emailpagewnd', 'width=400,height=520');
                return false;
            },
        browserNotIe6:
            function() {
                return (!$.browser.msie || ($.browser.msie && $.browser.version > 6));
            }
    };
} ();
$(document).ready(Cinemateket.base.init);

Cinemateket.calendarRotator = function() {
    var itemsToRotate = 3;
    var totalAjaxReq = 0;
    var currentAjaxReq = 0;
    return {
        init:
            function() {
                $('#calendarRotator li').not('#calendarRotator li ul li').animate({ 'left': '+=' + 20 + 'px' }, 700);
                $('.calendarRotatorWrapper .right').click(Cinemateket.calendarRotator.rightHandle);
                $('.calendarRotatorWrapper .left').click(Cinemateket.calendarRotator.leftHandle);
            },
        setEvenOdd:
            function() {
                $('#calendarRotator .item').removeClass('even odd');
                $('#calendarRotator .item:even').addClass('even');
                $('#calendarRotator .item:odd').addClass('odd');
            },
        rightHandle:
            function(evt) {
                var nextUrl = $(this).attr('href');
                if (currentAjaxReq === totalAjaxReq) {
                    Cinemateket.calendarRotator.doAjax(nextUrl);
                }
                else {
                    Cinemateket.calendarRotator.rotateRight();
                }
                return false;
            },
        doAjax:
            function(nextUrl) {
                $.ajax({
                    url: "/Templates/Cinemateket/XMLWebGetCinemateketProgram.aspx",
                    data: { AfterDateProgramUrl: nextUrl },
                    dataType: "html",
                    success: function(data) {
                        Cinemateket.calendarRotator.onAjaxSuccess(data, nextUrl);
                    },
                    error: function(data) {
                        $('.calendarRotatorWrapper .ajaxLoader').css('display', 'none');
                    },
                    beforeSend: function() {
                        $('.calendarRotatorWrapper .ajaxLoader').css('display', 'block');
                    }
                });
                return false;
            },
        onAjaxSuccess:
            function(data, nextUrl) {
                if ($.trim(data) != '') {
                    $('#calendarRotator').append(data);
                    $('.calendarRotatorWrapper .ajaxLoader').css('display', 'none');
                    totalAjaxReq++;
                    Cinemateket.calendarRotator.setEvenOdd();
                    Cinemateket.calendarRotator.rotateRight();
                    $('.calendarRotatorWrapper .right').attr('href', nextUrl.split('=')[0] + '=' + $('#calendarRotator li').not('#calendarRotator li ul li').last().attr('id'));
                }
                else {
                    var rest = ($('#calendarRotator .item').length % (currentAjaxReq * itemsToRotate));
                    if (rest == 4) {
                        Cinemateket.calendarRotator.rotateRight();
                        totalAjaxReq++;
                    }
                    $('.calendarRotatorWrapper .ajaxLoader').css('display', 'none');
                }
                return false;
            },
        leftHandle:
            function(evt) {
                if (currentAjaxReq === 0) {
                    return true;
                }
                Cinemateket.calendarRotator.rotateLeft();
                return false;
            },
        rotateRight:
            function() {
                var itemWidth = $('#calendarRotator li').width();
                var firstPos = ($('#calendarRotator li:first').css('left')).toString().split('p')[0];
                $('#calendarRotator li').not('#calendarRotator li ul li').css('left', firstPos + 'px');
                $('#calendarRotator li').not('#calendarRotator li ul li').animate({ 'left': ((parseFloat(firstPos) - (itemWidth * itemsToRotate))) + 'px' }, 700);
                currentAjaxReq++;
                return false;
            },
        rotateLeft:
            function() {
                var itemWidth = $('#calendarRotator li').width();
                var firstPos = ($('#calendarRotator li:first').css('left')).toString().split('p')[0];
                $('#calendarRotator li').not('#calendarRotator li ul li').css('left', firstPos + 'px');
                $('#calendarRotator li').not('#calendarRotator li ul li').animate({ 'left': (parseFloat(firstPos) + (itemWidth * itemsToRotate)) + 'px' }, 700);
                currentAjaxReq--;
                return false;
            }
    };
} ();
$(document).ready(Cinemateket.calendarRotator.init);


Cinemateket.colorFade = function() {
    var currColor = 0;

    return {
        init:
            function() {
                if (Cinemateket.base.browserNotIe6) {
                    setInterval(Cinemateket.colorFade.doFade, 15000);
                }
            },
        doFade:
            function() {
                var colors = ['#91b401', '#0091ac', '#4cb0dd', '#f47920', '#de981b', '#3b3092', '#772284', '#a30234', '#ee3897'];
                var $headerSection = $('#headerSection');

                if (currColor < colors.length - 1) {
                    $headerSection.animate({ backgroundColor: colors[currColor] }, 5000);
                    currColor++;
                }
                else {
                    currColor = 0;
                    $headerSection.animate({ backgroundColor: colors[currColor] }, 5000);
                    currColor++;
                }
            }
    };
} ();
$(document).ready(Cinemateket.colorFade.init);

Cinemateket.wholeProgram = function() {
    return {
        init:
            function() {
                Cinemateket.wholeProgram.scrollHandle();

                
            },
        scrollHandle:
            function() {
                if (Cinemateket.base.browserNotIe6) {
                    if ($('.wholeProgram').find('.pageLinkList').hasClass('pageLinkList')) {
                        $(window).scroll(function() {
                            if ($(window).scrollTop() > ($('.wholeProgram').offset().top + 70)) {
                                $('.pageLinkList').addClass('pageLinkListFixed');
                            } else {
                                $('.pageLinkList').removeClass('pageLinkListFixed');
                            }
                        });
                    }
                }
            }
    };
} ();
$(document).ready(Cinemateket.wholeProgram.init);

Cinemateket.currentSeries = function() {
    return {
        init:
            function() {
                $('.seriesList li img, .seriesList li a, .seriesList li p, .seriesList li div, .seriesList li h4')
                    .css('display', 'none');

                $('.showListInfo')
                    .text('Visa lång översikt')
                    .addClass('showListInfoExpand')
                    .css('display', 'block');

                $('.showListInfo').toggle(function() {
                    Cinemateket.currentSeries.miniListItems(this, '.seriesList li');
                },
                    function() {
                        Cinemateket.currentSeries.expandListItems(this, '.seriesList li');
                    });

                $('.seriesList h3').toggle(function() {
                    Cinemateket.currentSeries.expandListItem(this.parentNode);
                },
                function() {
                    Cinemateket.currentSeries.miniListItem(this.parentNode);
                });
            },
        expandListItems:
            function(toggleLink, item) {
                $(item + ' img, ' + item + ' a,' + item + ' p, ' + item + ' div, ' + item + ' h4').css('display', 'none');
                $(toggleLink).text('Visa lång översikt').addClass('showListInfoExpand');
                return false;
            },
        miniListItems:
            function(toggleLink, item) {
                $(item + ' a').css('display', 'inline');
                $(item + ' img, ' + item + ' p, ' + item + ' div, ' + item + ' h4').css('display', 'block');
                $(item + ' .textWrapper').css('display', 'inline-block');
                $(toggleLink).text('Visa kort översikt').removeClass('showListInfoExpand');
                return false;
            },
        miniListItem:
            function(nod) {
                $(nod).find('a, p, img, h4, div').css('display', 'none');
            },
        expandListItem:
            function(nod) {
                $(nod).find('p, img, h4, div').css('display', 'block');
                $(nod).find('a').css('display', 'inline');
                $(nod).find('.textWrapper').css('display', 'inline-block');
            }
    };
} ();
$(document).ready(Cinemateket.currentSeries.init);
