var flashTracker = new FlashTracker();

Shadowbox.init($.extend(Swatch.Shadowbox.config, {
	handleOversize: "resize",
	modal: true,
	overlayOpacity: 0.75,
	skipSetup: true
})
);

/*** Firebug Fallback ***/
if (!window.console || !console.firebug) {
	var names = ["log", "debug", "info", "warn", "error",
	"assert", "dir", "dirxml", "group",
	"groupEnd", "time", "timeEnd", "count",
	"trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {}
}


$(function() {
	Shadowbox.setup("a#login", {
		height: 380,
		width:  350,
		player: 'iframe',
		gallery: 'swatch',
		options: {modal: true}
	});

	Shadowbox.setup("a#settings", {
		height: 380,
		width:  350,
		player: 'iframe',
		gallery: 'swatch',
		options: {modal: true}
	});

	Swatch.Breadcrumb.init();
	if(Swatch.Flash.hasFlash) {
		Swatch.Flash.initWmodeFix();
	}

	// SEARCH Results - hover status
	$('ul.videos li').hover(function(){
		$(this).find('div.hover').fadeIn(300);
	}, function() {
		$(this).find('div.hover').fadeOut(300);
	});

	//Listener Cat Navigation
	$('ul#navMain').each(function() {
		var $root	= $(this);
		var $childs	= $root.find('li a');
		$childs.each(function(i) {
			$(this).click(function(e) {
				if( $(this).hasClass('hardlink') ) {
					
					return true;
				}
				
				
				if(Swatch.Flash.hasFlash) {
					e.preventDefault();
					var catSlug = $(this).attr('rel');
					window.location.hash = $(this).attr('href');
					$childs.parent().removeClass('active');
					$(this).parent().addClass('active');
					thisMovie("flash").changeViewFromHTML( null, catSlug, catSlug );
					Swatch.Breadcrumb.addCategory( catSlug );
				}
			})
		});
	});

})

var getLoginState = Swatch.User.checkLogIn;
var setBreadCrumb = Swatch.Breadcrumb.addVideo;
var setLoginReady = Swatch.User.setLoginReady;
var flashLoaded = Swatch.Flash.callOnReady

/**
 * Setzt die Cat-navigation vom FLashFilm aus
 * @param i
 */
function setNavigation(i) {
	$('ul#navMain').each(function() {
		$(this).find('li').removeClass('active');
		$(this).find('li:eq(' + i + ')').addClass('active');
	});
}

function thisMovie(movieName) {
	if(Swatch.Flash.hasFlash) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	}
}

// Um aus einem Flash-Film heraus eine Shadowbox zu öffnen wird die Action Script's 'getURL' Funktion benötigt
// getURL("javascript:openShadowbox('movie.swf', 'swf', 'Title')");
function openShadowbox(content, player, width, height, closeCallback){
	Shadowbox.open({
		content:    content,
		player:     player,
		width:		width,
		height:     height,
		onClose:	closeCallback
	});
}

jQuery(document).ready(function() {



});

