$( document ).ready( function() {

    $( "a.inline-video" ).fancybox({
        'width': '800px',
        'height' : '600px',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none'
    });

	// init ticker
      	$( '.box.newsticker div .news:eq(2)' ).addClass( 'last' );
      	$( '.box.newsticker div .news:lt(3)' ).show();
      	$( '.box.newsticker div .news:gt(2)' ).hide();

	function newsticker()
	{
	    // algorithm:
	    // get last element, remove it from the list,
	    // add to first position with hidden style
	    // slideDown the new first element
	    // continue
	    last = $( '.box.newsticker div .news:last' ).hide().remove();
	    $( '.box.newsticker div.newsticker' ).prepend( last );
        $( '.box.newsticker div .news:first' ).slideDown( 'fast' );
      	$( '.box.newsticker div .news:not(:last)' ).removeClass( 'last' );
      	$( '.box.newsticker div .news:eq(2)' ).addClass( 'last' );
      	$( '.box.newsticker div .news:lt(3)' ).show();
      	$( '.box.newsticker div .news:gt(2)' ).hide();

	}
	if ( typeof(wIsInEditor) == "undefined" ) {
		interval = setInterval( newsticker, 8000 );
	}

	$(".einbetten").fancybox({
		'hideOnContentClick': true,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});


    $( "a.newsletterpreview" ).click( function() {
        commonFunctions.openPopup( 780, 480, $(this).attr( "href" ) );
        return false;
    } );

});

var commonFunctions = {

    openPopup :function( width, height, href )
    {
        var height = height - 20;
        var x = 0;
        var y = 0;

        if (width < screen.availWidth || height < screen.availHeight) {

            x = ( screen.availWidth - width - 12 ) / 2;
            y = ( screen.availHeight - height - 104 ) / 2;

            if ( window.opera ) {
                y = 0; // Opera positioniert unter den Symbolleisten
            }

            if ( x < 0 || y < 0 ) {
                x = 0;
                y = 0;
            } else {
                parameter = "width=" + width + ",height=" + height + ",";
            }

        }

        // arguments-literal for open.window
        var args = {
            'left' : x,
            'top' : y,
            'menubar' : 'yes',
            'location' : 'yes',
            'toolbar' : 'no',
            'status' : 'no',
            'resizable' :'yes',
            'scrollbars' : 'yes'
        }

        var windowInstanceArgs = '';
        for ( var key in args ) {
            if( 0 !== windowInstanceArgs.length ) {
                windowInstanceArgs += ',';
            }
            windowInstanceArgs += key + '=' + args[key];
        }

        var windowInstance = window.open( href, "popup", windowInstanceArgs );

        if ( windowInstance ) {
            windowInstance.focus();
        }

        return !windowInstance;
    }

}

