//faq - effects
function toggleAnswer(slug) {
    if (!jQuery('#id-faq-'+slug).hasClass('closed-item-height')) {
        window.dont_open_item = true;
        window.location.hash = '#'+slug;
    }
    jQuery('#id-faq-'+slug).toggleClass('closed-item-height', 500, function() { toggleAnswerButton(slug); });
}

function toggleAnswerButton(slug) {
    if (jQuery('#id-faq-'+slug).hasClass('closed-item-height')) {
        jQuery('#id-faq-link-'+slug).html('<span>'+trans_show_answer+'</span>');
    } else {
        jQuery('#id-faq-link-'+slug).html('<span>'+trans_hide_answer+'</span>');
    }
}

//kurzy - effects
function toggleCourse(slug) {
    if (jQuery('#id-course-'+slug).css('display')!='none') {
        window.dont_open_item = true;
        window.location.hash = '#'+slug;
    }
    jQuery('#id-course-'+slug).toggle(500, function() {toggleCourseButton(slug);});
}

function toggleCourseButton(slug) {
    if (jQuery('#id-course-'+slug).css('display') == 'none') {
        jQuery('#id-course-link-'+slug).html('<span>'+trans_show_detail+'</span>');
    } else {
        jQuery('#id-course-link-'+slug).html('<span>'+trans_hide_detail +'</span>');
    }
}

//vyhledavani
function searchToggle(obj) {
    jQuery(obj).parent().parent().children('.content').find('.hiddenable').toggleClass('hidden', 500);
    toggleSearchButton(obj);
}

function toggleSearchButton(obj) {
    if (!obj._search_shown) {
        jQuery(obj).find('.button-content').html(trans_hide_results+' »');
        obj._search_shown = true;
    } else {
        jQuery(obj).find('.button-content').html(trans_show_results+' »');
        obj._search_shown = false;
    }
}
//


jQuery(document).ready(function() {
    //faq a kurzy
    if (window.location.hash && (!window.dont_open_item)) {
        if (jQuery('.faq')) {
            toggleAnswer(window.location.hash.substring(1));
        }
        if (jQuery('.course')) {
            toggleCourse(window.location.hash.substring(1));
        }
    }

    //hp actions products cycler
    if (jQuery('.slideshowBox')) { //ocisteni od chyby
        jQuery('.slideshowBox').cycle({
            fx: 'fade',
            speed: 1500,
            timeout: 5000,
            next: '#ap-prev',
            prev: '#ap-next',
            cleartypeNoBg: true,
            cleartype: !jQuery.support.opacity
        });
    }

    //datepicker
    if (jQuery(".datepicker")) {
        jQuery(".datepicker").datepicker({
            dateFormat: 'd.m.yy',
            buttonImage: '/media/css/global/news-ico-calendar.gif',
            buttonImageOnly: true,
            showOn: 'both'
        });
    }


    // initialize scrollable
    if (jQuery("div.article-gallery")) { //ocisteni od chyby
        jQuery("div.article-gallery").scrollable({
            clickable: false,
            size: 4
        }).mousewheel().circular();
    }


    //prettyphoto
    if (jQuery("a[rel^='prettyPhoto']")) { //ocisteni od chyby
        jQuery("a[rel^='prettyPhoto']").prettyPhoto({default_width: 720, default_height: 570, theme:'facebook', showTitle: 'false'});
    }

    //tooltip
    if (jQuery("a[rel='tooltip']")) { //ocisteni od chyby
        jQuery("a[rel='tooltip']").tooltip({
            track: true,
            delay: 0,
            showURL: false,
            fixPNG: true,
            opacity: 0.95,
            left: -120,
            fade: 250
        });
    }

    //ask us eform validation
    if (jQuery("#askus")) {
        jQuery("#askus").validate();
    }

    //Club Registration eform validation
    if (jQuery("#clubReg")) {
        jQuery("#clubReg").validate();
    }

    if (jQuery("#objKurz")) {
        jQuery("#objKurz").validate();
    }
    //anti_spam
    as = function (i) {
        this.title = this.title.replace('$','@');
        this.innerHTML = this.title.replace('$','@');
        this.href = 'mailto:'+this.title.replace('$','@');
    }
    jQuery('.mailto').each(as);

});

