/**
 * Collection of all Swatch.TV related Libraries
 *
 * @author Michael Feinbier
 * @author Carsten Biebricher
 * @version $Id: swatch.js 337 2011-01-25 16:31:08Z kevin.cruel $
 */
Swatch = {};

/**
 * Shorthand for console.log() - Fallback
 */
Swatch.log = function () {
	if(typeof console != 'undefined') {
		//console.log(arguments);
		console.log.apply(null,arguments);
	}
}

/**
 * User Container
 * @var Object
 */
Swatch.User = {
	loggedIn: false,
	initialState: true,
	//Check the login State
	checkLogIn: function() {
		if(Swatch.User.loggedIn) {
			thisMovie("flash").setLoginState( true );
		} else {
			Shadowbox.open({
				height: 200,
				width:  350,
				player: 'iframe',
				content: $('a#login').attr('href'),
				options: {modal: true}
			});
		}
	},
	/**
	 * Wird aufgerufen, wenn Login aus der Shadowbox erfolgreich war
	 */
	setLoginReady: function() {		
		$("div#navAccount").html(link_to_settings + '<a href="' + url_for_logout + '" title="LOGOUT" >LOGOUT</a>');
		thisMovie("flash").setLoginState( true );
		Swatch.User.loggedIn = true;
		Shadowbox.close();		
		Shadowbox.setup("a#settings", {
			height: 380,
			width:  350,
			player: 'iframe',
			gallery: 'swatch',
			options: {modal: true}
		});		
	}
};

/**
 * Flash Related
 * Configuration
 *
 * @author mf
 * @var Object
 */
Swatch.Flash = {
	onReady: [],
	isOverFlash: false,
	skipIntro: false,
	hasFlash: false,
	isReady: false,
	callOnReady: function () {
		Swatch.Flash.isReady = true;
		//Skip Intro?
		if(Swatch.Flash.skipIntro) {
			thisMovie("flash").introDisabled();
		}

		//Call all pushed onReady actions
		$.each(Swatch.Flash.onReady,function() {
			this.call();
		});
	},
	/**
	 * Feuer ein Event an den Flashfilm, wenn außerhalb des Flash
	 * die Maus "losgelassen" wird
	 */
	initWmodeFix: function () {
		Swatch.Flash.onReady.push(function() {
			$('#flash').live('mouseenter',function() {
				console.log('enter flash');
				Swatch.Flash.isOverFlash = true;
			});
			$('#flash').live('mouseleave',function() {
				console.log('leave flash');
				Swatch.Flash.isOverFlash = false;
			});
		});
		$('body').mousemove(function( e ){
			if(Swatch.Flash.isReady && Swatch.Flash.isOverFlash == false) {
				//console.log('triggering mouseMove ',e.pageX,',', e.pageY);
				thisMovie("flash").mouseUpEventFromHTML();
			}
		});
	}
}

/**
 * The dynamic Breadcrumb
 * @author Michael Feinbier
 */
Swatch.Breadcrumb = {
	breadcrumb: false,
	init: function() {
		Swatch.Breadcrumb.breadcrumb = $('ol#navBreadcrumb');
	},
	addVideo: function(videoID, unused, category) {
		Swatch.Breadcrumb.render({
			video: videoID,
			category: category
		});
	},
	addCategory: function(category) {
		if(category == 'home')
			Swatch.Breadcrumb.render( );
		else
			Swatch.Breadcrumb.render({category: category});
	},
	render: function(parameter) {
		//Parameter in String umwandeln
		var s = '';
		for(var i in parameter) {
			s = s + '/' + i + '/' + parameter[i]
		}
		var base = (frontendBase == '/' ? '' : frontendBase);
		Swatch.Breadcrumb.breadcrumb.load(base + '/content/breadcrumb' +s);
	}
};
/**
 * Shadowbox-Related Functions
 *
 * @author Michael Feinbier
 * @author Carsten Biebricher
 */
Swatch.Shadowbox = {
	config: {},
	resize: function(width, height) {
		Shadowbox.player.width = width;
		Shadowbox.player.height = height;
		Shadowbox.skin.onReady();
	},
	redirectToUrl: function(url) {
		window.location.href = url;
	},
	redirectToHome: function() {
		Swatch.Shadowbox.redirectToUrl(frontendBase);
	}
}

