﻿"use strict";
(function () {
    var view,
        $ = jQuery;

    /**
      * View Namespace
      * @namespace
      */
    view = {
        /**
          * Invoked by document.ready event
          */
        init : function () {
            if ($('.list_type_1_wrapper').length) {
                view.makeTwoColList();
            }

            this.backgroundHoverEvent();
        },
        /**
          * Finds all li-elements in class list_type_1 and splits it in to 2 list to show a 2 colum list.
          * First colum holds first half of list and second the last part of elements
          */
        makeTwoColList : function () {
            var items = $('.list_type_1 li');
                index = items.length % 2 == 0 ? Math.floor(items.length/2) - 1 : Math.floor(items.length/2),
                ul = $('<ul class="list_type_1"></ul>'),
                liToMove = $('.list_type_1_wrapper li:gt(' + index + ')');
           	
            liToMove.appendTo(ul);
			$(ul).addClass('right')
            ul.appendTo('.list_type_1_wrapper');
            
        },
        /**
          * Binds mouseover/mouseleave event to change background color.
          * Binds click event to emulate a-element click. Take href attribute from last a-element child in found element from element with class "mouse_over_leave_background".
          */
        backgroundHoverEvent : function () {
            /** Edit selector to add event to more elements **/
            $('.whole').mouseover(function () {
                $(this).css({ backgroundColor : '#FFFFEE' });
            }).mouseleave(function () {
                $(this).css({ backgroundColor : '#fff' });
            }).click(function () {
                document.location.href = $(this).find('a:last').attr('href');
            });
        }
    };

    $(document).ready(function () { 
        view.init();
    });
}());