jQuery(document).ready(function($) {

    jQuery.fn.outerHTML = function(s) {
        return (s)
        ? this.before(s).remove()
        : jQuery("<p>").append(this.eq(0).clone()).html();
    };

    jQuery.fn.exists = function() {
        return jQuery(this).length>0;
    };

    jQuery('.top_prev_img').css("opacity", 0.5);
    jQuery("li.navitem1stlevel").hover(
        function() {
            jQuery(this).addClass('hover');
            jQuery("#"+this.id+"_prev").stop().animate({
                left:'0px'
            },{
                queue:true,
                duration:300
            },'linear');
            jQuery("#"+this.id+"_prev .top_prev_img").stop().animate({
                opacity: 1
            },{
                queue:true,
                duration:1000
            },'linear');
        },
        function() {
            jQuery(this).removeClass('hover');
            jQuery("#"+this.id+"_prev .top_prev_img").stop().animate({
                opacity: 0
            },{
                queue:true,
                duration:200
            },'linear');
            jQuery("#"+this.id+"_prev").stop().animate({
                left:'-3000px'
            },{
                queue:true,
                duration:1000
            },'linear');
        });

    jQuery('#top_banner').click(
        function() {
            self.location.href = 'http://www.photoadventure.at';
        });

    jQuery(".accordion").accordion({
        clearStyle: true
    });
    jQuery(".facebook-livestream-bigger-button span").click(function() {
        jQuery(".facebook-livestream-big ").toggleClass('hidden');
        jQuery(".facebook-livestream-small").toggleClass('hidden');

    });
    jQuery(".facebook-livestream-close-button span").click(function() {
        jQuery(".facebook-livestream-big").toggleClass('hidden');
        jQuery(".facebook-livestream-small").toggleClass('hidden');

    });

    jQuery('#countdown-to-next-event').countdown({
        until: new Date(2012, 11 - 1, 11),
        //format: 'dHM',
        onTick: watchCountdown
    });

    jQuery(".fancybox-iframe").fancybox({
        'width'				: '85%',
        'height'			: '85%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'type'				: 'iframe'
    });
    
    /*jQuery(".navitem1stlevel").hover(function() {
       jQuery(this).children('.nav2ndlevel').toggleClass('hidden');
    });
     */
    jQuery(".registrationform > div").hover(function() {
        jQuery(this).toggleClass('registrationformhover');
    });

    jQuery("ul.thumb li").hover(function() {

        jQuery(this).css({
            'z-index' : '10'
        }); /*Add a higher z-index value so this image stays on top*/
        jQuery(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
        .animate({
            marginTop: '-110px', /* The next 4 lines will vertically align this image */
            marginLeft: '-50px',
            //top: '50%',
            //left: '50%',
            width: '174px', /* Set new width */
            height: '174px', /* Set new height */
            padding: '2px',
            opacity: '1'
        }, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

    } , function() {
        jQuery(this).css({
            'z-index' : '0'
        }); /* Set z-index back to 0 */
        jQuery(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
        .animate({
            marginTop: '0', /* Set alignment back to default */
            marginLeft: '0',
            top: '0',
            left: '0',
            width: '65px', /* Set width back to default */
            height: '65px', /* Set height back to default */
            padding: '2px',
            opacity: '0.5'
        }, 400);
    });

});
jQuery(window).resize(function() {
    });
function watchCountdown(periods) {
    jQuery('#countdown-to-next-event').text('Nächste P+A in '+periods[3] +' Tagen\n10. & 11. Nov. 2012\nDesign Center Linz');
}
