$().ready(function(){
	// Init simple accordion
	$('div.accordion').accordion({header: 'h1', autoheight: false });

	// Search for external links and add some content
	$("#container p a[href^='http://']").prepend('<img src="img/icon_externallink.gif" border="0" alt="" class="linkicon" />').attr('title', 'Externer Link');

	// Search for email links and add some content
	$("#container p a[href^='mailto:']").prepend('<img src="img/icon_email.gif" border="0" alt="" class="linkicon" />');

	// Fancybox
	$("a.fancybox_no_zoomicon").fancybox(
		{
			'titleShow': true,
			'titlePosition': 'inside'
		}
	);
	$("a.fancybox").fancybox(
		{
			padding: 15,
			overlayShow: true,
			width: $(window).width() - 90,
			height: $(window).height() - 110,
			titleShow: false,
			callbackOnShow: function () {$('.flash').css('visibility', 'hidden');},
			callbackOnClose: function () {$('.flash').css('visibility', 'visible');}
		}
	);

	// Other stuff
    $('p.error').css('background', 'url(img/btn_close.gif) right 14px no-repeat #EDEEED');
    $('p.error').hide().slideDown('slow').click(function () {
        $(this).fadeOut('slow');
    });
});


/* Stuff for _templates/_plugins/box_finanzwelt.tv.plugin.php */
var index      = 0;
var res_url    = 'http://www.finanzwelt.tv/quantum_cms/_media/';
var mov_url    = 'http://www.finanzwelt.tv/?page=';

function prev() {
    if (index-1 > 0)
        index--;

	$('#tvcover').fadeOut(500, function(){
	    updateCover();
		$('#tvcover').fadeIn(500);
	});

    updateButtons();
}

function next() {
    if (index+1 <= res_cover.length-1)
        index++;

	$('#tvcover').fadeOut(500, function(){
	    updateCover();
		$('#tvcover').fadeIn(500);
	});

    updateButtons();
}

function updateCover() {
    $('#tvdesc').text(res_cover[index-1][1]);
    $('#tvcover img').attr('src', res_url + res_cover[index-1][0]);
    $('#tvcover').attr('href', mov_url + res_cover[index-1][2]);
}

function updateButtons() {
    $('#tvprev').css('visibility', index > 1 ? 'visible' : 'hidden');
    $('#tvnext').css('visibility', index < res_cover.length-1 ? 'visible' : 'hidden');
}


/* Object for storing banners */
function Banners() {
    this.current = 0;
    this.banners = new Array();
    this.id = '';
    this.instancename = '';
    this.next = function () {
        if (this.current > this.banners.length-1)
            this.current = 0;

        if (this.id != '')
            $(this.id).html('<img src="' + this.banners[this.current][0] + '" alt="" border="0" />').attr('href', this.banners[this.current][1]);

        if (this.instancename != '')
            window.setTimeout(this.instancename + ".next()", parseInt(this.banners[this.current][2]) * 1000);

        this.current++;
    }
}

