/**
 * Raveco JavaScript libraries.
 *
 * Copyright (c) 2009 Raveco S.C.
 *
 * This code is not freeware. It may not be used for any purposes (private or commercial) except by Raveco S.C.
 */
 
 raveco = new Object();
 
 /**
  * Creates a new menu drop down menu with given elements.
  * 
  * @param elementId - menu element which will open the drop down menu
  * @param elements - an array of drop down elements, each element is an object with a 'label' and 'link' property
  */
 raveco.menuCreateDropdown = function(elementId, elements) {
 	var parentElement = $('#'+elementId);
 	var offset = parentElement.offset();
 	var height = parentElement.height();

 	var menu = $('<div class="raveco_dropdown_menu menuDropdown" id="rav_dropDownMenu_' + elementId + '"></div>');
 	var elementsCount = elements.length;
 	var i = 0;
 	for(i = 0; i < elementsCount; i++) {
 		var link = elements[i].link;
 		var menuEntry = $('<div class="raveco_dropdown_menu_entry" onclick="raveco.goToLocation(\'' + link + '\');"></div>');
 		menuEntry.append('<a href=\"'+link+'\" class="menuDropdownLink">'+ elements[i].label+'</a>');
 		menu.append(menuEntry);
 	}
 	
 	menu.css('top', offset.top + height + 'px');
	menu.css('left', offset.left + 'px');
	menu.css('width', 'auto')
 	
 	$('body').append(menu);
 	menu.hover(function(){},
 		function() {
 			menu.hide();
 		
 	});
 	
 	menu.hide();
 	
 }
 
 /**
  * Opens the belonging element drop down menu
  */
 raveco.menuShowDropdown = function(elementId) {
 	var menu = $('#rav_dropDownMenu_'+elementId);
 	menu.show();
 }
 
 /**
  * Creates a menu entry with a label and a link.
  */
 raveco.menuCreateMenuEntry = function(label,link) {
 	var entry = new Object();
 	entry.label = label;
 	entry.link = link;
 	
 	return entry;
 }
 
 /**
  * Changes current browser location.
  */
 raveco.goToLocation = function(link) {
 	window.location.assign(link);
}

/**
 * Changes spotlight content to the selected one.
 */
 raveco.setSpotlightContent = function(id) {
    $('.spotlightTitle').removeClass('spotlightTitleActive');
    $('.spotlightTitle').addClass('spotlightTitleInactive');

    var text = $('#' + id + '_content').text();
    $('#'+id).addClass('spotlightTitleActive');
    $('#spotlightText').text(text);
}

/**
* Initializes dynamic elements on the page.
*/
raveco.init = function() {
    $('div.rIcon').hover(function() {
        $(this).removeClass("ui-state-default");
        $(this).addClass("ui-state-hover");
    },
    function() {
        $(this).removeClass("ui-state-hover");
        $(this).addClass("ui-state-default");
    });

    $('div.spotlightTitle').click(function() {
        var id = $(this).attr('id');
        raveco.setSpotlightContent(id);
    });
    raveco.setSpotlightContent('cel');
}

$().ready(function() {
    raveco.init();
});
