

var video_id = 0;
var video_start = 0;


$(function()
{
	highlight_courses_books();
	replace_by_artoteka_font("small");


	$().piroBox({
		my_speed: 300,  //animate speed
		radius: 4,  // caption rounded corners
		this_next : 'next', // next button inside or outside the imageBox--> next == inside, next_out == outside
		this_prev : 'prev', // prev button inside or outside the imageBox--> prev == inside, prev_out == outside
		credit: null // credits to pirolab website,if don't want to show it leave so!!
	});
});


function showsubmenu()
{
	$("#submenu").css("display","block");
}


function hidesubmenu()
{
	$("#submenu").css("display","none");
}
	             

function highlight_courses_books()
{
	$.each($(".b_over"),function()
	{                             
		var self = this;   
		var img = $(self).find("img");
		var out_src = img.attr("src");
		var over_src = "";

		var ar = out_src.split(".");
		for (var i = 0; i < ar.length; i++)
		{
			if (i == ar.length - 1) over_src += "_over.";
			over_src += ar[i];
		}

		if (over_src.length > 0)
		{
			var new_img = new Image();
			new_img.src = over_src;
			new_img.onload = function()
			{
				$(self).mouseover(function() { img.attr("src",over_src); }).mouseout(function() { img.attr("src",out_src); });
			}
		}
	});
}


function replace_by_artoteka_font(size)
{
	var alphabet = getArtotekaAlphabet();

	if (size == "small")
	{
		for (var i in alphabet)
		{
			alphabet[i][1] = parseInt(alphabet[i][1]/2);
			alphabet[i][0] = parseInt(alphabet[i][0]/2);
		}
	}


	$.each($("h1.artoteka_font"),function()
	{
		var str = $(this).html();
		var out = "";
		var string_length = 0;
		var word_length = new Array();
		var max_string_length = 1000;

		var word_i = 0;
		word_length[word_i] = 0;
		for (var i = 0; i < str.length; i++)
		{
			var letter = str.substr(i,1);
			if (alphabet[letter] != null && typeof alphabet[letter] == "object")
			{
				out += "<div class='aa_tmpl" + (size=="small"?"_small":"")  + "' style='width:"+alphabet[letter][1]+"px; background-position:-"+alphabet[letter][0]+"px 0px;'></div>\n";
				string_length += alphabet[letter][1];
				word_length[word_i] += alphabet[letter][1];
				if (string_length > max_string_length)
				{
					if (out.match(/~!~/) && word_length[word_i] <= max_string_length)
					{
						out = out.split("").reverse().join("").replace("~!~","~!!~").split("").reverse().join("");
					}
				}
			}
			else if (letter == " ")
			{
				out += "~!~";
				word_i++;
				word_length[word_i] = 0;
			}
			else
				out += letter;
		}
		out += "~!!~";
		out = out.replace(/~!~/g,"<div class='aa_tmpl_space'></div>").replace(/~!!~/g,"<div class='aa_tmpl_br'></div>");
		$(this).empty().append(out);
	});
}


function loadVideo(new_video_id)
{
	if (new_video_id != null) video_id = new_video_id;
	$("#divVideo").myload({url:"/video.php",params:{video_id:video_id}});
}

function loadPlaylist(new_video_id,new_video_start)
{
	if (new_video_start != null) video_start = new_video_start;
	$("#divPlaylist").myload({url:"/videoplaylist.php",params:{video_start:video_start,video_id:new_video_id}});
}


function video_playlistUp()
{
	if (video_start > 0)
		loadPlaylist(0,video_start-1);
}

function video_playlistDown()
{
	loadPlaylist(0,video_start+1);
}


function switch_subcourse()
{
	var i = $("#course_sel").val();
	var str = "";
	if (i > 0)
		str = $("#course_sel_"+i).html();
	$("#subcourse_place").empty().append(str);
}









