var eurlex_lang = {
    'LV':'Latviski',
    'EN':'Angliski'
};

jQuery(document).ready(function() {
    jQuery('#feature-content').delegate('a[id^="ext_sakn"]', 'click', function()
    {
	    csak_id = jQuery(this).attr('id').slice(9);
        popitup('popup_links.php?csak_id=' + csak_id);
		return false;
	});
    
    jQuery('#feature-content').delegate('a[id^="ext_sakn"]', 'mouseover', function(event)
    {
        jQuery(this).qtip({
            overwrite: false,
            content: {
                text: '<div style="background: #F5F3F4;"><img src="/images/ajax-loader-small.gif" /> mirkli uzgaidiet!</div>',
                ajax: {
                    url: '/jq_popup_links.php?csak_id=' + jQuery(this).attr('id') + '&qtip=1',
                    type: 'POST',
                    data: {qt_title: jQuery(this).text()},
                    once: true,
                    success: function(data, status) {
                        this.set('content.text', data);
                    }
                }
            },
            position: {
                my: 'bottom center',
                at: 'top center',
                target: 'mouse',
                viewport: jQuery(window),
                adjust: {
                    y: -5,
                    mouse: false
                }
            },
            show: {
                event: event.type,
                ready: true,
                delay: 1000,
                solo: true
            },
            hide: {
                fixed: true,
                event: 'mouseleave',
                delay: 300,
                inactive: 10000,
                leave: true
            },
            style: {
                width: 600,
                classes: 'ui-tooltip-l2d ui-tooltip-rounded'
            }
        }, event);
    }).each(function(i) {
       jQuery.attr(this, 'oldtitle', jQuery.attr(this, 'title'));
       this.removeAttribute('title');
    });
    
    jQuery('a.qtip_more').live('click', function() {
	    csak_id = jQuery(this).attr('id').slice(5);
        popitup('popup_links.php?csak_id=' + csak_id);
		return false;
	});
    
    jQuery('#feature-content').delegate(
        'a[href^="http://eur-lex"]:not(a[id^="ext_sakn"])',
        'mouseover',
        function(event)
    {
        jQuery(this).qtip({
            overwrite: false,
            content: {
                text: function(api) {
                    
                    var hreftext   = jQuery(this).text();
                    var templink   = jQuery(this).attr('href');
                    var langlink   = '';
                    var returntext = '';
                    
                    for (var i in eurlex_lang)
                    {
                        langlink = templink.replace(':LV:', ':' + i + ':');
                        returntext += '<div class="eur-lex"><a href="'
                            + langlink + '" target="_blank">'
                            + hreftext + ' '
                            + eurlex_lang[i] + '</a></div>';
                    }
                    
                    return returntext;
                }
            },
            position: {
                my: 'bottom center',
                at: 'top center',
                target: 'mouse',
                viewport: jQuery(window),
                adjust: {
                    y: -5,
                    mouse: false
                }
            },
            show: {
                event: event.type,
                ready: true,
                delay: 1000,
                solo: true
            },
            hide: {
                fixed: true,
                event: 'mouseleave',
                delay: 300,
                inactive: 10000,
                leave: true
            },
            style: {
                width: 150,
                classes: 'ui-tooltip-l2d ui-tooltip-rounded'
            }
        }, event);
    }).each(function(i) {
       jQuery.attr(this, 'oldtitle', jQuery.attr(this, 'title'));
       this.removeAttribute('title');
    });
    
})
