function run_forecasts_flash(that)
{
	var wrapper = that;

	var flash = $(that).flash(
		{
			src: $(that).attr('src'),
			width: $(that).attr('width'),
			height: $(that).attr('height'),
			allowscriptaccess: 'sameDomain'
		},
		null,
		null,
		function() { $(wrapper).find('.alt').css('display', 'block'); }
	);
}

function run_fb_auth(that) {
	if (typeof(FB) == "undefined") {
		return;
	}

	var appId = $(that).attr('app_id');
	var urlBase = $(that).attr('url_base');
	var urlLogin = urlBase+'auth_mode=fb';
	var urlLogout = urlBase+'auth_mode=fb&auth_action=logout';

	FB.Event.subscribe('auth.login', function() {
		window.location.href = urlLogin;
	});
	FB.Event.subscribe('auth.logout', function() {
		window.location.href = urlLogout;
	});
	if ($(that).attr('get_login_status') != undefined && $(that).attr('get_login_status') != 'false') {
		FB.getLoginStatus(function(response) {
			if (response.session) {
				window.location.href = urlLogin;
			}
		});
	}

	$('a#fb_login_button').click(function() {
		FB.login(function(response) {
			}, {perms:'email'});
	});

	$('a#fb_logout_button').click(function() {
		FB.logout(function(response) {
			window.location.href = urlLogout;
		});
	});
}

function run_load_comments_form(that) {
	var datasource = $(that).attr('datasource');
	if (typeof(FB) == "object") {
		FB.getLoginStatus(function(response) {
			if (response.session) {
				datasource = datasource + (datasource.match(/\?/) ? '&' : '?') + 'auth_mode=fb';
			}
		});
	}

	$.get(
		datasource,
		{
			id: $(that).attr('link_id'),
			type: $(that).attr('link_type')
		},
		function(data) {
			$(that).html($(data));
			var fbAuth = $(that).find('div.run_fb_auth');
			if (fbAuth.length > 0) {
				$(fbAuth[0]).attr('get_login_status', 'false');
				run_fb_auth($(fbAuth[0]));
			}
		},
		'html'
	);
}

function run_own_result(that) {
    $(that).find("div.left a").click( function() {
    	$(that).find("p.horoscope").css("display", "block");
    	$(that).find("p.influence").css("display", "none");
		$(that).find("div.left").addClass("box-cim");
		$(that).find("div.right").removeClass("box-cim");
    });

    $(that).find("div.right a").click( function() {
    	$(that).find("p.horoscope").css("display", "none");
    	$(that).find("p.influence").css("display", "block");
		$(that).find("div.right").addClass("box-cim");
		$(that).find("div.left").removeClass("box-cim");
    });
}

function run_gallery_share(that) {
    $(that).find('li a').click( function() {
        var target_url = '';
        var target = $(this).attr('class');
        var cikk_url = document.URL + '&pic=' + (parseInt($('.box-galeria .counter').text().split('/')[0])-1);
        var cikk_url_enc = encodeURIComponent(cikk_url);
        var cikk_title = $('.box-galeria .header span').text();
        var cikk_title_enc = encodeURIComponent(cikk_title);
        var wnd_w = 640;
        var wnd_h = 480;

        switch(target) {
        case "iwiw":
           target_url = "http://iwiw.hu/pages/share/share.jsp?u="+cikk_url_enc+"&t="+cikk_title_enc;
           wnd_w = 650;
           wnd_h = 600;
           break;
        case "facebook":
           target_url = "http://www.facebook.com/sharer.php?u="+cikk_url_enc+"&t="+cikk_title_enc;
           break;
        case "twitter":
           target_url = "http://twitter.com/home?status=Ezt olvasom most: "+cikk_title_enc+" "+cikk_url_enc+"";
           wnd_w = 850;
           break;
        default:

        }
        if (target_url!="") {
           open_doc(target_url,wnd_w,wnd_h,target);
        }
        $.modal.close();
        return false;
    });
}

function run_iwiw_layer(that) {
	$(that).click( function() {
		$(this).parents('div.kozosseg').find('.box.astronet').slideToggle();
	});
}

