$(document).ready(function() {	
	
	$('.languageList-inner').slideUp();
		
		$('.languageList-inner li').click(function()
		{
			var TXT = $(this).children('.languagebox-inner').text();
			$(this).parents('ul').parents('.languageSelectionBox-inner').children('.languagebox-inner').html(TXT);
			
			var LanguageIDString =  $(this).attr("id");
			var LanguageIDArray  =  LanguageIDString.split("content_language_");
			var LanguageID	     =  LanguageIDArray[1];
			
			setContentLanguage(LanguageID);
			
		});

	$('.language-block-inner').click(function()
	{
		if($(".languageList-inner").is(':visible')){
		  $(".languageList-inner").hide();
		  $(".language-block-inner").removeClass("active");
		    $(".language-block-inner").addClass("normal");
	}
	else
	{
		$(".languageList-inner").show();  
		$(".language-block-inner").addClass("active"); 
		 $(".language-block-inner").removeClass("normal");
	}
});

});
		
$(document).mouseup(function (e)
{
	var container2 = $(".languageList-inner");

    if (container2.has(e.target).length === 0)
    {
       container2.slideUp('fast');
		$(".language-block-inner").removeClass("active");
		$(".language-block-inner").addClass("normal");
    }
});


function setContentLanguage(LanguageID)
{
	var dataArray 			= new Array();
	dataArray[0] 			= LanguageID;	
	$.ajax({
		  url: GLOBAL_BASE_PATH+"/language/ajaxreset/type/content/",
		  type: "POST",
		  cache: false,
		  async: false,
		  global: false,
		  data: { ajax_request: dataArray },
		  success: function(data) {
			  window.location.reload();
		  }
	});
}
