/**
 *  This is the SiteController. It is mainly used to register other controllers and execute
 *  the other controller's behaviors.
 *  http://www.thinkingphp.org/2006/11/23/how-to-organize-your-cakephp-app’s-javascript-ii/
 */
SiteController = {
	controllers: [],

	initialize: function() {
		this.registerController(this);
		this.applyBehaviors();
		this.applyAjaxBehaviors();
	},
	
	applyBehaviors: function() {
		$(this.controllers).each(function() {
			for (var fct in this.Behaviors) {
				if (typeof(this.Behaviors[fct]) == 'function' && !(Function[fct])) {
					this.Behaviors[fct]();
				}
			}
		});
	},
	
	// These behaviours will only be executed after an ajax-request
	applyAjaxBehaviors: function() {
		$(this.controllers).each(function() {
			for (var fct in this.AjaxBehaviors) {
				if (typeof(this.AjaxBehaviors[fct]) == 'function' && !(Function[fct])) {
					this.AjaxBehaviors[fct]();
				}
			}
		});
	},
	
	Behaviors: {
		externalLinks: function() {
			$('a[@rel=external]').click(function() {
				window.open(this.href);
				return false;
			});
		},
		highlite: function() {
			highliteContent();
		},
		iflow: function() {
			$(".caption").show();
			$("#myController").jFlow({
				slides: "#mySlides",
				height: "200px",
				duration: 400
			});
			$("#btn-home").click(function(){
				$(this).effect("shake", { times: 1, distance: 5 }, 100);
				$("#content-2,#content-3,#content-4,#default-content-right").hide();
				$("#content-1").fadeIn(1000);
				highliteContent();
			});
			$("#btn-kamera").click(function(){
				$(this).effect("shake", { times: 1, distance: 5 }, 100);
				$("#content-1,#content-3,#content-4,#default-content-right").hide();
				$("#content-2").fadeIn(1000);
				highliteContent();
			});
			$("#btn-lock").click(function(){
				$(this).effect("shake", { times: 1, distance: 5 }, 100);
				$("#content-1,#content-2,#content-4,#default-content-right").hide();
				$("#content-3").fadeIn(1000);
				highliteContent();
			});
			$("#btn-tools").click(function(){
				$(this).effect("shake", { times: 1, distance: 5 }, 100);
				$("#content-1,#content-3,#content-2,#default-content-right").hide();
				$("#content-4").fadeIn(1000);
				highliteContent();
			});
		}
	},
	
	registerController: function(controller) {
		this.controllers.push(controller);
	}
};

var highliteContent = function() {
	$('#right')
	.css('background-color', '#ffffff')
	.animateColor
	(
		1300
		,{
			backgroundColor: ['#fff', '#274383']
		}
	);
};

$(document).ready(function() { SiteController.initialize(); } );

  $(document).ready(function(){
  	$("#btn-home").effect("bounce", { times: 5, distance: 10 }, 150);
  });

