$(document).ready(function(){
	onetRandomArray = new Array();
	onetRandomCount = 0;
	//while( $(".tx-onetrandomcontent-pi1").text() == "" ){}
	$(".tx-onetrandomcontent-pi1").showRandom();	
	window.setInterval("showNext()", 30000);
});

function closeLayer() {
	$("#flashlayer").remove();
}

function showNext() {
	for(i = 0; i < onetRandomArray.length; i++) {
		onetRandomArray[i]['cObj'] = $(onetRandomArray[i]['container']).children(".element:visible");
		$(onetRandomArray[i]['cObj']).hide();
		if (onetRandomArray[i]['countInt'] < onetRandomArray[i]['countElem']) {
			onetRandomArray[i]['cObj'] = $(onetRandomArray[i]['cObj']).nextAll(".element")[0];
			$(onetRandomArray[i]['cObj']).show();
			onetRandomArray[i]['countInt']++;
		} else {
			onetRandomArray[i]['countInt'] = 1;
			onetRandomArray[i]['cObj'] = $(onetRandomArray[i]['container']).children(".element:first");
			$(onetRandomArray[i]['cObj']).show();
		}
	}
}

(function($) {
    $.fn.showRandom = function(options) {
        var opts = $.extend({}, $.fn.showRandom.defaults, options);        
        //alert($(this).attr('class'));
        return this.each(function() {
        
            var o = $.meta ? $.extend({}, opts, $(this).data()) : opts;
            
            // für Browser, die die CSS-Anweisung :first-child nicht verstehen
            $(this).children(".element").hide();
			$(this).children(".element:first").show();
			onetRandomArray[onetRandomCount] = new Array();
			onetRandomArray[onetRandomCount]['container'] = this;
			onetRandomArray[onetRandomCount]['countElem'] = $(this).children(".element").length;
			onetRandomArray[onetRandomCount]['countInt'] = 1;
			onetRandomCount++;
        });
    };
    
    $.fn.showRandom.defaults = {
    };
})(jQuery);

/* media search */

function deleteAllOptions() {
	for(i = document.mediaselector.category.options.length-1; i > 0; i--) {
		document.mediaselector.category.remove(i)
	}
}

function addOptionsForBranch(id) {
	for (var i = 0; i < branches[id].length; i++) {
		document.mediaselector.category.options[document.mediaselector.category.length] = branches[id][i];
	}
}

function generateSelectbox(id) {
	deleteAllOptions();
	if (id == 'all') {
		for (var b_id = 1; b_id < branches.length; b_id++) {
			addOptionsForBranch(b_id);
		}
	} 
	else {
		addOptionsForBranch(id);
	}
	document.mediaselector.category.selectedIndex = 0;
}

/**
 * This function is called out of the slideshow flash
 */
function showDetails(detailId) {
	$.ajax({
		url: "index.php",
		data: "type=98&details=" + detailId,
		success: function(data) {
			$("#gwv_flow_details").html(data);
			window.location.href = 'http://' + window.location.host + window.location.pathname + '#details';
		}
	});
}