﻿jQuery(document).ready(function(){

// Tooltips

	// Tooltip styles
	$.fn.qtip.styles.menu = {
		width: {
			min: 120,
			max: 400
		},
		background: '#444',
		color: '#fff',
		textAlign: 'left',
		padding: 4,
		border: {
			width: 6,
			radius: 6,
			color: '#444'
		},
		tip: {
			corner: true
		},
		name: 'light' // Inherit the rest of the attributes from the preset dark style
	};


	// Menu and Filter tooltips

	var menu_tooltop_options = {
			content: { text: false },
			title: { text: false },
			position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				},
				adjust: { x: 10 }
			},
			hide: 'unfocus',
			show: {
				solo: true,
				when: {	event: 'click' }
			},
			style: 'menu',
			api: {
				onContentUpdate: function() {
					this.updatePosition();
				}
			}
	}

	$('#icon_menu a').each( function() {

		menu_tooltop_options.content.url = $(this).children('span').text();
		$(this).qtip(menu_tooltop_options);

	});

	$('.filter').each( function() {

		menu_tooltop_options.content.url = $(this).children('span').text();
		menu_tooltop_options.position.corner.target = 'bottomMiddle';
		menu_tooltop_options.position.corner.tooltip = 'topRight';
		menu_tooltop_options.position.adjust.x = 0;
		menu_tooltop_options.style.background = '#333';
		menu_tooltop_options.style.border.color = '#333';
		$(this).qtip(menu_tooltop_options);

	});

	/*
// Context menu
	$(".item_list tr").contextMenu({ menu: 'centro_contextm' },
		function(action, el, pos) {
		/*alert(
			'Action: ' + action + '\n\n' +
			'Element ID: ' + $(el).attr('id') + '\n\n' +
			'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
			'X: ' + pos.docX + '  Y: ' + pos.docY+ ' (relative to document)'
		);
	});
	$("th").parent().disableContextMenu();*/

// Sortable lists
	$(".item_list tbody").sortable({
		handle: 'img.handler',
		start: function(event, ui) {
			$('tr.ui-sortable-placeholder').append('<td colspan="10">&nbsp;</td>');
			$('tr.ui-sortable-placeholder td').css({ 'border':'1px solid #DEDEDE', 'border-width':'0 1px 1px 1px' });
		},
		placeholder: 'ui-sortable-placeholder'
	});
	$(".item_list tbody").disableSelection();
	$(".item_list td").each( function(){
		var current_width = $(this).width();
		var current_height = $(this).height();
		$(this).attr("width", current_width);
		$(this).attr("height", current_height);
	});

	/* qTip */

	$('.modalbox').click(function(e){e.preventDefault();}).each(function(){

      $(this).qtip(
      {
      content: {
         title: {
            text: '',
            button: 'Bezárás'
         },
         url: $(this).attr('href')
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { min: 700, max: 700 },
         title: { 'padding-top': 0, 'padding-bottom': 0, 'background': '#fff', 'overflow': 'hidden' },
         button: { 'margin-top': '7px' },
         padding: '0 22px 14px',
         border: {
            width: 9,
            radius: 9,
            color: '#9FA6AC'
         },
         name: 'light'
      },
      api: {
         beforeShow: function()
         {
            // Fade in the modal "blanket" using the defined show speed
            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
         },
         beforeHide: function()
         {
            // Fade out the modal "blanket" using the defined hide speed
            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
         }
      }
      });

    });

   // Create the modal backdrop on document load so all modal tooltips can use it
   $('<div id="qtip-blanket">')
      .css({
         position: 'absolute',
         top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
         left: 0,
         height: $(document).height(), // Span the full document height...
         width: '100%', // ...and full width

         opacity: 0.7, // Make it slightly transparent
         backgroundColor: 'white',
         zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
      })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially


});