var map = undefined;

function run_horoscope_personal(that)
{
	var $form = $(that).find('form');

	$form.find('input[name=born_place]').change( function() {
		var born_place = $form.find('input[name=born_place]:checked').val()
		show_google_map(born_place == 'abroad');
	});
}

function submit_horoscope_form()
{
	var $form = $('.run_horoscope_personal').find('form');
	if (map != undefined && $form.find('input[name=born_place]:checked').val() == 'abroad') {
		$form.find('input[name=latlong]').val(map.getCenter().lat()+';'+map.getCenter().lng());
	}

	$form.submit();
}

function show_google_map(show)
{
	if (show == undefined) {
		show = true;
	}

	$('#horoszkop_form_magyar').css('display', show ? 'none' : 'block');
	$('#horoszkop_form_terkep').css('display', show ? 'block' : 'none');

	if (show && map == undefined) {
		init_google_map($('#map'));
	}
}

function init_google_map(that)
{
	if (GBrowserIsCompatible()) {

		var url_icon = $(that).find('#url_crosshair').text();

		map = new GMap2(that[0]);

		// pusztavacs, az orszag kozepe :)
		map.setCenter(new GLatLng(47.18013848178129, 19.503607749938965), 7);
		map.addControl(new google.maps.SmallMapControl());
		map.addControl(new google.maps.MapTypeControl());
		map.addControl(new google.maps.OverviewMapControl());

		if (url_icon) {
			map.addOverlay(new google.maps.ScreenOverlay(url_icon, new google.maps.ScreenPoint(0.5,0.5,"fraction","fraction"), new google.maps.ScreenPoint(0.5,0.5,"fraction","fraction"), new google.maps.ScreenSize(50,50)));
		}
	}
}

function run_horoscope_multitabs(that){
	$(that).find('li a[href="javascript:void(0);"]').click( function() {
		$(that).removeClass().addClass( 'tabs ' + $(this).parent().attr('class') );
		return false;
	});
}

function run_scrollbox(that) {
	var $this = $(that).find('.thumbnails');
	var w = 0;
	$.each( $this.find('.scroll-container .scrollable ul li'), function() {
		w += $(this).width()+2;
	});
	$this.find('.scroll-container .scrollable').css('width', w);
	new scroller(
	   $this.find('.scroll-container'),
	   $this.find('.scroll-container .scrollable'),
	   $this.find('a.prev'),
	   $this.find('a.next')
	);
}

