var myloading = '<center><div class="my_loading">&nbsp;</div></center>';
$.get("./skin/default/my_images/ajax-loader.gif");
$.get("./skin/black/my_images/ajax-loader.gif");

function give_me_position(e,dialog_width,dialog_height){
	var e_position;

	var new_x=$(e).position().left + $(e).width() + 10;
	var new_y=$(e).position().top + 83;

	var page_width = $(document).width();
	var same=true;
	while( (new_x + (dialog_width + 10)) >  page_width && (new_x > 0)) {
		new_x=new_x-100;
		same =false;
	}
	if(!same) new_y=new_y+25;
	e_scrollTop=$(window).scrollTop(); // because position is in viewport ;)
	e_position=[new_x,(new_y - e_scrollTop)];

	return e_position;
}


function load_tooltip(this_element,tooltip,this_width,this_height){
	$("#Tip").dialog('destroy');
	$("#View_Comment").dialog('destroy');

	//Debug... we have to keep this line
	$('.ui-effects-wrapper').remove();


	var this_title=$(this_element).attr('title');
	var dialog_width = this_width;
	var dialog_height = this_height;
	var this_position=give_me_position(this_element,dialog_width,dialog_height);

	var id_report=$(this_element).attr('id_report');
	var id_file=$(this_element).attr('id_file');
	var filename=$(this_element).attr('filename');
	var mini_modules='mini_modules.php?rep=tooltip&nom=' + tooltip + '&id_report=' + id_report + '&id_file=' + id_file + '&filename=' + filename + '';


	$("#Tip").dialog({hide: 'fold', show: 'fold', shadow: false, width: dialog_width, height: dialog_height, resizable:false, overflowx:'auto', overflowy:'auto', position:this_position, title: this_title});
	$("#Tip").html(myloading);
	$.get(mini_modules, function(data){
		$("#Tip").html(data);
	});

}

function loadTab(index){;
	$("#main_tab").tabs('select', index);
}

$(document).ready(function(){



	$("#increase_XP").click(function () {
		loadTab(1);
	});

	$("#main_tab").fadeIn("slow");
	$("#main_tab").tabs({
		fx: {
			//height: 'toggle',
			opacity: 'toggle',
			duration: 'fast'
		}
	});

	var browser_recommanded=$('#browser_recommanded').html();

	if (browser_recommanded == 'false') {
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=index&nom=browser_recommanded';
		var this_title=$('#browser_recommanded').attr('title');

		var dialog_width = 600;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',250], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	}

	$('#parser_release_note').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=release&nom=version_history';
		var this_title=$(this).attr('title');

		var this_height= $(document).height() - 45;

		var dialog_width = 900;
		var dialog_height = this_height;
		//var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',30], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});

	$('#doc').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=doc&nom=index';
		var this_title=$(this).attr('title');

		var this_height= $(document).height() - 45;

		if (this_height < 200) {
			this_height = 200 - 45;
		}

		var dialog_width = 1024;
		var dialog_height = this_height;
		//var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',30], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});

	$('#download').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=download&nom=getsysteminfo';
		var this_title=$(this).attr('title');

		var dialog_width = 600;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',250], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});

	$('#Instruction').click(function(){
		// Instruction
		$("#Tip").dialog('destroy');
		var content=$('#Instruction_content').html();
		var this_title=$('#Instruction_content').attr('title');

		var dialog_width = 600;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',250], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false , title: this_title });
		$("#Tip").html(content);
		$("#Tip").css("padding","10px");
		$("#Tip table td").css("padding","5px");
	});


	$('#password_lost').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=user&nom=lost_pass';
		var this_title=$(this).attr('title');

		var dialog_width = 500;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});

	$('#login').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=login&nom=mini_login';
		var this_title=$(this).attr('title');

		var dialog_width = 350;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});


	$('#create_account_now').click(function(){
		$("#Tip").dialog('destroy');
		var mini_modules='mini_modules.php?rep=user&nom=add_user';
		var this_title=$(this).attr('title');

		var dialog_width = 500;
		var dialog_height = 'auto';

		$("#Tip").html(myloading);
		$("#Tip").dialog({position: ['center',30], shadow :false , modal: true , width: dialog_width , height: dialog_height , resizable:false, overflowx:'auto', overflowy:'auto' , title: this_title });
		$("#Tip").load(mini_modules);
	});


	$('.hover').hover(
	function(){
		$(this).css('text-decoration', 'underline');
		$(this).css('cursor', 'pointer');
	},
	function(){
		$(this).css('text-decoration', '');
		$(this).css('cursor', '');
	}
	);

	$(function() {
		$('.ui-tabs-panel').css("padding-top","0px");
		$('.ui-tabs-panel').css("padding-bottom","0em");
		$('.ui-tabs-panel').css("padding-left","0em");
		$('.ui-tabs-panel').css("padding-right","0em");
		$('.ui-widget').css("font-size","1em");
	});

});