
function ajax_init_tabs() {
	var cookie = GetCookie("tab_news");
	if (cookie == 1) {
		$("#news_tabs_id_1").css({display: "block"});
		$("#news_tabs_id_2").css({display: "none"});
		$("#news_tabs_id_3").css({display: "none"});
	} else if (cookie == 2) {
		$("#news_tabs_id_1").css({display: "none"});
		$("#news_tabs_id_2").css({display: "block"});
		$("#news_tabs_id_3").css({display: "none"});
	} else if (cookie == 3) {
		$("#news_tabs_id_1").css({display: "none"});
		$("#news_tabs_id_2").css({display: "none"});
		$("#news_tabs_id_3").css({display: "block"});
	} else {
		$("#news_tabs_id_1").css({display: "block"});
		$("#news_tabs_id_2").css({display: "none"});
		$("#news_tabs_id_3").css({display: "none"});
	}
}

function ajax_init(element) {
	$(element+" .news_box_pages a.news_box_prev_active[@href*=#]").css({ "background-image": "url('images/box_prev_inactive.gif')", cursor: "default" });
	$(element+" .news_box_pages a.news_box_next_active[@href*=#]").css({ "background-image": "url('images/box_next_inactive.gif')", cursor: "default" });

	//$(element+" .news_box_pages a").click(function() { this.blur(); ajax_load(element, this.href); return false; }).css({display: "inline"});

	$(element+" .news_box_pages a").css({ display: "inline" });
	$(element+" .news_box_pages a.news_box_prev_active").click(function() { this.blur(); ajax_load(element, this.href); return false; });
	$(element+" .news_box_pages a.news_box_next_active").click(function() { this.blur(); ajax_load(element, this.href); return false; });

	$(element+" .news_box_pages a[@href*=#]").unbind();
	$(element+" .news_box_pages a[@href*=#]").click(function() {  this.blur(); return false; });
}

function ajax_load(element, url) {
	$(element+" .news_box_page").html('<div id="preloader"><img src="images/loading.gif" width="48" height="48" border="0" alt=""></div>');
	var preloader_padding = Math.floor(($(element).height() - 75) / 2);
	$('#preloader').css({'padding-top': preloader_padding,'padding-bottom': preloader_padding});
	$.get(url, function(data) { $(element).html(data); ajax_init(element); });
}

function tab_action(id, ids) {
	document.getElementById("news_tabs_id_"+id).style.display = "block";
	for (b=0; b<=ids.length-1; b++)
		document.getElementById("news_tabs_id_"+ids[b]).style.display = "none";
	SetCookie("tab_news", id, 1, '/', '', '');
}

function ajax_init_block_tabs() {
	var cookie = GetCookie("tab_block");
	if (cookie == 1) {
		$("#block_tabs_id_1").css({display: "block"});
		$("#block_tabs_id_2").css({display: "none"});
	} else if (cookie == 2) {
		$("#block_tabs_id_1").css({display: "none"});
		$("#block_tabs_id_2").css({display: "block"});
	} else {
		$("#block_tabs_id_1").css({display: "block"});
		$("#block_tabs_id_2").css({display: "none"});
	}
}

function block_tab_action(id, ids) {
	document.getElementById("block_tabs_id_"+id).style.display = "block";
	document.getElementById("block_tabs_id_"+ids).style.display = "none";
	SetCookie("tab_block", id, 1, '/', '', '');
}

var mouseovered = false;
var clicked = false;

function btns_mouseover() {
	if (this == clicked)
		return;
	if (mouseovered && mouseovered != this) {
		if (mouseovered == clicked)
			mouseovered.className = 'news_box_data_c';
		else
			mouseovered.className = '';
	}
	this.className = 'news_box_data';
	mouseovered = this;
}

function btns_onclick() {
	if (clicked && clicked != this)
		clicked.className = 'news_box_data';
	this.className = 'news_box_data_c';
	clicked = this;
}

function ajax_init_btns() {
	var buttons = document.getElementsByName('tab_btn');
	for (var n=0; n<buttons.length; n++) {
		buttons[n].onmouseover = btns_mouseover;
		buttons[n].onclick = btns_onclick;
	}
}


/* cookies */

function SetCookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires)
		expires = expires*1000*60*60*24;
	var expires_date = new Date(today.getTime()+(expires));
	document.cookie = name+"="+escape(value)+((expires)?";expires = "+expires_date.toGMTString():"")+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+((secure)?";secure":"");
}

function GetCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0, name.length)))
		return null;
	if (start == -1)
		return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1)
		end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

function DeleteCookie(name, path, domain) {
	var exp = new Date();
	exp.setTime(exp.getTime()-1);
	if (GetCookie(name))
		document.cookie = name+"="+((path)?";path="+path:"")+((domain)?";domain="+domain:"" )+";expires="+exp.toGMTString();
}

function CheckCoockie(domain) {
	if (document.cookie.length)
		return 0;
	else
		return 1;
}


/* menu */

if (document.images) {
	menu_bg = new Array();
	menu_bg[0] = new Image();
	menu_bg[0].src = "images/m00bg.png";
	menu_bg[1] = new Image();
	menu_bg[1].src = "images/m01bg.png";
	menu_bg[2] = new Image();
	menu_bg[2].src = "images/m02bg.png";
	menu_bg[3] = new Image();
	menu_bg[3].src = "images/m03bg.png";
	menu_bg[4] = new Image();
	menu_bg[4].src = "images/m04bg.png";
	menu_bg[5] = new Image();
	menu_bg[5].src = "images/m05bg.png";
	menu_bg[6] = new Image();
	menu_bg[6].src = "images/m06bg.png";
	menu_bg[7] = new Image();
	menu_bg[7].src = "images/m07bg.png";
	
	menu_en = new Array();
	menu_en[0] = new Image();
	menu_en[0].src = "images/m00en.png";
	menu_en[1] = new Image();
	menu_en[1].src = "images/m01en.png";
	menu_en[2] = new Image();
	menu_en[2].src = "images/m02en.png";
	menu_en[3] = new Image();
	menu_en[3].src = "images/m03en.png";
	menu_en[4] = new Image();
	menu_en[4].src = "images/m04en.png";
	menu_en[5] = new Image();
	menu_en[5].src = "images/m05en.png";
	menu_en[6] = new Image();
	menu_en[6].src = "images/m06en.png";
	menu_en[7] = new Image();
	menu_en[7].src = "images/m07en.png";
}

function set_menu(from, to, lang) {
	if (document.images) {
		if (lang == 'bg') {
			document.images[from].src = menu_bg[to].src;
		} else {
			document.images[from].src = menu_en[to].src;
		}
		//document.images[from].src = menu[to].src;
	}
}


/* banners */

var bw = new browsers_checks();
var stop = false;
var bans_ix = 0;
var ie_crr = bw.ie ? 1 : 0;

function bans_generate() {
	document.write('<style>');
	for (w=0; w<=bans.length-1-ie_crr; w++) {
		document.write('.bans-'+(w+1)+' { background-image: url(images/pictures/'+bans[w][0]+'); background-repeat: no-repeat; background-position: 242px 4px; }');
	}
	document.write('</style>');
	bans_start();
}

function bans_start() {
	if (!stop) {
		bansInterval = window.setInterval("bans_rotate()", 10000); // 10 sec.
		stop = true;
	}
}

function bans_stop() {
	if (stop) {
		window.clearInterval(bansInterval);
		stop = false;
	}
}

function bans_change(nid) {
	bans_ix = nid-1;
	bans_rotate();
}
/*
function bans_rotate(f) {
	if (f < 0) {
		if (bans_ix>1)
			bans_ix--;
		else
			bans_ix = 5;
	} else {
		if (bans_ix < 5)
			bans_ix++;
		else
			bans_ix = 1;
	}
	for (n=1; n<=bans.length-ie_crr; n++) {
		getObj("bans").className = "bans-"+n;
		getObj("n"+n).className = "bans-pages-n";
	}
	getObj("bans").className = "bans-"+bans_ix;
	getObj("n"+bans_ix).className = "bans-pages-c";
}
*/


// BANNER 1
var bw_1 = new browsers_checks();
var stop_1 = false;
var bans_ix_1 = 0;
var ie_crr_1 = bw_1.ie ? 1 : 0;