function scroller( container, inner, left, right ) {
    this.scrollSize = 20;      // ennyit lép egy kattintásra a scroll célpontja [px]

    // belső változók
    this.scrolling = false;    // most épp scrollozás zajlik?
    this.intervalBtn = 0;      // lenyomva tartott görgető gomb setInterval handlerje
    this.intervalScr = 0;      // a görgető folyamat setInterval handlerje
    this.targetScrollPos = 0;  // a scroll célpontja [px]
    this.containerWidth = 0;  // a befoglaló konténer magassága, ebben fog a tartalom gördülni
    this.minScrollLeft = 0;     // a legkisebb scroll pozíció az aktuális tartalom mellett
    this.currPos = 0;          // a görgetés aktuális pozíciója

    this.scrollContener = null;
    this.scrollInner = null;
    this.scrollButtonLeft = null;
    this.scrollButtonRight = null;

    this.stopScroller = function() {
        if (this.intervalScr) {     // volt görgető időzítő beállítva?
            clearTimeout(this.intervalScr);    // akkor azt most kikapcsolom
        }
        this.targetScrollPos = this.currPos;   // és a görgetési célt az aktuális pozícióra állítom
        return true;
    };

    this.triggerScroller = function() {
        var scroller = this;

        this.currPos = parseInt(this.scrollInner.css('left'));  // itt tart most a görgetés

        if (this.currPos==this.targetScrollPos) {  // ha már nem kell görgetni
            this.stopScroller();
            return false;
        }

        // kell görgetni
        if (Math.abs(this.currPos-this.targetScrollPos)<2) {   // majdnem a végén vagyok a görgetésnek
            this.scrollInner.css('left', this.targetScrollPos );
            this.stopScroller();
            return false;
        }

        var delta = (this.targetScrollPos-this.currPos)/10;
        var elojel = delta > 0 ? 1 : -1;
        if (Math.abs(delta)<2) delta = elojel*2;
        if (Math.abs(delta)>5) delta = elojel*5;
        this.currPos = this.currPos+delta;
        this.scrollInner.css('left', this.currPos );

        // debug
        //document.title = 'Target='+this.targetScrollPos + ' Curr='+this.currPos+' Delta='+delta;

        this.intervalScr = setTimeout( function() { scroller.triggerScroller() }, 10);
    },

    this.scroll = function( lines ) {
        this.targetScrollPos += lines;

        if (this.targetScrollPos < this.minScrollLeft) {
           this.targetScrollPos = this.minScrollLeft;
        }

        if (this.targetScrollPos > 0) {
           this.targetScrollPos = 0;
        }

        // debug
        //document.title = 'Target='+this.targetScrollPos + ' Curr='+this.currPos;
        this.triggerScroller();

        return;
    },

    this.startScrollLeft = function() {
        var scroller = this;
        this.intervalBtn = setInterval( function() { scroller.scroll(scroller.scrollSize); }, 20 );
        return false;
    },

    this.startScrollRight = function() {
        var scroller = this;

        this.intervalBtn = setInterval( function() { scroller.scroll(-scroller.scrollSize); }, 20 );
        return false;
    },

    this.stopScroll = function() {
        clearInterval(this.intervalBtn);
        return false;
    },

    this.init = function( container, inner, left, right ) {
        var scroller = this;

        this.scrollContainer = container;
        this.scrollInner = inner;
        this.scrollLeft = left;
        this.scrollRight = right;

        // a betöltött tartalom alapján kiszámolom, hogy mennyit lehet max görgetni
        this.containerWidth = container.width();
        var innerWidth = inner.width();
        this.minScrollLeft = this.containerWidth-innerWidth;

        inner.css('left',0);
        left.mousedown( function() { return scroller.startScrollLeft(); });
        left.mouseup( function() { return scroller.stopScroll(); });
        left.click( function() { scroller.scroll(scroller.scrollSize); return false; });
        right.mousedown( function() { return scroller.startScrollRight(); });
        right.mouseup( function() { return scroller.stopScroll(); });
        right.click( function() { scroller.scroll(-scroller.scrollSize); return false; });
    }

    this.init(container, inner, left, right);
}

function run_gallery(that) {
    new gallery(that);
}

function gallery(that) {
    var gn = this;
    $that = $(that);
    this.$that = $that;

    this.gid = getUrlParam('gid');
    this.$preview_img = $that.find('.content .preview .pic img');
    this.$preview_text = $that.find('.content .description .text');
    this.$preview_controllers = $that.find('.content .description .page-controllers');
    this.$preview_prev = this.$preview_controllers.find('a.prev');
    this.$preview_next = this.$preview_controllers.find('a.next');
    this.$preview_counter = $that.find('.content .description .counter');
    this.imgs = this.$preview_counter.text().substring(0, this.$preview_counter.text().length-3).split('/');
    //this.imgs_sum = parseInt(this.imgs[1]);
    this.imgs_curr = parseInt(this.imgs[0])-1;

    this.$thumbs_a = $that.find('#thumbnails .scroll-container a');
    this.imgs_sum = this.$thumbs_a.length;
    this.$thumbs_prev = $that.find('#thumbnails a.prev');
    this.$thumbs_next = $that.find('#thumbnails a.next');
    this.$thumbs_scrollable = $that.find('#thumbnails .scroll-container .scrollable');

    this.scrollable_width = 0;
    $.each(this.$thumbs_a, function() {
        gn.scrollable_width += $(this).width()+3;
    });
    this.$thumbs_scrollable.find('ul').css('width', this.scrollable_width);

    new scroller(
        this.$thumbs_scrollable.parent(),
        this.$thumbs_scrollable,
        this.$thumbs_prev,
        this.$thumbs_next
    );

    this.showPicture = function(picNum) {
        $curr_img_a = gn.$thumbs_a.eq(picNum);
        $curr_img = $curr_img_a.find('img');

        gn.$preview_img.attr({
            'src': $curr_img_a.attr('href'),
            'alt': $curr_img_a.attr('title'),
            'title': $curr_img_a.attr('title')
        });

        gn.$preview_text.html( $curr_img.attr('alt') );
        gn.$preview_counter.text( (gn.imgs_curr+1) + ' / ' + gn.imgs_sum + ' kép' );

        gn.imgs_curr = picNum;

        $.get('entry/ajax_getStatistics.php', {type: 'galeria', id: gn.gid });
        if (window.trackStats) {
            window.trackStats();
        }

    }

    this.$preview_prev.click( function() {
        if (gn.imgs_curr<1) {
            gn.imgs_curr = gn.imgs_sum-1;
        } else {
            gn.imgs_curr--;
        }

        gn.showPicture(gn.imgs_curr);

        return false;
    });

    this.$preview_next.click( function() {
        if (gn.imgs_curr>gn.imgs_sum-2) {
            gn.imgs_curr = 0;
        } else {
            gn.imgs_curr++;
        }

        gn.showPicture(gn.imgs_curr);

        return false;
    });

    this.$thumbs_a.click( function() {
        gn.showPicture( gn.$thumbs_a.index(this) );
        return false;
    });
}

