//euromena
$(
    function () {
        var euromena = $('span.euromena');
        var skkmena = $('span.skkmena');
        if (euromena) {
            euromena.each(function () {
                var self = $(this);
                var offset = self.offset();
                var euro = $('<span class="eurogo"> (&euro;)</span>').css('cursor','pointer');
                self.before(euro);
                euro.hover(function () {
                    var offset = $(this).offset();
                    self.css(
                        {
                            top: (offset.top - $(this).height() - self.height() + 10) + 'px',
                            left: offset.left + 'px'
                        }
                    ).show();
                },function () {
                    self.hide();
                });
            });
        }
        if (skkmena) {
            skkmena.each(function () {
                var self = $(this);
                var offset = self.offset();
                var euro = $('<span class="eurogo"> (SKK)</span>').css('cursor','pointer');
                self.before(euro);
                euro.hover(function () {
                    var offset = $(this).offset();
                    self.css(
                        {
                            top: (offset.top - $(this).height() - self.height() + 10) + 'px',
                            left: offset.left + 'px'
                        }
                    ).show();
                },function () {
                    self.hide();
                });
            });
        }
    }
);




var gClientIsGecko = (window.controllers) ? true : false;
var gClientIsOpera = (window.opera) ? true : false;
var gClientIsIE    = (document.all && !gClientIsOpera) ? true : false;
var gClientIsIE5   = (gClientIsIE && /MSIE 5\.0/.test(navigator.appVersion)) ? true : false;
var gClientIsMac   = (/Mac/.test(navigator.appVersion)) ? true : false;
var DOM = {
	isParentOf: function( parentElm, contextElm) {
		while(contextElm && (contextElm != parentElm))
			contextElm = contextElm.parentNode;
		return (contextElm == parentElm);
	},
	getParentOrSelf: function( contextElm, nodeName ) {
		nodeName = nodeName.toLowerCase();
		while(contextElm.nodeName.toLowerCase() != nodeName && contextElm.parentNode)
			contextElm = contextElm.parentNode;
		return contextElm;
	},
	addClass: function( elm, className ) {
		elm.className += ' '+className;
	},
	removeClass: function( elm, className) {
		var classMatch = new RegExp('\\b'+className+'\\b', 'g');
		if(classMatch.test(elm.className))
			elm.className = elm.className.replace(classMatch, ' ');
	}	
};

function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

timer = null;
IMG = null;
NewWindow = null;
function ViewImage(Isrc,title) {
	IMG = new Image;
	IMG.src = Isrc;
	if (typeof(title)=="undefined" || title=="") title="Gallery";
	if (NewWindow) { NewWindow.close(); }
	if (NewWindow==null || NewWindow.closed) {
		settings=
		 "left="+50+","
		 +"top="+50+","
		 +"width="+640+","
		 +"height="+480+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=no,"
		 +"resizable=yes"
		 NewWindow = window.open("",'Gallery',settings);
	}
	NewWindow.document.open();
	NewWindow.document.clear();
	NewWindow.document.write(
 	"<html><head><title>"+ title +"</title>" +
	"<script type=\"text/javascript\">\n" + 
	"function disableclick(e) {\n" + 
	"	if (document.all) {\n" + 
	"		if (event.button==2 || event.button==3) {\n" + 
	"			if (event.srcElement.tagName==\"IMG\") {\n" + 
	"				window.close();\n" + 
	"				return false;\n" + 
	"			}\n" + 
	"		}\n" + 
	"	}\n" + 
	"	else if (document.layers) {\n" + 
	"		if (e.which == 3) {\n" + 
	"			window.close();\n" + 
	"			return false;\n" + 
	"		}\n" + 
	"	}\n" + 
	"	else if (document.getElementById) {\n" + 
	"		if (e.which==3 && e.target.tagName==\"IMG\") {\n" + 
	"			window.close();\n" + 
	"			return false;\n" + 
	"		}\n" + 
	"	}\n" + 
	"}\n" + 
	"</script>"
	+"</head>\n"
	+"<body topmargin=0 leftmargin=0 bgcolor=\"#FFFFFF\" onclick=\"window.close();\">\n"
	+"<table border=\"0\" cellpadding=\"0\" cellspacing=0><tr><td align=\"center\" valign=\"middle\"><img src=" + IMG.src + " border=0 alt=\""+title+"\" onmousedown=\"disableclick(event);\" /></td></tr></table>\n"
	+"</body>\n"
	+"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
	timer = setInterval("resize()",250);
}

function resize() {
    if(!IMG.complete){ return; }
    clearInterval(timer);
	resizeWindowTo(NewWindow,(IMG.width-18+30),(IMG.height-18+50));
	IMG = null;
}

function resizeWindowTo(WindowObject,w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			WindowObject.outerWidth=w;
			WindowObject.outerHeight=h;
		}
		else WindowObject.resizeTo(w,h);
	}
}

