var is_opera = (navigator.userAgent.indexOf('Opera')!=-1);
var is_ie = (!is_opera && navigator.userAgent.indexOf('MSIE')!=-1);

var datum = new Date();
var isPopupOpen = false;

function InitPromo(firstelement, category_id)
{
	var flashvars = {
		docRoot: "/",
		xmlPath: "",
		xmlFile: "PromoGenerate?category_id="+category_id+"&amp;id="+firstelement,
		promoPath: "gallery/",
		themeID: parseInt(datum.getMonth(), 10) + 1
	};
	var params = {
		allowScriptAccess: "sameDomain",
		wmode: "transparent",
		quality: "best",
		allowFullScreen: "true"
	};
	var attributes = {};
	attributes.id = "promo_rotator";
	
	swfobject.embedSWF("swf/akcios_promorotator.swf", "promo_rotator", "972px", "150px", "10.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}

var ti = parseInt(datum.getMonth(), 10);

function InitHeadline(flashId, Headline1)
{
	var mw = Headline1.length * 13;
	var flashvars = {
		themeID: ti,
		headline: Headline1,
		maxWidth: flashId == "title" ? 350 : mw,
		flashID: flashId
	};
	var params = {
		allowScriptAccess: "sameDomain",
		wmode: "transparent",
		quality: "best",
		allowFullScreen: "true"
	};
	var attributes = {};
	attributes.id = flashId;
	
	swfobject.embedSWF("swf/headline.swf", flashId, "100%", "100%", "10.0.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}

function setHeadline(id, w)
{
	$(id).style.width = w + "px";
};

function SetAllHeadlines()
{
	var hl = getElementsByClass("producttitle", null, "h1");
	for(var i = 0; i < hl.length; i++)
	{
		InitHeadline(hl[i].id, hl[i].innerHTML);
	}
}

function ShowPopupDiv(gomb, id)
{
	document.onclick = function() {
		if (isPopupOpen) {
			document.body.removeChild(popup);
			isPopupOpen = false;
		}
	};
	if (parseInt(navigator.appVersion)>3) {
		if (is_ie) {
			var w = document.body.offsetWidth;
		}
		else
		{
			var w = window.innerWidth;
		}
		var top = gomb.offsetTop;
	}
	popup = document.createElement('div');
	popup.style.width = "970px";
	popup.style.height = "260px";
	popup.style.position = "absolute";
	popup.style.left = Math.round(w/2 - 485) + "px";
	
	popup.style.top = (top-200)+"px";
	popup.align = "center";
	popup.style.background = "#FFFFFF";
	popup.style.border = "1px solid #666666";
	popup.innerHTML = '<div align="center" style="margin-top:64px;"><img src="img/loading.gif" width="72" height="72" alt="" /></div>';
	document.body.appendChild(popup);
	
	AJAXrequest("/ajax/AccessoriesGenerate?id="+id, function(req) {
		if (req.readyState == 4 && req.status == 200) {
			popup.innerHTML = req.responseText;
			isPopupOpen = true;
		} 
	});
}

var akt = 0;
var aktid = 0;
function ResetDefault()
{
	if (akt == 0) Hide();
}
function Show()
{
	$("menu-container").style.backgroundImage = 'url(img/submenu_bg.png)';
	$("menu-top").style.backgroundImage = 'url(img/submenu_top.png)';
	$("menu-content").style.display = "block";
	$("menualja").style.display = "block";
	akt = 1;
}
function PrepareHide()
{
	akt = 0;
	setTimeout("ResetDefault()", 500);
}
function Hide()
{
	$("menu-container").style.backgroundImage = 'none';
	$("menu-top").style.backgroundImage = 'none';
	$("menu-content").style.display = "none";
	$("menualja").style.display = "none";
}
function SetAkt()
{
	akt = 1;
}

function GetMenuContent(id)
{
	if(aktid != id)
	{
		aktid = id;
		$("menu-content").innerHTML = '<div align="center"><img src="img/loading.gif" width="72" height="72" alt="" /></div>';
		Show();
		AJAXrequest("/ajax/MenuGenerate?menuid="+id, function(req) {
			if (req.readyState == 4 && req.status == 200) {
				$("menu-content").innerHTML = req.responseText;
			} 
		});
	}
	else Show();
}

var tipwidth='150px'; //default tooltip width
var tipbgcolor='#EEEEEE';  //tooltip bgcolor
var disappeardelay=250;  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px"; //horizontal offset of tooltip from anchor link
var horizontal_offset="-3px"; //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all;
var ns6=document.getElementById&&!document.all;

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>');

function getposOffset(what, offsettype) {
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null) {
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth) {
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!="") {
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=tipwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge) {
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
	if (whichedge=="rightedge") {
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
	}
	else {
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
	}
	return edgeoffset;
}

function fixedtooltip(title, menucontents, obj, e, tipwidth) {
	if (window.event) event.cancelBubble=true;
		else if (e.stopPropagation) e.stopPropagation();
	clearhidetip();
	dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv;
	menucontents = '<span>'+title+'</span>'+menucontents;
	dropmenuobj.innerHTML=menucontents;

	if (ie4||ns6) {
		showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth);
		dropmenuobj.x=getposOffset(obj, "left");
		dropmenuobj.y=getposOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+50+"px";
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+2+"px";
	}
}

function hidetip(e) {
	if (typeof dropmenuobj!="undefined") {
		if (ie4||ns6) dropmenuobj.style.visibility="hidden";
	}
}

function delayhidetip() {
	if (ie4||ns6) delayhide=setTimeout("hidetip()",disappeardelay);
}

function clearhidetip() {
	if (typeof delayhide!="undefined") clearTimeout(delayhide);
}

function InitServices()
{
	var uls = getElementsByClass("services2");
	if (uls.length > 0) {
		for (var j = 0; j < uls.length; j++) {
			var lis = uls[j].getElementsByTagName("a");
			for (var i = 0; i < lis.length; i++) {
				if (lis[i].rev != '') {
					lis[i].onclick = function(){
						return false;
					}
					lis[i].onmouseover = function(e){
						fixedtooltip(this.rel, this.rev, this, e ? e : event, "400px");
					};
					lis[i].onmouseout = function(){
						delayhidetip();
					};
				}
			}
		}
	}
	else {
		var ul = $("servicesul");
		if (ul) {
			var lis = ul.getElementsByTagName("a");
			for (var i = 0; i < lis.length; i++) {
				if (lis[i].rev != '') {
					lis[i].onclick = function(){
						return false;
					}
					lis[i].onmouseover = function(e){
						fixedtooltip(this.innerHTML, this.rev, this, e ? e : event, "400px");
					};
					lis[i].onmouseout = function(){
						delayhidetip();
					};
				}
			}
		}
	}
}
addEvent(window, "load", InitServices);
addEvent(window, "load", SetAllHeadlines);
