$(document).ready(function() {
    var lis = $('#lang > li');
    $.each(lis, function() {
        var liclass = $(this).attr('class');
        if ( liclass == 'lang-select' ) {
            $(this).mouseover(function() {
                $(this).attr('class', 'over');
            }).mouseout(function() {
                $(this).attr('class', '');
            });
        }
    });
    
    $("a[id*='language_']").click(function(event) {
        event.preventDefault();
        var click_id  = $(this).attr('id');
        var id_split  = click_id.split('_');
        var lang      = id_split[1] ;
	var clickable = id_split[3];
	if ( clickable != 'disabled' ) {
    	    $("input[name=lang]").val(lang);
    	    $('#language_form').submit();
	}
    });
});

function showModal(e, url, type)
{	
	var e = $(e);   
	if(!type)
		var type = "GET";
	$.ajax({
	  type: type,
	  url: url,
	  data: e.serialize(),
	  cache: false,
	  success: function(data) {
		doModal(e, data);
	  }
	});	
}   

function doModal(e, text)
{  
  // Create the modal backdrop on document load so all modal tooltips can use it
  $('<div id="qtip-blanket">')
	  .css({
		 position: 'absolute',
		 top: 0, // 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: 'black',
		 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
	  
   $(e).qtip(
   {
	  content: {				
		title: {
			text: e.attr("title") || '&nbsp;&nbsp;&nbsp;',
			button: 'close'
		 },
		 text: text
	  },
	  position: {
		 target: $(document.body), // Position it via the document body...
		 corner: 'center' // ...at the center of the viewport
	  },
	  show: {
		 when: false, // Don't specify a show event
		 ready: true, // Show the tooltip when ready
		 solo: true
	  },
	  hide: false,
	  style: {
		 width: { min: 500 },
		 padding: '14px',
		 border: {
			width: 9,
			radius: 9,
			color: '#666666'
		 },
		 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);
		 }
	  }
   });  
}