function GenerateIndexSlogan() {
	var SloganData = GetSloganData();
	if (!SloganData) { return false; }
	//text
	var textTime = 0;
	if (navigator.appName == "Microsoft Internet Explorer") { textTime = 500; }
	window.setTimeout(function foo() {
		document.getElementById('mainslogantext').innerHTML = SloganData[1];
	},textTime);
	//image
	//efekt:
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById('mainimage').style.filter = "blendTrans(duration=2)";
		document.getElementById('mainimage').filters[0].Apply();
		document.getElementById('mainimage').filters[0].Play();
	}
	document.getElementById('mainimage').src = SloganData[0];
}

var curIdx = 0;
function GetSloganData() {
	//var idx = Math.round(Math.random()*IndexSlogan.length);
	if (curIdx > IndexSlogan.length-1) { curIdx = 0 }
	return IndexSlogan[curIdx++];
}

function ViewPhotogalleryImage(iSrc,iAlt,iDescr) {
	//obrazok
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById('PhotogalleryImage').style.filter = "blendTrans(duration=1)";
		document.getElementById('PhotogalleryImage').filters[0].Apply();
		document.getElementById('PhotogalleryImage').filters[0].Play();
	}
	document.getElementById('PhotogalleryImage').src = iSrc;
	document.getElementById('PhotogalleryImage').alt = iAlt;
	//popis
	document.getElementById('PhotogalleryImageDescr').innerHTML = iDescr;
}

PopupWin = null;
function OpenPopup(url,w,h) {
	if (PopupWin) { PopupWin.close(); }
	if (PopupWin==null || PopupWin.closed) {
		settings=
		 "left="+(screen.width-w)/2+","
		 +"top="+(screen.width-h)/2+","
		 +"width="+w+","
		 +"height="+h+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=no,"
		 +"resizable=yes"
		 PopupWin = window.open(url,'PopupWin',settings);
	}
	PopupWin.focus();
}

function RezervationChangePrice(checked,amount,totalprice)
{
    var CurPrice = eval(document.getElementById(totalprice).innerHTML.replace(/[^0-9]/,''));
    if (checked)
    {
        CurPrice = CurPrice - 1 + 1 + amount;
    }
    else
    {
        CurPrice = CurPrice - 1 + 1 - amount;
    }
    document.getElementById(totalprice).innerHTML = NumberFormat(CurPrice);
    var eurid = totalprice.replace('price','priceSKK');
    var eurel = document.getElementById(eurid);
    if (eurel) {
        eurel.innerHTML = (Math.round(CurPrice * 100 * 30.126) / 100) + ' SKK';
    }
}

function RezervationSetPrice(amount,totalprice,uncheck)
{
    document.getElementById(totalprice).innerHTML = NumberFormat(amount);
    if (uncheck) {
        for (var i = 0 ; i < uncheck.length ; i++) {
            if (!document.getElementById(uncheck[i]).disabled) {
                document.getElementById(uncheck[i]).checked = false;
            }
        }
    }
    var eurid = totalprice.replace('price','priceSKK');
    var eurel = document.getElementById(eurid);
    if (eurel) {
        eurel.innerHTML = (Math.round(amount * 100 * 30.126) / 100) + ' SKK';
    }
}

function NumberFormat(num)
{
    num = num.toString();
    var output = '';
    for (i = num.length-1 ; i >= 0 ; i--)
    {
        output = num.charAt(i) + output;
        if (i > 0 && ((num.length - i) % 3) == 0)
        {
            output = ' ' + output;
        }
    }
    return output;
}

// Getting element dimensions
function getDimensions( elm ) {
	var box = { x:0, y:0, w:0, h:0 };
	if(document.getBoxObjectFor) {
		var boxRef = document.getBoxObjectFor(elm);
		box.x = boxRef.x;
		box.y = boxRef.y;
		box.w = boxRef.width;
		box.h = boxRef.height;
	}
	else if(elm.getBoundingClientRect) {
		var rxIE50 = /MSIE 5\.0/g;
		//alert(rxIE50 + '.test("' + navigator.appVersion + '" = ' + rxIE50.test(navigator.appVersion));
		var boxRef = elm.getBoundingClientRect();
		box.x = boxRef.left;
		box.y = boxRef.top;
		box.w = (boxRef.right - boxRef.left);
		box.h = (boxRef.bottom - boxRef.top);
		//var s='';for(p in boxRef) s+=p+'    '; alert(s);
		// Damn IE...
		if(document.compatMode && document.compatMode != 'BackCompat') {
			// IE6/compliance mode
			box.x += document.documentElement.scrollLeft - 2;
			box.y += document.documentElement.scrollTop - 2;
		}
		else if(!gClientIsIE5) {
			// IE5.5
			box.x += document.body.scrollLeft - 2;
			box.y += document.body.scrollTop - 2;
		}
	}
	else {
		// No known box information available, walking
		// manually through offsetParents to calculate x/y coordinates
		box.w = elm.offsetWidth;
		box.h = elm.offsetHeight;
		while(elm) {
			box.x += elm.offsetLeft;
			box.y += elm.offsetTop;
			if(elm.offsetParent) // Required for Safari 1.3 :(
				elm = elm.offsetParent;
			else
				break;
		}
	}
	var cc;
	if(cc = document.getElementById('bodyconstraint'))
		box.x -= cc.offsetLeft;
	return box;
}