function bans_generate_1() {
	document.write('<style>');
	for (i=1; i<=bans_1.length-1-ie_crr_1; i++) {
		document.write('#banner1'+(i+1)+' { display: none; }');
	}
	document.write('</style>');
	for (w=0; w<=bans_1.length-1-ie_crr_1; w++) {
		document.write('<div id="banner1'+(w+1)+'">');
		document.write('<a href="'+bans_1[w][0]+'" target="_blank"><img src="images/pictures/'+bans_1[w][1]+'" width="140" height="60" border="0" alt="" /></a>');
		document.write('</div>');
	}
	bans_start_1();
}
function bans_start_1() {
	if (!stop_1) {
		bansInterval_1 = window.setInterval("bans_rotate_1()", 5000); // 10 sec.
		stop_1 = true;
	}
}
function bans_stop_1() {
	if (stop_1) {
		window.clearInterval(bansInterval_1);
		stop_1 = false;
	}
}
function bans_change_1(nid) {
	bans_ix_1 = nid-1;
	bans_rotate_1();
}
// BANNER 2
var bw_2 = new browsers_checks();
var stop_2 = false;
var bans_ix_2 = 0;
var ie_crr_2 = bw_2.ie ? 1 : 0;

function bans_generate_2() {
	document.write('<style>');
	for (i=1; i<=bans_2.length-1-ie_crr_2; i++) {
		document.write('#banner2'+(i+1)+' { display: none; }');
	}
	document.write('</style>');
	for (w=0; w<=bans_2.length-1-ie_crr_2; w++) {
		document.write('<div id="banner2'+(w+1)+'">');
		document.write('<a href="'+bans_2[w][0]+'" target="_blank"><img src="images/pictures/'+bans_2[w][1]+'" width="140" height="140" border="0" alt="" /></a>');
		document.write('</div>');
	}
	bans_start_2();
}
function bans_start_2() {
	if (!stop_2) {
		bansInterval_2 = window.setInterval("bans_rotate_2()", 5000); // 10 sec.
		stop_2 = true;
	}
}
function bans_stop_2() {
	if (stop_2) {
		window.clearInterval(bansInterval_2);
		stop_2 = false;
	}
}
function bans_change_2(nid) {
	bans_ix_2 = nid-1;
	bans_rotate_2();
}
// BANNER 3
var bw_3 = new browsers_checks();
var stop_3 = false;
var bans_ix_3 = 0;
var ie_crr_3 = bw_3.ie ? 1 : 0;

function bans_generate_3() {
	document.write('<style>');
	for (i=1; i<=bans_3.length-1-ie_crr_3; i++) {
		document.write('#banner3'+(i+1)+' { display: none; }');
	}
	document.write('</style>');
	for (w=0; w<=bans_3.length-1-ie_crr_3; w++) {
		document.write('<div id="banner3'+(w+1)+'">');
		document.write('<a href="'+bans_3[w][0]+'" target="_blank"><img src="images/pictures/'+bans_3[w][1]+'" width="140" height="140" border="0" alt="" /></a>');
		document.write('</div>');
	}
	bans_start_3();
}
function bans_start_3() {
	if (!stop_3) {
		bansInterval_3 = window.setInterval("bans_rotate_3()", 5000); // 10 sec.
		stop_3 = true;
	}
}
function bans_stop_3() {
	if (stop_3) {
		window.clearInterval(bansInterval_3);
		stop_3 = false;
	}
}
function bans_change_3(nid) {
	bans_ix_3 = nid-1;
	bans_rotate_3();
}











function browsers_checks() {
	this.n = navigator.userAgent;
	this.dom = document.getElementById ? 1 : 0;
	this.ie4 = document.all && !this.dom ? 1 : 0;
	this.ns4 = document.layers ? 1 : 0;
	this.ns = (this.n.indexOf("Netscape") >- 1) && !this.ns4;
	this.mz = (this.n.indexOf("Gecko") >- 1) && !this.ns;
	this.op = this.n.indexOf("Opera") >- 1;
	this.op8 = this.n.indexOf("Opera/8") >- 1 || (this.n.indexOf("MSIE") >- 1 && !this.ie4);
	this.ie = (this.n.indexOf("MSIE") >- 1) && !this.op && !this.ie4;
	this.bw = (this.ns || this.mz || this.ie || this.op8) ? 1 : 0;
	return this;
}

function getObj(id) {
	var obj = false;
	if (document.getElementById(id))
		obj = document.getElementById(id);
	return obj
}


/* newsletter */

function newsletter_show(obj) {
	if (document.getElementById) {
		var newsletter = document.getElementById('newsletter')
		newsletter.style.left = newsletter_getpos(obj, "left")+"px"
		newsletter.style.top = newsletter_getpos(obj, "top")+"px"
		newsletter.style.display = "block"
		return false
	}
	else
		return true
}

function newsletter_hide() {
	document.getElementById('newsletter').style.display = "none"
}

