﻿$slideshow = {
    context: false,
    tabs: false,
    timeout: 10000,      // time before next slide appears (in ms)  
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)  
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs  
    fx: 'scrollLeft',   // the slide effect to use  

    init: function () {
        // set the context to help speed up selectors/improve performance  
        this.context = $('.box-breakingnews');

        // set tabs to current hard coded navigation items  
        this.tabs = $('ul.slides-nav li', this.context);
        //set first active
        $('ul.slides-nav li:first', this.context).addClass('on');
        // remove hard coded navigation items from DOM  
        // because they aren't hooked up to jQuery cycle  
        this.tabs.remove();

        // prepare slideshow and jQuery cycle tabs  
        this.prepareSlideshow();
    },

    prepareSlideshow: function () {
        // initialise the jquery cycle plugin -  
        // for information on the options set below go to:  
        // http://malsup.com/jquery/cycle/options.html  
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });
    },

    prepareTabs: function (i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs  
        // (attaches necessary jQuery cycle events to tabs)  
        return $slideshow.tabs.eq(i);
    },

    activateTab: function (currentSlide, nextSlide) {
        // get the active tab  
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);

        // if there is an active tab 
        if (activeTab.length) {
            // remove active styling from all other tabs 
            $slideshow.tabs.removeClass('on');

            // add active styling to active button 
            activeTab.parent().addClass('on');
        }
    }
};

$(function () {
    // initialise the slideshow when the DOM is ready  
    $slideshow.init();
});  




// ------------------------------------------
// functions
// ------------------------------------------
function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function CL_printWindow() {
    window.print();
}
// ------------------------------------------
// issuu
// ------------------------------------------
function cu_issuuPopup(parameters, title) {
    cu_generatePopup("issuu-pupup", "/pages/issuuDetail.aspx?" + parameters, 600, 500, title);
    return false;
}
function cu_issuuFancybox(o, event) {
    if (event && event.preventDefault) {
        event.preventDefault();
    } else {
        event.returnValue = false;
    }
    var fbox = $(o).fancybox({
            height: 460,
            type: 'iframe'
        });
        if (event.preventDefault) {
            fbox.trigger('click');
        }
    }

$(document).ready(function () {
    // ------------------------------------------
    // bookmark
    // ------------------------------------------
    $(".footer-zone a.bookmark").jBrowserBookmark({
        language: {
            'de': ['Bitte drücken Sie [key] + ', ' um ein Lesezeichen zu setzen.'],
            'en': ['Press [key] + ', ' to bookmark this page.'],
            'it': ['Premere [key] + ', ' per aggiungere questa pagina ai segnalibri.']
        }
    });

    // ------------------------------------------
    // team accordion
    // ------------------------------------------
    $("#menu-top .level-0 .flyout").css("top", "30px");
    $("#menu-top .menu-top-container > ul").supersubs({
        minWidth: 12,   // minimum width of sub-menus in em units 
        maxWidth: 30,   // maximum width of sub-menus in em units 
        extraWidth: 1
    }).superfish({
        autoArrows: false,
        animation: { opacity: 'show', height: 'show' },
        hoverClass: 'active'
    });

    // ------------------------------------------
    // team accordion
    // ------------------------------------------
    $(".team-accordion").accordion({
        collapsible: true,
        autoHeight: false,
        active: false
    });
    // ------------------------------------------
    // voting popup
    // ------------------------------------------
    var keyCookieVoting = 'brixner-voting';

    //read cookie
    if (readCookie(keyCookieVoting) == null) {
        var voting = $(".popup-votings");

        //set votingbox positon
        var windowWidth = $(window).width();
        var votingPositionLeft = parseInt((windowWidth - voting.width()) / 2);
        voting.css("left", votingPositionLeft);
        //show box
        voting.show();

        //remove voting button
        voting.find('.header-votings .close').click(function () {
            voting.hide();
        });

        //save cookie
        createCookie(keyCookieVoting, '1', 30);
    }
    // ------------------------------------------
    // issu search keybord command (enter)
    // ------------------------------------------
    $("#issuu .search-text").keydown(function (event) {
        if (event.keyCode == '13') {
            event.preventDefault();
            __doPostBack('<%=SearchCommand.UniqueID %>', '');
        }
    });

    // ------------------------------------------
    // ajax get issuu data
    // ------------------------------------------
    $(".ajax-result").ready(function () {


    });

});

function OpenPopupBanner(lang) {
    var title = "Titel";
    var w = 400;
    var h = 400;
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    window.open("/pages/banner.aspx?lang=" + lang, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    self.focus();
}
//function getAjaxIssuu() {
//    ajaxCommand("getissuu", "");
//}
//function getAjaxTopIssue() {
//    ajaxCommand("gettopissue", "");
//}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

//---------------------------------------------------
// print
//---------------------------------------------------
function CL_printWindow() {
    window.print();
}
