/**
 * This javascript will control several view actions (like sliding containers)
 *
 * @module control
 */
var fbPanelController = fbPanelController || {};
fbPanelController.facebookOpen = false;

7/** 
 * This function will slide open / close) the facebook container
 * When closing the container it will make sure the slidebutton remains
 * visible
 *
 * @method slideFacebookContainer
 * @param {String} The id of the container that should slide
 * @param {String} The id of the slidebutton that must stay visible
 * @return void
 */
fbPanelController.slideFacebookContainer = function (containerID, slidebuttonID, slideButtonImageID) {
    "use strict";
    var container = $('#' + containerID),
		slidebutton = $('#' + slidebuttonID),
		slideButtonImage = $('#' + slideButtonImageID),
		openXPos = 8,
		sliderBackground="FacebookSlider_Left.png";
	
	container.animate(
	{
		right: (parseInt(container.css('right'), 10) == openXPos
			? -(parseInt(container.css('width'), 10) - slidebutton.outerWidth())
			: openXPos)
	}, 1000);
	
	fbPanelController.facebookOpen = !(parseInt(container.css('right'), 10) == openXPos);
	
	if (fbPanelController.facebookOpen) {
		sliderBackground="FacebookSlider_Right.png"
	}
	
	slideButtonImage.css('background', 'url(assets/images/' + sliderBackground + ') no-repeat');
}

fbPanelController.resizeHandler = function (event) {
    "use strict";	
	// Close the facebook container when the width <= 1250px
	// Open the facebook container when the width > 1250px
	// Use the animation for both
	if (fbPanelController.facebookOpen && $(window).width() <= 1250) {
		fbPanelController.slideFacebookContainer('sliderContainer', 'slideButton', 'slideButtonImage');
		fbPanelController.facebookOpen = false;
	} else if (!fbPanelController.facebookOpen && $(window).width() > 1250) {
		fbPanelController.slideFacebookContainer('sliderContainer', 'slideButton', 'slideButtonImage');
		fbPanelController.facebookOpen = true;
	}
}
