/**
 * Author: rheinschafe.de
 *
 */

window.log = function() {
	log.history = log.history || [];
	log.history.push(arguments);
	if(this.console) {
		console.log(Array.prototype.slice.call(arguments))
	}
};

jQuery.noConflict();
jQuery(document).ready(function($) {

	$.tools.tabs.addEffect('superfade', function(i, done) {
		this.getPanes().css({
			'z-index' : 1
		});
		this.getCurrentPane().css({
			'z-index' : 2
		});
		this.getPanes().eq(i).hide().css({
			'z-index' : 5
		}).fadeIn(1000, 'easeInOutExpo', function() {
			done.call()
		});
	});
	//mod-dropswitch
	$('.mod-dropswitch').each(function() {
		var el = $(this), drop = el.find('dd');
		el.hover(function() {
			drop.hide().slideDown(200);
		}, function() {
			drop.slideUp(100);
		});
	})

	$('.mod-flashembed-replace').each(function() {
		var el = $(this), link = el.attr('href');
		var holder = el.parent().html('').height(el.data('height')).width(el.data('width')).attr('id', el.attr('id'))[0];
		var flashDataLink = el.data('flashvar-link');
		flashembed(holder, link, {
			link : flashDataLink
		});
	});
	var dlc_links = $('.dlc_links');
	if(dlc_links.length) {
		var selectbox = $("<select/>", {
			'class' : 'mod-jumpmenu'
		});
		dlc_links.children().each(function() {
			var el = $(this);
			$("<option/>").val(el.attr('href')).text($(this).text()).appendTo(selectbox);
		});
		dlc_links.replaceWith(selectbox);

		$('.mod-jumpmenu').change(function() {
			if($(this).val()) {
				window.location.href = 'http://' + document.domain + '/' + $(this).val();
			}
			return false;
		});
	}

	// fadeables
	$('.mod-keyvisual').each(function() {
		var self = $(this), panes = self.find('.item'), str = '';

		if(panes.size() == 1) {
			return;
		}

		panes.each(function(i) {
			str += '<li><a href="#' + (i + 1) + '">' + (i + 1) + '</a></li>';
		});
		var tabs = $('<ul>', {
			'class' : 'tabs',
			'html' : str
		}).appendTo(self);
		tabs.tabs(panes, {
			rotate : true,
			effect : 'superfade'
		}).slideshow({
			autoplay : true,
			interval : 6000
		});

	});
	// adujst iframes from the download center
	$('.dlc_iframe').each(function() {
		var that = $(this);

		// function to adjust frame heigh
		var adjustFrame = function() {
			//that.parent().prepend(that.contents().find('body').height());
			that.height((that.contents().find('table').height() + 20));
		}
		// initial call
		adjustFrame();

		// set/unset interval
		var intv = setInterval(adjustFrame, 1000);
		setTimeout(function() {
			clearInterval(intv);
		}, 5000);
	});
});

