/**
* Name: piroBox v.1.2.1
* Date: November 2009
* Autor: Diego Valobra (http://www.pirolab.it),(http://www.diegovalobra.com)
* Version: 1.2.1
* Licence: CC-BY-SA http://creativecommons.org/licenses/by-sa/2.5/it/
**/		
(function(a){a.fn.piroBox=function(b){b=jQuery.extend({my_speed:null,close_speed:300,bg_alpha:0.5,scrollImage:null,pirobox_next:"piro_next_out",pirobox_prev:"piro_prev_out",radius:4,close_all:".piro_close,.piro_overlay",slideShow:null,slideSpeed:null},b);function c(){var s='<tr><td colspan="3" class="pirobox_up"></td></tr><tr><td class="t_l"></td><td class="t_c"></td><td class="t_r"></td></tr><tr><td class="c_l"></td><td class="c_c"><span><span></span></span><div></div></td><td class="c_r"></td></tr><tr><td class="b_l"></td><td class="b_c"></td><td class="b_r"></td></tr><tr><td colspan="3" class="pirobox_down"></td></tr>';var q=a(window).height();var p=a(jQuery('<div class="piro_overlay"></div>').hide().css({opacity:+b.bg_alpha,height:q+"px"}));var l=a(jQuery('<table class="pirobox_content" cellpadding="0" cellspacing="0"></table>'));var w=a(jQuery('<div class="caption"></div>').css({opacity:"0.8","-moz-border-radius":b.radius+"px","-khtml-border-radius":b.radius+"px","-webkit-border-radius":b.radius+"px","border-radius":b.radius+"px"}));var f=a(jQuery('<div class="piro_nav"></div>'));var t=a(jQuery('<div class="piro_close"></div>'));var r=a(jQuery('<a href="#play" class="play"></a>'));var n=a(jQuery('<a href="#stop" class="stop"></a>'));var j=a(jQuery('<a href="#prev" class="'+b.pirobox_prev+'"></a>'));var k=a(jQuery('<a href="#next" class="'+b.pirobox_next+'"></a>'));a("body").append(p).append(l);l.append(s);a(".pirobox_up").append(t);a(".pirobox_down").append(f);a(".c_c").append(r);r.hide();f.append(j).append(k).append(w);if(j.is(".piro_prev_out")||k.is(".piro_next_out")){a("body").append(j).append(k);j.add(k).hide()}else{f.append(j).append(k)}var e=j.width();l.hide();var x=a("a[class^='pirobox_gall']");var y=new Object();for(var v=0;v<x.length;v++){var h=a(x[v]);y["a."+h.attr("class")]=0}var o=new Array();for(var B in y){o.push(B);if(a(B).length===1){alert("For single image is recommended to use class pirobox");a(B).css("border","2px dotted red")}}for(var v=0;v<o.length;v++){a(o[v]).each(function(i){this.rel=i+1+"&nbsp;/&nbsp;"+a(o[v]).length});var d=a(o[v]+":first").addClass("first");var u=a(o[v]+":last").addClass("last")}a(x).each(function(i){this.rev=i+0});var m=a(x);var z=a("a.pirobox");a.fn.fixPNG=function(){return this.each(function(){var i=a(this).css("backgroundImage");if(i.match(/^url\(["']?(.*\.png)["']?\)$/i)){i=RegExp.$1;a(this).css({backgroundImage:"none",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod="+(a(this).css("backgroundRepeat")=="no-repeat"?"crop":"scale")+", src='"+i+"')"}).each(function(){var C=a(this).css("position");if(C!="absolute"&&C!="relative"){a(this).css("position","relative")}})}})};a(window).resize(function(){var i=a(window).height();p.css({visibility:"visible",height:+i+"px"})});j.add(k).bind("click",function(D){D.preventDefault();var i=parseInt(a(m).filter(".item").attr("rev"));var C=a(this).is(".piro_prev_out,.piro_prev")?a(m).eq(i-1):a(m).eq(i+1);C.click();t.add(w).add(k).add(j).css("visibility","hidden")});z.each(function(C){var i=a(this);i.bind("click",function(F){F.preventDefault();g(i.attr("href"));var D=i.attr("href");var E=i.attr("title");if(E==""){w.html("<p>"+D+"<a href="+D+' class="link_to" target="_blank" title="Open Image in a new window"></a></p>')}else{w.html("<p>"+E+"<a href="+D+' class="link_to" target="_blank" title="Open Image in a new window"></a></p>')}a(".c_c").addClass("unique");k.add(j).add(t).add(w).hide();a(".play").remove()})});a(m).each(function(C){var i=a(this);i.bind("click",function(G){G.preventDefault();g(i.attr("href"));var D=i.attr("href");var F=i.attr("title");var E=i.attr("rel");if(F==""){w.html("<p>"+D+'<em class="number">'+E+"</em><a href="+D+' class="link_to" target="_blank" title="Open Image in a new window"></a></p>')}else{w.html("<p>"+F+'<em class="number">'+E+"</em><a href="+D+' class="link_to" target="_blank" title="Open Image in a new window"></a></p>')}if(i.is(".last")){a(".number").css("text-decoration","underline")}else{a(".number").css("text-decoration","none")}if(i.is(".first")){j.hide();k.show()}else{k.add(j).show()}if(i.is(".last")){j.show();k.hide()}if(i.is(".last")&&i.is(".first")){j.add(k).hide();a(".number").hide();r.remove()}a(m).filter(".item").removeClass("item");i.addClass("item");a(".c_c").removeClass("unique")})});var g=function(i){r.add(n).hide();t.add(w).add(k).add(j).css("visibility","hidden");if(l.is(":visible")){a(".c_c div").children().fadeOut(300,function(){a(".c_c div").children().remove();A(i)})}else{a(".c_c div").children().remove();l.show();p.fadeIn(300,function(){A(i)})}};var A=function(H){if(l.is(".loading")){return}l.addClass("loading");var C=new Image();C.onerror=function(){var J=a(l).height();l.css({marginTop:parseInt(a(document).scrollTop())-(J/1.9)});a(".c_c div").append('<p class="err_mess">There seems to be an Error:&nbsp;<a href="#close" class="close_pirobox">Close Pirobox</a></p>');a(".close_pirobox").bind("click",function(){a(".err_mess").remove();l.add(p).fadeOut(b.close_speed);l.removeClass("loading");a(".c_c").append(r);return false})};C.onload=function(){var M=C.height;var O=C.width;var L=a(l).height();var Q=a(window).height();var K=a(window).width();if(M+100>Q||O+100>K){var J=O;var P=M;var R=(O+250)/K;var N=(M+250)/Q;if(N>R){J=Math.round(O*(1/N));P=Math.round(M*(1/N))}else{J=Math.round(O*(1/R));P=Math.round(M*(1/R))}M+=P;O+=J;a(C).height(P).width(J).hide();a(".c_c div").animate({height:P+"px",width:J+"px"},b.my_speed);l.animate({height:(P+20)+"px",width:(J+20)+"px",marginLeft:"-"+((J)/2+10)+"px",marginTop:parseInt(a(document).scrollTop())-(P/1.9)-20},b.my_speed,function(){a(".piro_nav,.caption").css({width:(J)+"px"});a(".piro_nav").css("margin-left","-"+(J+5)/2+"px");var S=w.height();w.css({bottom:"-"+(S+5)+"px"});a(".c_c div").append(C);t.css("display","block");k.add(j).add(t).css("visibility","visible");w.css({visibility:"visible",display:"block"});a(C).show().fadeIn(300);l.removeClass("loading");if(b.slideShow=="slideshow"){r.add(n).show()}else{r.add(n).hide()}})}else{a(C).height(M).width(O).hide();a(".c_c div").animate({height:M+"px",width:O+"px"},b.my_speed);l.animate({height:(M+20)+"px",width:(O+20)+"px",marginLeft:"-"+((O)/2+10)+"px",marginTop:parseInt(a(document).scrollTop())-(M/1.9)-20},b.my_speed,function(){a(".piro_nav,.caption").css({width:(O)+"px"});a(".piro_nav").css("margin-left","-"+(O+5)/2+"px");var S=w.height();w.css({bottom:"-"+(S+5)+"px"});a(".c_c div").append(C);t.css("display","block");k.add(j).add(t).css("visibility","visible");w.css({visibility:"visible",display:"block"});a(C).fadeIn(300);l.removeClass("loading");if(b.slideShow=="slideshow"){r.add(n).show()}else{r.add(n).hide()}})}};C.src=H;var i=a(window).height();var F=a(".piro_prev_out").height();a(".piro_prev_out").add(".piro_next_out").css({marginTop:parseInt(a(document).scrollTop())+(i/F-125)});a(".caption p").css({"-moz-border-radius":b.radius+"px","-khtml-border-radius":b.radius+"px","-webkit-border-radius":b.radius+"px","border-radius":b.radius+"px"});n.bind("click",function(J){J.preventDefault();clearTimeout(I);a(m).children().removeAttr("class");a(".stop").remove();a(".c_c").append(r);k.add(j).css("width",e+"px")});r.bind("click",function(J){J.preventDefault();clearTimeout(I);if(a(C).is(":visible")){a(m).children().addClass(b.slideShow);a(".play").remove();a(".c_c").append(n)}k.add(j).css({width:"0px"});return E()});a(b.close_all).bind("click",function(J){clearTimeout(I);if(a(C).is(":visible")){J.preventDefault();t.add(p).add(l).add(w).add(k).add(j).fadeOut(b.close_speed);l.removeClass("loading");a(m).children().removeAttr("class");k.add(j).css("width",e+"px").hide();a(".stop").remove();a(".c_c").append(r);r.hide()}});function E(){clearTimeout(I);if(a(m).filter(".item").is(".last")){a(m).children().removeAttr("class");k.add(j).css("width",e+"px");a(".stop").remove();a(".c_c").append(r);r.hide()}else{if(a(m).children().is("."+b.slideShow)){k.click()}}}var I=setInterval(E,b.slideSpeed*1000);a().bind("keydown",function(J){if(J.keyCode===27){J.preventDefault();if(a(C).is(":visible")||a(".c_c>div>p>a").is(".close_pirobox")){t.add(p).add(l).add(w).add(k).add(j).fadeOut(b.close_speed);l.removeClass("loading");clearTimeout(I);a(m).children().removeAttr("class");a(".stop").remove();a(".c_c").append(r);k.add(j).css("width",e+"px");a(m).add(z).children().fadeTo(100,1)}}}).bind("keydown",function(J){if(a(".c_c").is(".unique")||a(".item").is(".first")){}else{if(a(".c_c").is(".c_c")&&(J.keyCode===37)){J.preventDefault();if(a(C).is(":visible")){clearTimeout(I);a(m).children().removeAttr("class");a(".stop").remove();a(".c_c").append(r);k.add(j).css("width",e+"px");j.click()}}}if(a(".c_c").is(".unique")||a(".item").is(".last")){}else{if(a(".c_c").is(".c_c")&&(J.keyCode===39)){J.preventDefault();if(a(C).is(":visible")){clearTimeout(I);a(m).children().removeAttr("class");a(".stop").remove();a(".c_c").append(r);k.add(j).css("width",e+"px");k.click()}}}});a.browser.msie6=(a.browser.msie&&/MSIE 6\.0/i.test(window.navigator.userAgent));if(a.browser.msie6&&!/MSIE 8\.0/i.test(window.navigator.userAgent)){a(".t_l,.t_c,.t_r,.c_l,.c_r,.b_l,.b_c,.b_r,a.piro_next, a.piro_prev,a.piro_prev_out,a.piro_next_out,.c_c,.piro_close,a.play,a.stop").fixPNG();var D=a(document).height();p.css("height",D+"px")}if(a.browser.msie){b.close_speed=0}function G(){if(a(l).is(":visible")){window.onscroll=function(){var L=a(l).height();l.css({marginTop:parseInt(a(this).scrollTop())-(L/1.9)-10});var J=a(window).height();var K=a(".piro_prev_out").height();a(".piro_prev_out").add(".piro_next_out").css({marginTop:parseInt(a(document).scrollTop())+(J/K-125)})}}}if(b.scrollImage==true){return G()}}}c()}})(jQuery);



/** Alerts */
(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .6,                // transparency level of overlay
		overlayColor: '#000',               // base color of overlay
		draggable: false,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Mégse&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		alert: function(message, title, callback) {
			if( title == null ) title = 'Alert';
			$.alerts._show(title, message, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		confirm: function(message, title, callback) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', function(result) {
				if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			if( title == null ) title = 'Prompt';
			$.alerts._show(title, message, value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		// Private methods
		
		_show: function(title, msg, value, type, callback) {
			
			$.alerts._hide();
			$.alerts._overlay('show');
			
			$("BODY").append(
			  '<div id="popup_container">' +
			    '<h1 id="popup_title"></h1>' +
			    '<div id="popup_content">' +
			      '<div id="popup_message"></div>' +
				'</div>' +
			  '</div>');
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0
			});
			
			$("#popup_title").text(title);
			$("#popup_content").addClass(type);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			switch( type ) {
				case 'alert':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});
					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
		
		_hide: function() {
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', function() {
							$.alerts._reposition();
						});
					break;
					case false:
						$(window).unbind('resize');
					break;
				}
			}
		}
		
	}
	
	// Shortuct functions
	jAlert = function(message, title, callback) {
		$.alerts.alert(message, title, callback);
	}
	
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);

/* cookies */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* anchor */

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

var arrowimages={down:['downarrowclass', '/site/images/frontend/down.gif', 23], right:['rightarrowclass', '/site/images/frontend/right.gif']}

var cmsbuildmenu={

animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(cmsbuildmenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(cmsbuildmenu.animateduration.out)
				}
			) //end hover
			$curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="cmsslidemenu" on page:
cmsbuildmenu.buildmenu("cmsslidemenu", arrowimages);