function run_show_all_comments(that) {
    $(that).click( function() {
        $(this)
          .parents('.box-content').find('#comments .comment.last').removeClass('last');

        $(this)
          .parents('.more').hide()
          .parents('.box-content')
              .find('.ajanlo').addClass('last')
              .find('#comments .hidden').slideDown('slow')
          .children(':last').addClass('last');

        return false;
    });
}

function run_newcomment(that) {
    $(that).click( function() {
        $('#box-comment').modal({
            overlay:30,
            onShow: function() {
                $('#box-comment form').validate({
                    messages: {
                        username: "Kötelező kitölteni!",
                        checknum: "Kötelező kitölteni!",
                        comment: "Kötelező kitölteni!"
                    }
                });
            }
        });
        return false;
    });
}

function run_change_captcha(that) {
	$(that).click( function() {
		$captcha_img = $(that).parents('.control_value').find('.ellenorzes img');
	    src = $captcha_img.attr('src').split('&rnd=')[0];
	    $captcha_img.attr('src', src+'&rnd='+Math.random());

	    return false;
	});
}

function run_rotate(that) {
	new rotate_scroller(that);
}

function rotate_scroller(that) {
	var rs = this;
	$that = $(that);
	this.$that = $that;
	this.lw = 188;  // gÃ¶rgethetÅ lista elemek szÃ©lessÃ©ge
	this.$abc_a = $that.find('#lexikon-abc a');
	this.$scrollable = $that.find('.scrollable');
	this.$scrollable_list = $that.find('.scrollable').find('.lexikon-lista');
	this.$scrollable_title = this.$scrollable_list.find('.lista-header');
	this.$scroll_left = $that.find('a.prev');
	this.$scroll_right = $that.find('a.next');
	this.animating = false;

	this.$scrollable.css('width', this.$scrollable_list.length * this.lw);

	this.$abc_a.click( function() {
		rs.scrollListTo( rs.$abc_a.index(this) );

		return false;
	});

	this.scrollListTo = function(idx) {
		if (rs.animating) {
			return false;
		}
        rs.animating = true;

        rs.$that.find('#lexikon-abc a.active').removeClass('active');
        if (idx>rs.$scrollable_list.length-4) {
        	rs.$abc_a.eq( 0 ).addClass('active');
        } else {
            rs.$abc_a.eq(idx).addClass('active');
        }

        rs.$scrollable_list.find('.active').removeClass('active');
        rs.$scrollable_title.eq(idx+1).addClass('active');

        curr = parseInt(rs.$scrollable.css('left'));
        target = -(idx+0)*rs.lw;
        if (Math.abs(curr-target)>rs.lw) {
        	time = 1000;
        } else {
        	time = 400;
        }
        rs.$scrollable.animate({left: target+"px"}, time, 'linear', function() {
        	rs.animating = false;
        });
	}

	this.$scroll_left.click( function() {
		curr = rs.$abc_a.index( rs.$that.find('#lexikon-abc a.active') );
        if (curr == 0) {
            curr = rs.$scrollable_list.length-3;
            rs.$scrollable.css('left', -curr * rs.lw);
        }
		rs.scrollListTo( curr-1 );
		return false;
	});

	this.$scroll_right.click( function() {
        curr = rs.$abc_a.index( rs.$that.find('#lexikon-abc a.active') );
        if (curr == (rs.$scrollable_list.length-3)) {
        	rs.$scrollable.css('left', 0);
        	curr = 0;
        } else {
        	if (curr == 0 && parseInt(rs.$scrollable.css('left'))<rs.lw ) {
        		rs.$scrollable.css('left', 0);
                curr = 0;
        	}
        }
        rs.scrollListTo( curr+1 );
        return false;
    });
}

