
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - ++resource++freitag-website.js - */
// http://www.freitag.de/portal_javascripts/++resource++freitag-website.js?original=1
jq.fn.simple_batching=function(){return this.each(function(){obj=jq(this);obj.find('.batch').hide();obj.find('.batch:first').show();obj.find('#down').click(function(){var container=jq(this).parent().parent();var args=jq(this).attr('class').split('-');var index=args[2];container.find('.batch').hide();container.find('#batch-'+index).show();down_id=(parseInt(args[2])+1)>parseInt(args[1])?'1':(parseInt(args[2])+1);jq(this).attr('class',args[0]+'-'+args[1]+'-'+down_id);up_id=(parseInt(args[2])-1)==0?args[1]:(parseInt(args[2])-1);container.find('#up').attr('class',args[0]+'-'+args[1]+'-'+up_id)});obj.find('#up').click(function(){var container=jq(this).parent().parent();var args=jq(this).attr('class').split('-');var index=args[2];container.find('.batch').hide();container.find('#batch-'+index).show();up_id=(parseInt(args[2])-1)==0?args[1]:(parseInt(args[2])-1);jq(this).attr('class',args[0]+'-'+args[1]+'-'+up_id);down_id=(parseInt(args[2])+1)>parseInt(args[1])?'1':(parseInt(args[2])+1);container.find('#down').attr('class',args[0]+'-'+args[1]+'-'+down_id)})})}
jq.fn.paged_batching=function(){return this.each(function(){obj=jq(this);obj.find('.batch').hide();obj.find('.batch:first').show();obj.find('.navigation a').click(function(){var args=jq(this).attr('class').split('-');var index=args[2];jq(this).siblings().removeClass('current_page');jq(this).attr('class',jq(this).attr('class')+' current_page');jq(this).parent().parent().find('.batch').hide();jq(this).parent().parent().find('#batch-'+index).show()})})}
jq.fn.default_input=function(){return this.each(function(){jq(this).attr('value',jq(this).attr('title'));jq(this).focus(function(){jq(this).attr('value')=''});jq(this).blur(function(){var newValue=jq(this).attr('value');if(newValue==''){jq(this).attr('value')=jq(this).attr('title')}})})}
function delete_foto(){id=jq(this).parent().children('img')[0].id;var args='id='+id;jq.ajax({url:portal_url+'/remove_location_temp_foto',type:'POST',data:args,timeout:5000,success: function(id){jq('#'+id).parent().remove();jq('.form_message').text('Ihr Foto wurde gelöscht.');setTimeout(function(){jq('.form_message').text('')},3000)},error: function(){jq('.form_message').text('Foto konnte nicht gelöscht werden.');setTimeout(function(){jq('.form_message').text('')},3000)}})}
jq(document).ready(function(){jq('input#already_subscriber_yes').click(function(){jq('div#subscriber_fields').show('slow')});jq('input#already_subscriber_no').click(function(){jq('div#subscriber_fields').hide('slow')});jq('#lokales .button').hide();jq('#lokales .show').show();jq('.lokales-change').change( function(){jq(this).siblings('.button')[0].click()});jq('.lokales-change-city').change( function(){var l=jq(this).val().split('-');if(l.length==2){window.location="./lokales/stadt-hilfe?modus=stadt-hilfe"} else{jq(this).siblings('.button')[0].click()}});jq('a.new-location').click(function(event){event.preventDefault();jq('#new-location-button').click()});if(jq('form.kssattr-formname-neue-location').length>0||jq('form.kssattr-formname-neue-stadt').length>0){jq('#lokales .enableFormTabbing').removeClass('enableFormTabbing').removeClass('rowlike')
jq("#form-widgets-categories-category").change( function(){jq('#formfield-form-widgets-categories-subcategory').hide();jq('#form-widgets-categories-subcategory option').remove();var selected=jq('#form-widgets-categories-category').val();jq('#form-widgets-categories-subcategory').ajaxAddOption("@@freitag-website-utility/subcategories?category_link="+selected,{},false, function(){if(jq('#form-widgets-categories-subcategory option').length<1){jq('#formfield-form-widgets-categories-subcategory').hide()} else{jq('#formfield-form-widgets-categories-subcategory').show();var subcategory=jq('#subcategory').val();var wi_sub=jq('#form-widgets-categories-subcategory');if(subcategory!=''){wi_sub.selectOptions(subcategory)} else{wi_sub.selectOptions(wi_sub[0].options[0].value)}}})});var category=jq('#category').val();var reccategory=jq('#recommendation-category').val();if(reccategory!='all'){new_category=reccategory} else if(category!=''){new_category=category} else{new_category='restaurants'}
jq('#form-widgets-categories-category').selectOptions(new_category);jq("#form-widgets-categories-category").change();if(jq('form.kssattr-formname-neue-stadt').length>0){jq('#recommendation-userdata').css({'height':'120px'}).append(jq('#fieldset-0 .row').html());jq('#fieldset-0').remove();jq('#fieldset-default').remove();jq('#fieldset-1 legend').remove();jq('#fieldset-1').prepend('<div class="legend">Eine Location in dieser Stadt empfehlen</div>');jq('fieldset').hide();jq('#fieldset-1').show();jq('#fieldset-1').click(function(){jq('fieldset').show()})}
if(jq('form.kssattr-formname-neue-location').length>0){}
jq('#fieldset-3').append(jq('#recommendation-rating'));jq('.enableUnloadProtection').prepend(jq('#recommendation-userdata'));jq('.enableUnloadProtection').prepend(jq('#location-info input'));jq('#formfield-form-widgets-address-zip').append(jq('#cityname'));jq('.formFields').before(jq('#location_fotos'));jq('.enableUnloadProtection fieldset').addClass('closed').prepend('<div class="location_recommend_twister closed"><img /></div>').children('.row').hide();jq(".location_recommend_twister img").attr('src','twister-closed.gif');jq("div.location_recommend_twister").click(function(){var twisters=jq('div.location_recommend_twister');twisters.siblings('.row').hide();twisters.children('img').attr('src','twister-closed.gif');twisters.parent().addClass('closed').removeClass('open');jq(this).siblings('.row').show();jq(this).children('img').attr('src','twister-open.gif');jq(this).parent().addClass('open').removeClass('closed')});jq('.enableUnloadProtection legend').each(function(i){jq(this).parent().prepend('<div class="legend">'+jq(this).text()+'</div>');jq(this).remove()});jq('label').filter(function(index){return jq(this).siblings('.fieldRequired').length>0}).addClass('required');var options={target:'#upload_target',success: function(msg){if(msg.search(/&lt.+/)) { // image tag ohne error(<pre>&lt;img...)(TODO:do that serious,girl!)
var button='<div class="foto_delete"><img src="'+portal_url+'/icon_delete.gif"  title="Foto l&ouml;schen"/></div>';var html='<div class="fotocontainer">'+jq('#upload_target pre').text()+button+'</div>';jq('#fotos').append(jq(html));jq('.foto_delete').click(delete_foto);jq('.form_message').text('Foto wurde hochgeladen.');setTimeout(function(){jq('.form_message').text('')},3000)} else{jq('.form_message').html(msg);setTimeout(function(){jq('.form_message').text('')},3000)}
jq('#form_location_fotos .button_submit').removeClass('submitting')},error: function(msg){jq('.form_message').text(msg);setTimeout(function(){jq('.form_message').text('')},3000)}};jq('#lokales #form_location_fotos').ajaxForm(options)}
jq('#bestof-viewlet .content').hide();jq('#bestof-viewlet .content:first').show();jq('.bestof_link').click(function(){jq('#bestof-viewlet .content').hide();jq(this).parents('.section').children('.content').show()});jq('#notify').hide();jq('.location-detail-content #melden').click(function(){jq('#notify').show()});var options={target:'#notification_form_message',success: function(msg){setTimeout(function(){jq('#notification_form_message').text('');jq('#notification_message').val('');jq('#notify').hide()},8000)},error: function(msg){jq('#notification_form_message').val('Fehler beim Versenden der Mail.');setTimeout(function(){jq('#notification_form_message').text('')},8000)}};jq('#form_location_notification').ajaxForm(options)});

