$(document).ready(function(){
	//
	var xhr; 
	var requested = 0;
	var created = 0;
	var QS_ACTIVE_POPUP = ''
	var popup = $("#tip-popup")
	var popup_w = 600
	var content = $("#tip-popup-content")
	var ww_h = $(window).height() * 0.8
	var max_height = ww_h > 300 ? ww_h : 300
	if (ww_h < 300) {
		popup.css("position","absolute")
	} else {
		popup.css("position","fixed")
	}
	var win_w=$(window).width()
	var win_h = $(window).height()
	var site_opacity = $("#site-opacity")
	var width;
	
	function load_tip(tip_url,tip_title){
		//alert('ajax')
		QS_ACTIVE_POPUP = tip_url;
		requested = 1; created = 0;
		xhr = $.ajax({
			url: tip_url,
			cache: false,
			success: function(html){
				if (QS_ACTIVE_POPUP == tip_url) {
					content.html(html)
					popup.find(".title").html(tip_title)
					requested = 2
					created = 1
					show_tip()
				}
			}
		})
	}
	function show_tip() {
		//alert('show')
		
		site_opacity.show()
		popup.css("opacity","0").show() 
		if ($(window).width()<$(document).width()){
			popup.css({
				"position":"absolute",
				"left":0,
				"top":0
				})
		}
		if (content.width()>popup_w){content.width(popup_w)}
		if (content.height()>max_height){
			content.height(max_height)
			content.css("overflow","auto")
		}
		var pos_left = ($(window).width()-popup.width())/2
		var pos_top = ($(window).height()-popup.height())/2
		popup.css({"left":pos_left+"px", "top":pos_top+"px"})	
		popup.css("opacity","1")
		if ($.browser == 'msie' && $.browser.version < 7)
			popup.after($("<iframe>").attr({'id':'pop_fr'}).css({
					"width":popup.width()+"px",
					"height":popup.height()+"px",
					"position":"absolute",
					"left":pos_left+"px",
					"top":pos_top+"px",
					"z-index":999,
					"opacity":0
				})
			)
	}
	$("a[rel='tip']").click(function(){
		$("#popup").hide()
		tip_name = $(this).attr('name')
		if (tip_name.substring(tip_name.length - 10) != 'manual.php') {
			load_tip($(this).attr('name'),$(this).attr('title'))	
			return false
		}
	})
	$(".pop-button").each(function(){
		$(this).click(function(){
			popup.hide()
		})
	})
	popup.find(".cls").click(function(){
		site_opacity.hide()
		popup.hide()
		$("#pop_fr").die()
	})
})