/* a run_send hívja */
function send_form(that) {
	/* cikk kuldese + form validalasa */
	var $that = $('#box-send');
	var old_form;

	var ajaxSubmit = function() {
        $.post( 'entry/ajax_postSendContent.php', {
            to: $that.find('#target_email').val(),
            toName: $that.find('#target_name').val(),
            sender: $that.find('#sender_email').val(),
            senderName: $that.find('#sender_name').val(),
            message: $that.find('#message').val(),
            hidden: $that.find('input:hidden').serialize()
        }, function(data, textStatus) {
            if (textStatus=='success') {
                old_form = $that.find('.content').replaceWith( '<div id="form-replace">'+data+'</div>' );
                $that.find('#form-replace').append('<input class="ok" type="submit" value="OK" />');

                $that.find('input.ok').click( function() {
                    $.modal.close();
                    $that.find('#form-replace').replaceWith(old_form);
		            old_form = null;

		            return false;
                });
            }
        });

        return false;
    }

    $that.find('form').validate({
        submitHandler: function(form) {
            ajaxSubmit();
        },
        messages: {
            target_email: {
                required: "Kötelező kitölteni!",
                email: "Hibás cím, ellenőrizd!"
            },
            sender_name: "Kötelező kitölteni!",
            sender_email: {
                email: "Hibás cím, ellenőrizd!"
            }
        }
    });
}

/*
  annyival tobb mint a send_form, hogy az elkuldendo url-t a html forrasbol banyassza ki
*/
function send_daily_phrase(that) {
    $('#box-send').find('form input[name=content_url]').val($(that).find('div.url').text());

	return send_form();
}

function run_share_links(that) {
	$(that).find('li a').click( function() {
		var target_url = '';
		var target = $(this).parent().attr('class').substr(5);
		var cikk_url = document.URL;
		var cikk_url_enc = encodeURIComponent(cikk_url);
		var cikk_title = $('#box-share h2').text();
		var cikk_title_enc = encodeURIComponent(cikk_title);
		var wmd_w = 640;
		var wnd_h = 480;

		switch(target) {
		case "favor":
		   bookmarkSite(cikk_title, cikk_url);
		   break;
		case "iwiw":
		   target_url = "http://iwiw.hu/pages/share/share.jsp?u="+cikk_url_enc+"&t="+cikk_title_enc;
		   wnd_w = 650;
		   wnd_h = 600;
		   break;
		case "at_fa":
			// facebook
		   target_url = "http://www.facebook.com/sharer.php?u="+cikk_url_enc+"&t="+cikk_title_enc;
		   break;
		case "googl":
		   target_url = "http://www.google.com/bookmarks/mark?op=add&bkmk="+cikk_url_enc+"&title="+cikk_title_enc;
		   break;
		case "wlive":
		   target_url = "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url="+cikk_url_enc+"&title="+cikk_title_enc+"&top=1";
		   break;
		case "myspc":
		   target_url = "http://www.myspace.com/Modules/PostTo/Pages/?u="+cikk_url_enc+"&t="+cikk_title_enc+"&c=";
		   break;
		case "yahoo":
		   var pre_cod = "http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u="+cikk_url_enc+"&t="+cikk_title_enc;
		   target_url = "https://login.yahoo.com/config/login?src=bmk2&.intl=us&.done="+URLEncode(pre_cod);
		break;
		   case "myweb":
		   var pre_cod = "http://myweb.yahoo.com/myresults/bookmarklet?ei=UTF-8&u="+cikk_url_enc+"&t="+cikk_title_enc;
		   target_url = "https://login.yahoo.com/config/login?.intl=us&.src=smw&.pd=smw_ver%3d1&.done="+URLEncode(pre_cod);;
		   break;

		default:

		}
		if (target_url!="") {
		   open_doc(target_url,wnd_w,wnd_h,target);
		}
		$.modal.close();
		return false;
	});
}