/* - ++resource++freitag.theme.javascripts/freitag-theme.js - */
// twingly
// only show blogstream widget if we have blogs for this article
var tw_onComplete = function () {
    if(tw_numberOfPosts > 0) {
        jq("div.tw_link_widget_wrapper").css('display', 'inline');
    } else {
        jq("div.tw_link_widget_wrapper").css('display', 'none');
    }
};


function getPageEventCoords(evt) {
    // thanks to o'reilly!
    var coords = {left:0, top:0};
    if (evt.pageX) {
        coords.left = evt.pageX;
        coords.top = evt.pageY;
    } else if (evt.clientX) {
        coords.left =
            evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        coords.top =
            evt.clientY + document.body.scrollTop - document.body.clientTop;
        // include html element space, if applicable
        if (document.body.parentElement && document.body.parentElement.clientLeft) {
            var bodParent = document.body.parentElement;
            coords.left += bodParent.scrollLeft - bodParent.clientLeft;
            coords.top += bodParent.scrollTop - bodParent.clientTop;
        }
    }
    return coords;
}

function bind_login() {
    // Login-Box im Kontext von Aktionen anzeigen, die ein Login erfordern
    // Wir nutzen das form handling und laden deshalb das ganze form nach
    jq('.request-login').click(function(event) {
        event.preventDefault();
        jq('#loginform').load(portal_url+'/freitag_login_form', function() {
            jq('#loginbox').removeClass('shrunk').show();
            jq('#__ac_name').focus();
        });
        var coords = getPageEventCoords(event);
        jq('#loginbox').css('top', coords.top+15).css('left',coords.left);
        return false;
    });
}

