function rand(min, max)
{
	return Math.floor(Math.random() * (max - min + 1)) + min;
}
$(document).ready(function(){
	var points = "";
	for(i = 0; i < header_texts.length; i++) points += "<div class=\"header_point\" id=\"header_point"+i+"\" onclick=\"header_set("+i+")\"></div>";
	$("#header_points").html(points);
	header_current = rand(0, header_texts.length - 1);
	header_set(header_current);
	footer_set(0);
	var maxheight = Math.max($("#content_left").height(), $("#content_right").height());
	$("#content_left").height(maxheight);
	$("#content_right").height(maxheight);
	var footer_margin_top = $(document).height() - $("#header").height() - $("#content_right").height() - $("#footer").height() - 30;
	footer_margin_top = Math.max(footer_margin_top, 10);
	$("#footer").css("margin-top",footer_margin_top+"px");
    $(window).resize(function() { var footer_margin_top = $(document).height() - $("#header").height() - $("#content_right").height() - $("#footer").height() - 30; $("#footer").css("margin-top",footer_margin_top+"px"); });
	header_set(header_current);
	tooltip();
});
var header_current = 0;
function header_left()
{
	header_current--;
	if (header_current < 0) header_current = header_texts.length - 1;
	header_set(header_current);
}
function header_right()
{
	header_current++;
	if (header_current >= header_texts.length) header_current = 0;
	header_set(header_current);
}
function header_set(p)
{
	header_current = p;
	$("#header_content_info_center").html(header_texts[p]+" <a href=\""+header_links[p]+"\">[Още...]</a>");
	for(i = 0; i < header_texts.length; i++) $("#header_point"+i).removeClass('header_point_active');
	$("#header_point"+p).addClass('header_point_active');
}
function footer_set(p)
{
	for(i = 0; i < header_texts.length; i++) $("#footer_point"+i).removeClass('footer_point_active');
	$("#footer_point"+p).addClass('footer_point_active');
	$("#footer_content_center").html(footer_texts[p]);
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