function run_share(that) {
    $(that).click( function() {
        $('#box-share').modal({overlay:30});
        return false;
    });
}

function run_send(that) {
    $(that).click( function() {

        $('#box-send').modal({
        	overlay:30,
        	onShow: function() { send_form(); }
        });
        return false;
    });
}

function run_send_daily_phrase(that) {
    $(that).find('a').click( function() {

        $('#box-send').modal({
        	overlay:30,
        	onShow: function() { send_daily_phrase(that); }
        });
        return false;
    });
}

function run_login(that) {
	$(that).click( function() {
		$('#box-login').modal({overlay:30});
		return false;
	});
}

function run_bigger(that) {
	new article_letter_size(that,+2);
}

function run_smaller(that) {
    new article_letter_size(that,-2);
}

function article_letter_size(that, s) {
	var size = s;
	$(that).click( function() {
		currSize = parseInt($('body .article').css('font-size'));
		if ( (currSize<20 && size>0) || (currSize>10 && size<0) ) {
		  $('body .article').css('font-size',currSize+size);
		}

		return false;
	});
}

function run_expertdata(that) {
	new expertdata(that);
}

function expertdata(that) {
	var maxLength = 500; // az Ã¼zenet maximÃ¡lis hossza [karakter]

	var $that = $(that);
	var $buttons = $that.find('.box-content .ajanlo .buttons a');
	var $logged_in = $that.hasClass('user_loggedin');
	var $textarea = $that.find('.expert-ask form textarea');
	var $textcounter = $that.find('.expert-ask .header .counter');


	$buttons.click( function() {
		if ($buttons.index(this) == 0) {
			$that
                .removeClass('expertdata-login')
                .removeClass('expertdata-ask')
                .addClass('expertdata-resume');
		} else {
			if ($logged_in) {
				$that
	                .removeClass('expertdata-login')
	                .removeClass('expertdata-resume')
	                .addClass('expertdata-ask');
			} else {
				$that
                    .removeClass('expertdata-ask')
                    .removeClass('expertdata-resume')
                    .addClass('expertdata-login');
			}
		}
		return false;
	});

    $that.find('.header .more select').change( function() {
        var link = $(this).children().eq(this.selectedIndex).val();
        window.location.href = link;
    });

    $that.find('.close').click( function() {
		$that
	        .removeClass('expertdata-ask')
	        .removeClass('expertdata-resume')
	        .removeClass('expertdata-login');

	    return false;
	});

	$textarea.keyup( function() {
        var l = maxLength - $(this).val().length;
        if (l<0) {
            $(this).val( $(this).val().substring(0, maxLength) );
            l=0;
            $textcounter.text( l );
            return false;
        }
        $textcounter.text( l );
    });

    $textcounter.text( maxLength - $textarea.val().length );
}

function run_love_horoscope(that) {
	new love_horoscope(that);
}

function love_horoscope(that) {
	var $buttons = $(that).find('.box-content ul li a');
    var $target  = $(that).find('.box-content .info');

    $buttons.mouseover( function() {
        $target.html( '<a href="' + $(this).attr('href') + '">' + $(this).attr('title') + '</a>' + $(this).text() );
        $buttons.removeClass('active');
        $(this).addClass('active');
    });
}

