/*

	Tooltips

*/


// Document ready
$(document).ready(function(){
	//////////////////////////////////////////////////////////////////////////////////////////////
	// Login
	//////////////////////////////////////////////////////////////////////////////////////////////
	if($('.button[alt="logginn"]').length){
		$('.button[alt="logginn"]').qtip({
			content: $(".tooltip_content[alt='login']").html(),
			show: {
				event: "click"
			},
			hide: {
				event: "unfocus"
			},
			style: {
				classes: 'ui-tooltip-login ui-tooltip-shadow',
				tip: "topRight"
			},
			position: {
				at: "bottom center",
				my: "top right",
				target: $('.button[alt="logginn"]')
			},
			prerender: true,
			events: {
				visible: function(event, api) {
					api.elements.tooltip.find('input[name="Username"]').focus();
				}
			}
		});
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	// RSS Feeds
	//////////////////////////////////////////////////////////////////////////////////////////////
	$('#icon_menu > img[alt="RSS"]').qtip({
		content: $(".tooltip_content[alt='rss']").html(),
		show: "click",
		hide: "unfocus",
		style: {
			classes: 'ui-tooltip-rss ui-tooltip-shadow',
			tip: "topRight"
		},
		position: {
			at: "bottom center",
			my: "top right",
			target: $('#icon_menu > img[alt="RSS"]')
		},
		prerender: false
	});
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	// Administration
	//////////////////////////////////////////////////////////////////////////////////////////////
	$('.admin_link').each(function(){
		var what = $(this).attr('alt');
		
		$(this).qtip({
			content: {
				text: 'Laster inn...',
				ajax: {
					url: 'scripts/tooltip.admin.php' + what,
					type: 'GET',
					data: {}
				}
			},
			show: "click",
			hide: "unfocus",
			style: {
				classes: 'ui-tooltip-admin ui-tooltip-shadow',
				tip: "bottomRight"
			},
			position: {
				at: "top center",
				my: "bottom right"
			},
			prerender: true
		});
	});
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	// New content
	//////////////////////////////////////////////////////////////////////////////////////////////
	$('#icon_menu > img[alt="Nytt"]').qtip({
		content: {
			text: 'Laster inn...',
			ajax: {
				url: 'scripts/tooltip.new_content.php',
				type: 'GET',
				data: {}
			}
		},
		show: "click",
		hide: "unfocus",
		style: {
			classes: 'ui-tooltip-new ui-tooltip-shadow',
			tip: "topRight"
		},
		position: {
			at: "bottom center",
			my: "top right",
			target: $('#icon_menu > img[alt="Nytt"]')
		},
		prerender: true,
		events: {
			show: function(event, api){
				
			},
			visible: function(event, api){
				var new_content = api.elements.tooltip.find('.new_content');
				
				new_content.click(function(){
					$(this).hide();
				});
			}
		}
	});
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	// Profile image import
	//////////////////////////////////////////////////////////////////////////////////////////////
	$('.toolbar > div > img').each(function(){
		$(this).qtip({
			content: $(".tooltip_content[alt='" + $(this).attr('alt') + "']").html(),
			show: "click",
			hide: "unfocus",
			style: {
				classes: 'ui-tooltip-toolbar ui-tooltip-shadow',
				tip: "topLeft"
			},
			position: {
				at: "bottom center",
				my: "top left",
				target: "event"
			},
			prerender: false
		});
	});
});