function newsletter_getpos(obj, offsettype) {
	var totaloffset = (offsettype == "left") ? obj.offsetLeft-110 : obj.offsetTop+15;
	var parentEl = obj.offsetParent;
	while (parentEl != null) {
		totaloffset = (offsettype == "left") ? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return totaloffset;
}

function newsletter_validate() {

	//var error = false;
	if (document.newsletter_form.YMLP0.value == '') {
		alert('Enter E-Mail address');
		return;
	} else {
		document.newsletter_form.submit();
		//return true;
	}

}

/* djs */

var speed = 25;
var loop, timer;

function makeObj(obj, nest) {
	nest = (!nest) ? "" : 'document.'+nest+'.'
	this.el = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+'document.'+obj) : 0;
	this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest+'document.'+obj) : 0;
	this.scrollWidth = bw.ns4 ? this.css.document.height : this.el.offsetWidth
	this.clipWidth = bw.ns4 ? this.css.clip.height : this.el.offsetWidth
	this.right = goRight;
	this.left = goLeft;
	this.moveIt = moveIt;
	this.x;
	this.y;
	this.obj = obj + "Object"
	eval(this.obj + "=this")
	return this
}

function moveIt(x, y) {
	this.x = x;
	this.y = y;
	this.css.left = this.x;
	this.css.top = this.y;
}

function goDown(move) {
	if (this.y >- this.scrollHeight + oCont.clipHeight) {
		this.moveIt(0, this.y-move)
		if (loop) setTimeout(this.obj+".down("+move+")", speed)
	}
}

function goUp(move) {
	if (this.y < 0) {
		this.moveIt(0, this.y-move)
		if(loop) setTimeout(this.obj+".up("+move+")", speed)
	}
}

function goLeft(move){
	if (this.x >- this.scrollWidth + oCont.clipWidth) {
		this.moveIt(this.x-move,0)
			if (loop) setTimeout(this.obj+".left("+move+")", speed)
	}
}

function goRight(move) {
	if (this.x < 0){
		this.moveIt(this.x - move, 0)
		if (loop) setTimeout(this.obj+".right("+move+")", speed)
	}
}

function scroll(speed) {
	if (loaded) {
		loop = true;
		if (speed > 0)
			oScroll.left(speed)
		else
			oScroll.right(speed)
	}
}

function noScroll() {
	loop = false
	if (timer) clearTimeout(timer)
}

var loaded;

function scrollInit() {
	oCont = new makeObj('djs_div_cont')
	oScroll = new makeObj('djs_div_text', 'djs_div_cont')
	oScroll.moveIt(0, 0)
	oCont.css.visibility = 'visible'
	loaded = true;
}

onload = scrollInit;


if (document.images) {
	rightarron = new Image();
	rightarron.src = "images/djs_r_on.png";
	leftarron = new Image();
	leftarron.src = "images/djs_l_on.png";
	rightarroff = new Image();
	rightarroff.src = "images/djs_r_off.png";
	leftarroff = new Image();
	leftarroff.src = "images/djs_l_off.png";
}

function scroll_on(imageName) {
	if (document.images) {
		document[imageName].src = eval(imageName + "on.src");
	}
}

function scroll_off(imageName) {
	if (document.images) {
		document[imageName].src = eval(imageName + "off.src");
	}
}

function dj_image_show(obj, id) {
	if (document.getElementById) {
		var djs_images = document.getElementById(id);
		djs_images.style.left = dj_image_getpos(obj, 'left')+'px';
		djs_images.style.top = dj_image_getpos(obj, 'top')+'px';
		djs_images.style.display = "block";
	}
}

function dj_image_hide(id) {
	document.getElementById(id).style.display = "none";
}

function dj_image_getpos(obj, offsettype) {
	var totaloffset = (offsettype == "left") ? obj.offsetLeft+3 : obj.offsetTop+13;
	var parentEl = obj.offsetParent;
	while (parentEl != null) {
		totaloffset = (offsettype == "left") ? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return totaloffset;
}

function loadframe(frame, url) {
	if (window.frames[frame]) {
		window.frames[frame].location = url;
		SetCookie("frame", url, 1, '/', '', '');
		return false;
	}
	else return true;
}

function initframe() {
	var frameurl = GetCookie("frame");
	if (frameurl !== '') {
		if (window.frames['main']) {
			window.frames['main'].location = frameurl;
		}
	}
}
