/**
 * @fileOverview All JS-code for domain.nl
 * @author name
 * @since 1.0 - 2010-8-6
 * @version 1.0 - 2010-8-6
 */




if (typeof (nl) == "undefined") {
	/**
	* @namespace Top Level Domain
	*/
	var nl = {}
}




/**
 * @namespace Domain name and container for simple public functions
 */
nl.fhk = (function() {
    /* Start public */
    return {
        /**
        * Add Flash Spotlight to page
        * @param {String} swfUrl URL of SWF
        * @param {String} flashContainer ID of the DOM element where the SWF will be placed in
        * @requires swfobject
        * @requires jQuery
        * @example
        */
        AddSpotlight: function(swfUrl, flashContainer, libraryId, animationInterval, animationSwitchspeed) {
            var flashvars = {};
            flashvars.xmlConfigURL = "/Estate/XML/GetSpotlightData.aspx?LibraryID=" + libraryId;
            flashvars.animationInterval = animationInterval;
            flashvars.animationSwitchspeed = animationSwitchspeed;

            var params = {};
            params.wmode = "transparent";

            var attributes = {};

            if (swfobject.getFlashPlayerVersion().major >= 9) {
                swfobject.embedSWF(swfUrl + "?random=" + Math.random(), flashContainer, "682", "278", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
            }
        },
        
        /**
        * Shake the website a bit so that webkit won't show div.topContentContainer with a zero pixel height
        * @requires jQuery
        * @example
        * nl.fhk.FixWebkitBug()
        */
        FixWebkitBug: function() {
			if (jQuery.browser.webkit == true) {
				jQuery('div.genericContent > *').hide()
				jQuery('div.genericContent > *').show()
			}
        }
    }
    /* End public */
})();

/**
 * @namespace Boiler plate class
 */
nl.fhk.monthCalendar = (function() {
    var config = {
        containerID: "div.monthCalendar",
        itemCount: 0,
        position: 0,
        closedHeight: 40,
        openedHeight: 264
    }

    function open() {
        var newHeight = config.openedHeight;
        jQuery(config.containerID).height(newHeight);
    }

    function close() {
        var newHeight = config.closedHeight;
        jQuery(config.containerID).height(newHeight);

        MoveItems(0, true);

        setToCurrentMonth();
    }

    function MoveItems(input, setToInput) {
        var box = jQuery(config.containerID).find("div.itemsContainer .items");
        var strTop = box.css("top");
        var iTop = parseInt(strTop.replace("px", ""));

        var newTop = (iTop + input);

        if (setToInput) {
            newTop = input;
        }

        box.css("top", newTop + "px");

        if (input > 0) {
            config.position++;
        } else if (input < 0) {
            config.position--;
        } else {
            config.position = 0;
        }

        setArrows();
    }

    function setItemCount() {
        var iCount = jQuery(config.containerID).find("li").length;
        config.itemCount = iCount;
    }

    function setArrows() {
        var arrowUp = jQuery(config.containerID).find("div.itemsContainer .itemsUp");
        var arrowDown = jQuery(config.containerID).find("div.itemsContainer .itemsDown");

        var itemContainer = jQuery(config.containerID).find("div.itemsContainer .items");

        if (config.position < 0) {
            arrowUp.show();
        }

        if (config.position == 0) {
            arrowUp.hide();
            arrowDown.show();
        }

        if ((config.position - -config.itemCount) == 8) {
            arrowDown.hide();
        }
    }

    function up() {
        MoveItems(26, false);
    }

    function down() {
        MoveItems(-26, false);
    }

    function setToCurrentMonth() {
        var currDate = new Date();
        var iCurrYear = currDate.getFullYear();
        var iFirstYear = parseInt(jQuery(config.containerID).find("div.itemsContainer .items ul li").first().find("span").text());
        var yearDiff = (iCurrYear - iFirstYear);
        var moveToYear = false;

        jQuery(config.containerID).find("div.itemsContainer .items ul li span").each(function(i) {
            if (parseInt(jQuery(this).text()) == iCurrYear) {
                moveToYear = true;
            }
        });

        if ((yearDiff > 0) && (moveToYear == true)) {
            var yearMove = 0 - ((13 * 26) * yearDiff);
            var positionMove = 0 - (13 * yearDiff);

            MoveItems(yearMove, false);
            config.position = positionMove;

            // Start month calculation
            var currMonth = currDate.getMonth() + 1;
            var monthMove = 0 - (26 * (currMonth));
            positionMove = config.position - currMonth;

            MoveItems(monthMove, false);
            config.position = positionMove;
        }
    }

    /* Start public */
    return {
        /**
        * Boiler plate public method
        * @example
        * nl.domain.namespace.PublicMethod()
        */
        Init: function() {
            setItemCount();
            setArrows();
            setToCurrentMonth();

            jQuery(config.containerID).hover(
                function() {
                    open();
                },
                function() {
                    close();
                }
            );
        },

        MoveUp: function() {
            up();
        },

        MoveDown: function() {
            down();
        }
    }
    /* End public */
})();


nl.fhk.PositionMainMenu = (function() {
    /* START PUBLIC */
    return {
        Init: function(selector) {
            var totalWidth = 0;
            var totalButtons = 0;
            var marginLeft = 0;

            jQuery(selector).find(" > div > ul > li").each(function() {
                var currTxt = jQuery(this).find('> a').text();
                var currWidth = currTxt.length;

                if (currWidth > 20) {
                    jQuery(this).width(currWidth * 4);
                }

                totalWidth += jQuery(this).width();
                totalButtons += 1;
            });

            marginLeft = ((900 - totalWidth) / (totalButtons + 1));

            jQuery(selector).find(" > div > ul > li").each(function() {
                jQuery(this).css("margin-left", marginLeft);

                jQuery(this).show();
            });
            
            jQuery(selector).find("li:last-child").addClass('last')
        }
    }
    /* END PUBLIC */
})();



nl.fhk.PositionPager = (function() {
    
    var totalWidth
    var pagerWidth
    
    /* START PUBLIC */
    return {
        Init: function(selector) {
			totalWidth = jQuery(selector).width();
			pagerWidth = jQuery(selector).find("ol.sf_pager").width();
			jQuery(selector).find("ol.sf_pager").css("margin-left", (totalWidth-pagerWidth)/2);
			
			//.css( propertyName, value ) 
        }
    }
    /* END PUBLIC */
})();



/**
 * @namespace Equalizes heights of the rows in the list. That ways the list will behave more like a table.
 */
nl.fhk.profiles = (function() {
	var counter = 0
	var elements = new Array()

	/* START PUBLIC */
	return {
	/**
	 * Equalizes heights of the rows in the list
	 * @example
	 * nl.fhk.profiles.SetHeights()
	 */
	SetHeights: function() {
			jQuery('ul.personsList > li').each(function() {
				counter++

				elements.push(this)

				if (counter == 3) {
					Estate.CSSTools.EqualizeBlockHeight(elements)
					counter = 0
					elements = new Array()
				}
			})
		}
	}
	/* END PUBLIC */
})();




nl.fhk.player = (function() {
    /* START PUBLIC */
    return {
        Init: function(playerID, file, extension) {
            if ((extension == "mp3") || (extension == "m4a") || (extension == "m4v")) {

                eval("var media = {" + extension + ": file};");
                jQuery("#jquery_jplayer_" + playerID).jPlayer({
                    ready: function() {
                        jQuery(this).jPlayer("setMedia", media);
                    },
                    swfPath: "/Estate/Flash",
                    supplied: extension,
                    cssSelectorAncestor: "#jp_interface_" + playerID
                });

            } else {
                jQuery("#jp_interface_" + playerID).parent("div").parent("div").hide();
            }
        }
    }
    /* END PUBLIC */
})();




/**
* @namespace Boiler plate class
*/
nl.fhk.Spotlight = (function() {
    var maxCount = 0;
    var iCount = 0;
    var animationInterval;
    var animationSwitchspeed;

    function setZIndex() {
        var zIndex = (maxCount + 1) * 10;

        jQuery("div.containerSpotLight ul li").each(function(i) {
            jQuery(this).css("z-index", zIndex);
            zIndex = zIndex - 10;
        });
    }

    function animateImage(opacity, animate, listItem) {
        if (opacity == 1) {
            //listItem.show();
        }

        if (animate) {
            listItem.animate({ "opacity": opacity }, animationSwitchspeed);
        } else {
            listItem.css("opacity", opacity);
        }

        if (opacity == 0) {
            //listItem.hide();
        }
    }

    function setImages(index, animate) {
        jQuery("div.containerSpotLight ul li").each(function(i) {
            if (i != index) {

                animateImage(0, animate, jQuery(this));

            } else {

                animateImage(1, animate, jQuery(this));

            }
        });

        index++;
    }

    function startTimer(index) {
        iCount = index;

        jQuery("div.containerSpotLight ul").everyTime(animationInterval, "spotlight", function(i) {
            if (iCount >= maxCount) {
                iCount = 0;
            } else {
                iCount++;
            }

            setImages(iCount, true);
        });
    }

    /* Start public */
    return {
        /**
        * nl.fhk.Spotlight.Init()
        **/
        Init: function(iAnimationSwitchspeed, iAnimationInterval) {
            animationSwitchspeed = iAnimationSwitchspeed;
            animationInterval = iAnimationInterval;

            maxCount = (jQuery("div.containerSpotLight ul li").length - 1);

            setZIndex();

            setImages(0, false);

            startTimer(0);
        }
    }
    /* End public */
})();