function switch_favorite(o) {
    if(o=='on') {
        jq("img#favorite_img_off").css('display', 'none');
        jq("img#favorite_img_on").css('display', 'inline');
        jq("input#favorite").attr('value', 'on');
    } else {
        jq("img#favorite_img_on").css('display', 'none');
        jq("img#favorite_img_off").css('display', 'inline');
        jq("input#favorite").attr('value', '');
    }
    return false;
 }


jq(document).ready(function() {
     // jump to form
     /*
     jq(".article-form-action").click( function(event) {
        var elem_id = jq(this).attr('id');
        var elem_parts = elem_id.split("_");
        var c_id = elem_parts[elem_parts.length -1];
        window.location.hash = "#formplaceholder_" + c_id;
     });
     */
     // hide and show co-registration fields
     if(!jq("form#join_form input#coorder").attr('checked')) {
         jq("form#join_form div#co_registration").hide('fast');
     }
     jq("form#join_form input#coorder").click(function() {
        checkbox = jq(this);
        if (checkbox.attr('checked')) {
            jq("form#join_form div#co_registration").show('slow');
        } else {
            jq("form#join_form div#co_registration").hide('slow');
        }
     });

     // show comments, article actions and most commented portlet after the document is loaded
     jq("div#comments").css('display', 'inline');
     jq("div#article_action_box").css('display', 'inline');

     bind_login();

    // Login-Box ausblenden, wenn click ausserhalb
    jq('body').click(function(event){
       var currNode = jq(event.target || event.srcElement);
       if ((currNode.attr('id') != 'loginform' && currNode.parents('#loginform').length==0 && !currNode.hasClass('request-login') && currNode.parents('.request-login').length==0)) {
           jq('#loginbox').hide().addClass('shrunk');
           jq('#loginform').text('');
       }
    });

    /* Ressort Navigation */
    jq('#ressort-ressort-menu > li').hover( function() {
        var umenu_id = 'ressort-umenu-' + this.id.split('-')[2];
        jq('.ressort-umenu').hide();
        if (jq('#'+umenu_id).length>0) {
            jq('#'+umenu_id).fadeIn();
            jq('#ressort-umenu').removeClass('border-top').addClass('border-bottom');
        } else {
            jq('#ressort-umenu').removeClass('border-bottom').addClass('border-top');
        }
    },
    function() {
    });


    /* clock */
    var options = {
      /*fontFamily: 'Georgia, "Times New Roman", serif',
      fontSize: '11px'*/
    };
    jq('.jclock').jclock(options);


    /* topbox flash */
    /*jq('#topbox-flash').removeClass('flash_main_off').addClass('flash_main');
    jq('#topbox-flash-placeholder').hide();
    //        .html("");
    jq('#topbox-flash').flash({
        src: 'preloader.swf',
        width: 561,
        height: 348,
        wmode : "transparent",
        version : 7,
        'z-index': 10,
        flashvars: { preloadTarget: 'teaser1.swf', preloadDocumentClassName: 'Teaser1', preloadInitParams: '0' }
        },
        { expressInstall: true }
        );
*/
    /*jq('#topbox-flash').flash({
        src: 'teaser1.swf',
        width: 561,
        height: 348,
        wmode : "transparent",
        version : 7,
        'z-index': 10,
        flashvars: { config: 'asldkfjasldfkj.xml' }
        },
        { expressInstall: true }
        );*/

    /* lokales googlemaps flash */
 /*   jq('#lokalesbox-flash-placeholder').hide();
    jq('#lokales-flash').flash({
        src: 'preloader.swf',
        width: 875,
        height: 300,
        wmode : "transparent",
        version : 7,
        'z-index': 10,
        //flashvars: { preloadTarget: 'FlashMaps.swf', preloadDocumentClassName: 'FlashMaps', preloadInitParams: '0', requestPath: 'googlemaps.xml', requestParams: escape('?getLocations(view=city&city=berlin&categorie=hotel)') }
        flashvars: { preloadTarget: 'FlashMaps.swf', preloadDocumentClassName: 'FlashMaps', preloadInitParams: '0', requestPath: 'http://freitag.local:8051/freitag/googlemaps.xml', requestParams: escape('?getLocations(view=city&city=berlin&categorie=hotel)') }
        //flashvars: { preloadTarget: 'FlashMaps.swf', preloadDocumentClassName: 'FlashMaps', preloadInitParams: '0' }
        },
        { expressInstall: true }
        );
*/
    // wenn flash nicht installiert ist, dann injiziert jquery.flash ein element mit class ".flash-update"
    // dieses ersetzen wir durch den Platzhalter (Bild)
    // dies ist unsere flash detection
    // TODO version von flash checken
/*    if (jq('.flash-update').length>0) {
        //restore image for non flash users
        jq('#topbox-flash').hide();
        jq('#topbox-flash-placeholder').show();
    };
*/
    // Artikelinfobox in den Content verschieben (vor den fuenftletzten Absatz)
    // removed because of the possiblility that the infobox moves into the ad
    // we have to check the paragraph if it is the ad and if so, move the infobox elsewhere
    /*var thirdlastparagraph = jq(".artikel_content p").length - 6;
    if (thirdlastparagraph > 0) {
        try {
            jq(".artikel_content p:eq("+thirdlastparagraph+")").before(jQuery("#freitag-article-info"));
            jQuery("#freitag-article-info").css('width', '274px');
            jQuery("#freitag-article-info").css('margin', '8px 20px 5px 0');
            jQuery("#freitag-article-info").css('float', 'left');
        } catch(e) {}
    }*/

    // move links to the topic behind the last image
    /*
    if (jq(".artikel_content p").length > 2) {
        images = jq("div.image");
        links_to_topic = jQuery("#links_to_topic");
        if(images.length > 0) {
            jq(images[images.length-1]).after(links_to_topic);
        } else {
            jq(".artikel_content p:eq(1)").before(links_to_topic);
	}
        links_to_topic.css('width', '274px');
        links_to_topic.css('margin', '8px 20px 5px 0');
        links_to_topic.css('float', 'left');
    }
    */
    /* Vorschau */
    jq('#link-morgen').click( function () {
        jq('#vorschau-morgen').show();
        jq('#vorschau-uebermorgen').hide();
    });
    jq('#link-uebermorgen').click( function () {
        jq('#vorschau-uebermorgen').show();
        jq('#vorschau-morgen').hide();
    });

    /* Tooltip */
    /* the tooltip reacts with twingly and leads to a slow script warning
     * in safari 4.x */
    /*jq('a.people').tooltip({
        extraClass: "leser-tooltip",
        track: true,
        delay: 0,
        showURL: false,
        opacity: 0.85
    });

    jq('a:not(.people), img, area, label, input').tooltip({
        extraClass: "freitag-tooltip",
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        opacity: 0.85
    });*/

    // jq('a, img, area, label, input').tooltip();

    // no tooltip
    jq("div#portal-header a, #portal-siteactions a").removeAttr("title");

    /* formatting */
    jq('#relatedItemBox a').prepend('>>');

    jq('#main_text img[title]').each(function() {
        //jq(this).after(' <span class="img-caption>'+jq(this).attr('title')+'</span>').wrap(' <div style="border:solid 2px red"></div>');
        title_text = jq(this).attr('alt');
        if(title_text == '') { title_text = jq(this).attr('title'); }
        jq(this).wrap(' <div class="artikel_content_image captioned-img"></div>').parent().append(' <br />' + title_text);
    });

    // Startseite Bildergalerie
    jq('div.teaser-gallery').simple_batching();

    // Advertising
    jq("div[id^='viewlet-ad-']").each(function() {
        viewlet = jq(this);
        inner_childs = viewlet.children().children();
        // if the viewlet was not filled by hi-media: remove it
        if(inner_childs.length < 3) {
            viewlet.remove();
        }
    });

});