function run_gallery_offer(that) {
	new gallery_offer(that);
}

function gallery_offer(that) {
	var $that = $(that);
	var $preview_img = $that.find('.galeria-content .preview .pic a img');
	//var $preview_title = $that.find('.galeria-content .preview .title');
	var $preview_h2_a = $that.find('.galeria-content .preview h2 a');
	var $preview_p = $that.find('.galeria-content .preview p');
	var $preview_show_a = $that.find('.galeria-content .preview .more a');
	var $scrollable = $that.find('.galeria-content #thumbnails .scrollable');
	var $thumbs_a = $that.find('.galeria-content #thumbnails .scrollable ul li a');
	var $thumbs_prev = $that.find('.galeria-content #thumbnails .scroll-controllers a.prev');
	var $thumbs_next = $that.find('.galeria-content #thumbnails .scroll-controllers a.next');
	var animating = false;

	$scrollable.find('ul').css('width', $thumbs_a.length*73);

	if ($scrollable.css('left')=='auto') {
		$scrollable.css('left', 10);
	}

	$thumbs_next.click( function() {
		if (animating) {
			return false;
		}
		if ( parseInt($scrollable.css('left')) > -($thumbs_a.length-7)*73 ) {
			animating = true;
			$scrollable.animate( {left: "-=73px"}, "normal", "linear", function() {
				animating = false;
			} );
		}
		return false;
	});

	$thumbs_prev.click( function() {
        if (animating) {
            return false;
        }
        if ( parseInt($scrollable.css('left'))<0 ) {
	        animating = true;
	        $scrollable.animate( {left: "+=73px"}, "normal", "linear", function() {
                animating = false;
            } );
        }
        return false;
    });

    $thumbs_a.click( function() {
    	$preview_img.attr({
    		src: $(this).attr('href'),
    		alt: $(this).find('img').attr('title')
    	}).parent().attr({
    		href: $(this).attr('title')
    	});
    	$preview_h2_a.attr('href', $(this).attr('title')).text($(this).find('img').attr('title'));
    	$preview_p.html($(this).find('img').attr('alt'));
    	$preview_show_a.attr('href', $(this).attr('title'));
    	return false;
    });
}

function run_bigpicture_slider(that) {
	new bigpicture_slider(that);
}

function bigpicture_slider(that) {
	var $bigpics = $(that).find('a.bigpic');
	var $links = $(that).find('.ajanlo');
	var t;
	var timeout = 4000;

	$links.hover( function() {
		clearTimeout(t);
		$bigpics.addClass('hidden');
		$bigpics.eq( $links.index(this) ).removeClass('hidden');
	},
	function() {
		t = setTimeout(function() { this.nextpic(); }, timeout);
	});

	$bigpics.hover( function() {
		clearTimeout(t);
	},
	function() {
		t = setTimeout(function() { this.nextpic(); }, timeout);
	});

	nextpic = function() {
		next = $bigpics.index( $bigpics.not('.hidden') )+1;
		if (next == $bigpics.length) {
			next = 0
		}

		$bigpics.addClass('hidden');
        $bigpics.eq( next ).removeClass('hidden');

        t = setTimeout(function() { this.nextpic(); }, timeout);
	}

	t = setTimeout(function() { this.nextpic(); }, timeout);
}

function run_tabs(that) {
	new changeTabs(that);
}

// horoszkopnal van a bovebben is
function run_horoscope_tabs(that) {
	run_tabs(that);

	var $tabs = $(that).find('.header .tabs a');
	var $pages = $(that).find('.box-content .ajanlo');
	var $more = $(that).find('.box-content .horoscope-left .more a');
	var $extended = $(that).find('.box-content .ajanlo.extended');

	$more.click( function() {
		$pages.addClass('hidden');
		$extended.removeClass('hidden');
		$tabs.parent().removeClass('active');

		return false;
	});
}

function changeTabs(that) {
	var $tabs = $(that).find('.header .tabs a');
	var $pages = $(that).find('.box-content .ajanlo');

	$tabs.click( function() {
		$pages.addClass('hidden');
		$pages.eq( $tabs.index(this) ).removeClass('hidden');
		$tabs.parent().removeClass('active');
		$(this).parent().addClass('active');

		return false;
	});
}

function run_inputfield(that) {
    new toggleInputField(that);
}

function toggleInputField( that ) {
    var toggleInputField = this;
    this.field = that;
    this.emptyFieldVal = $(that).val();

    $(that)
        .focus( function() {
            if ($(toggleInputField.field).hasClass('empty')) {
                $(toggleInputField.field).removeClass('empty').val('');
            }
        })
        .blur( function() {
            if ($(toggleInputField.field).val()=='') {
                $(toggleInputField.field).addClass('empty').val(toggleInputField.emptyFieldVal);
            }
        });
}


/* Nano Templates (Tomasz Mazur, Jacek Becela) */
(function($){
  $.nano = function(template, data){
    return template.replace(/\{([\w\.]*)}/g, function(str, key){
      var keys = key.split("."), value = data[keys.shift()]
      $.each(keys, function(){ value = value[this] })
      return value
    })
  }
})(jQuery);

/*
 *
 *  main
 *
 *
 */

function open_doc(cime,szelesseg,magassag,ablak){
    if (!szelesseg) szelesseg=500;
    if (!magassag) magassag=535;
    if (typeof usrwindow != 'undefined'){
    if (!usrwindow.closed){usrwindow.close();}}
        usrwindow=window.open(cime, ablak, 'top=0,left=0,resizable=no,hotkeys=yes,width='+szelesseg+',height='+magassag);
}

function open_doc_scroll(cime,szelesseg,magassag,ablak){
    if (!szelesseg) szelesseg=516;
    if (!magassag) magassag=535;
    if (typeof usrwindow != 'undefined'){
    if (!usrwindow.closed){usrwindow.close();}}
        usrwindow=window.open(cime, ablak, 'toolbar=no,scrollbars=yes,menubar=no,top=0,left=0,resizable=yes,hotkeys=yes,width='+szelesseg+',height='+magassag);
}

function URLEncode(url) //Function to encode URL.
{
    var SAFECHARS = "0123456789" + // Numeric
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
    "abcdefghijklmnopqrstuvwxyz" +
    "-_.!~*'()"; // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var plaintext = url;
    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
        var ch = plaintext.charAt(i);
        if (ch == " ") {
            encoded += "+"; // x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
           encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    }
    return encoded;
};

function bookmarkSite(title,url){
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

function getClickTarget(ev) {
    return {top:ev.pageY, left:ev.pageX};
}

function stripScripts(markup) {
  return markup.replace(/<script[^>]*?>[\s\S]*?<\/script>/gi, '');
}

function run_movehtml(that) {
    copyhtml(that, false);
}

function run_copyhtml(that) {
    copyhtml(that, true);
}

function copyhtml(that, clone) {
    this.target = $(that);
    this.sources = $( this.target.text() );

    if (this.sources.length==0) {
        this.target.remove();
    } else {
        var $source = $(this.sources[0]);
        if (this.target.length) {
            this.target.html( stripScripts($source.html()) );
            this.target.attr('class', $source.attr('class') );
            if (!clone) {
                $source.remove();
            }
        }
    }
}

function getUrlParam( name ) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
}

function run( runjs_tag ) {
    runjs_each($('.runjs.'+runjs_tag));
}

function executeRunjs( startElement ) {
    runjs_each($(startElement+' .runjs'));
}

function runjs_each( objlist ) {
    jQuery.each(objlist, function() {
        var className = $(this).attr('class');
        var currObj = this;
        if (/\brunning\b/.test(className)==false) {
            var classes = className.split(' ');
            var thisobj = $(this);
            jQuery.each(classes, function() {
                if (this.substring(0,4)=='run_') {
                    if (jQuery.isFunction( window[this] )) {
                      window[this](thisobj);
	                    $(currObj).addClass('running');
                    }
                    else {
                      $(currObj).addClass('notfound');
                    }
              }
            });
        }
     });
}

$(document).ready( function() {
    executeRunjs( 'body' );
});
