(function($){
    
    var win =  (navigator.appVersion.indexOf("Win")!=-1) ? 1 : 0;
    
    function popup(obj){
        
        var def = {
                url : 'http://www.google.com',
                name: 'mywindow',
                setup: {
                    location: 0,
                    status: 1,
                    scrollbars: 0,
                    width: 200,
                    height: 200,
                    pos: {
                        x: 200,
                        y: 200
                    }
                }
            },
            obj = obj || {},
            opts = $.extend(true, def, obj);
        
        var mywindow = window.open(opts.url, opts.name, 'location='+opts.setup.location+',status='+opts.setup.status +',scrollbars='+opts.setup.scrollbars+',width='+opts.setup.width+',height='+opts.setup.height);
        mywindow.moveTo(opts.setup.pos.x, opts.setup.pos.y);
        mywindow.focus();
    }

    
    window.video = {
        silverlight : (function(){
            var browser = navigator.appName; // Get browser
            var silverlightInstalled = false;
            
            if (browser == 'Microsoft Internet Explorer') {
                try {
                    var slControl = new ActiveXObject('AgControl.AgControl');
                    silverlightInstalled = true;
                } 
                catch (e) {
                    // Error. Silverlight not installed.
                }
            }
            else {
                // Handle Netscape, FireFox, Google chrome etc
                try {
                    if (navigator.plugins["Silverlight Plug-In"]) {
                        silverlightInstalled = true;
                    }
                } 
                catch (e) {
                    
                    // Error. Silverlight not installed.
                }
            }
            
            return silverlightInstalled;
        })(),
        wmp: (function(){
            var wmpInstalled = false;
            wmpObj = false;
            
            if (navigator.plugins && navigator.plugins.length) {
                for (var i = 0; i < navigator.plugins.length; i++) {
                    var plugin = navigator.plugins[i];
                    if (plugin.name.indexOf("Windows Media Player") > -1) {
                        wmpInstalled = true;
                    }
                }
            }
            else {
                execScript('on error resume next: wmpObj = IsObject(CreateObject("MediaPlayer.MediaPlayer.1"))', 'VBScript');
                wmpInstalled = wmpObj;
            }
            return wmpInstalled;
        })(),
        play: function(streamURL){
            
            var $playInWMP = $('#playInWMP'),
                $installSilverlight = $('#installSilverlight'),
                $installWMP = $('#installWMP');
                
            
            function playerJW(){
                var cnt = document.getElementById("mediaspace"),
                    src = K_APP_PATH + 'static/js/lib/wmvplayer/wmvplayer.xaml',
                    cfg = {
                        file: streamURL,
                        width: '658',
                        height: '370'
                    };
                    window.ply = new jeroenwijering.Player(cnt,src,cfg);
            }
            
            function playerWMP(){
                var wmp = generatePlayerCode(streamURL, 659, 370);
                document.getElementById('mediaspace').innerHTML = wmp;
            }
            
            if(this.silverlight){
                playerJW();
                $playInWMP.remove();
                $installSilverlight.remove();
            } else {
                if(this.wmp){
                    $playInWMP.show().find('a').click(function(e){
                        e.preventDefault();
                        playerWMP();
                    });
                }
                $installSilverlight.show().find('a').click(function(e){
                    e.preventDefault();
                    Silverlight.getSilverlight("1.0");
                });    
            }
        }
    };
    
    var debug = true;
    
	function noJs() {
		$('body').removeClass('noJs');
	}
	
	function nicknameTooltip() {
		$('div.nicknameHelpRow a').tooltip({
			cont: "Olyan becenevet válassz, ami egyedi, jellemző rád, de nem tartalmazza a személyes adataidat.<br /> Ne szerepeljen benne a vezetékneved, az e-mailcímed, telefonszámod, stb. Legyen 6-20 karakter hosszú és csak betűket, számokat tartalmazzon.",
			pushX: 5,
			pushY: 5,
			fade: 300,
            hook: 'right-top',
			trigger: 'click'
		});
	}
	
    function contentColumns(){
		var $wideNewsList = $('.wideNewsList');
            
        if ($wideNewsList.length) {
			$.each($wideNewsList.find('li'), function() {
				$(this).find('.newsLeft, .newsRight').equalHeights();
			});
        }
    }
    
    function showSubMenu(){
        var $mainMenu = $('.mainMenu > li');
        if ($mainMenu.length) {
            $mainMenu.bind('mouseenter mouseleave', function(){
                $(this).toggleClass('hovered');
            });
        }
    }
    
    function newsRotator(){
        function verticalAlign(){
            $.each($('.newsRotator .news li div'), function(k, v){
                var liHeight  = $( this ).parent().height()
                    divHeight = $( this ).height();

                $( this ).css( {
                    'padding-top' : Math.round( ( liHeight - divHeight ) / 2 ) - 3
                } );
            });
        }
        $('.newsRotator .news li').find('img,p').show();
        verticalAlign();
        
        
        var $news = $('.newsRotator .news li');
        var timer = null;
        var delaySeconds = 6000;
        
        
        if ($news.length) {            
            var active = 0;
            $news.eq(active).addClass('active');
            var $newsPic = $('<ul />').appendTo('.newsPic');
            $news.each(function(){
                var $t = $(this), $pic = $t.find('img'), $lead = $t.find('p'), $li = $('<li />');
                $newsPic.append($li.append($pic).append($lead));
            });
            var $newsPicList = $newsPic.find('li');
            $newsPicList.eq(active).addClass('active');
            
            $news.mouseover(function(){
                var $t = $(this);
                active = $news.index($t);
                showActiveContent();
                clearTimeout(timer);
                timer = null;
            }).mouseout(function(){
                timer = setTimeout(autoPlay, delaySeconds);
            });
            
            function showActiveContent(){
                if (active == $newsPicList.length) 
                    active = 0;
                $news.eq(active).addClass('active').siblings().removeClass('active');
                $newsPicList.removeClass('active').eq(active).fadeIn(300).siblings().fadeOut(300);
            }
            
            function autoPlay(){
                active++;
                showActiveContent();
                timer = setTimeout(autoPlay, delaySeconds);
            }
            timer = setTimeout(autoPlay, delaySeconds);
        }
    }
    
    function relatedGalleriesItems(){
        $('div.relatedGalleries div.text div.pictures a:nth-child(4)').addClass('fourth');
    }
    
    function showPollResults(){
        function calculatePercentage(){
            var $questions = $('div.poll.results .answer');
            $.each($questions, function(k, v){
                var $t = $(this);
                $t.find('.percentLine').width($t.find('.percent').text());
            });
        }
		
		var $showPollResults = $('a.showPollResults');
        
        $showPollResults.click(function(e){
            $('div.poll.results').toggle();
            $(this).prev($('div.form')).remove();
            $(this).remove();
            e.preventDefault();
        });
        
        $('input.pollSubmit').click(function(e){
            e.preventDefault();
        });
        
        $('form.voteForm').submit(function(e){
            var $t = $(this);
            var $parentDiv = $t.parents('div.form').find('div.formRow').eq(0);
            var ajaxUrl = $t.attr('action');
            var selectedItemValue = $t.find('input:checked').val() || false;

            $.ajax({
                type: "POST",
                url: ajaxUrl,
                data: $t.serialize(),
                success: function(response){
                    if (!response.error) {
                        if (response.link) {
                            location.href = response.link;
                        }
                        else {
                            var animSpeed = 400;
                            var $pollBox = $('div.poll.results');
                            $t.fadeOut(animSpeed, function(){
                                $pollBox.fadeOut(animSpeed, function(){
                                    $(this).html(response.item).fadeIn(animSpeed);
                                });
                                $t.remove();
                                $showPollResults.remove();
                            });
                        }
                    }
                    else {
                        var r = $(response.item),
                            errors = $('<ul class="formError"></ul>');
                        r.find('ul.formError').each(function(){
                            errors.append($(this).children());
                        });
                        r.find('div.fbChk').after(errors);
                        $t.html(r.html());
                        $t.find('input:submit').click(function(e){
                            e.preventDefault();
                        }).replaceSubmitBtn();
                    }
                }
            });
			e.preventDefault();
        });       
    }
    
    function modalLayer(){
        if ($('div.overlay').length) {
            var animSpeed   = 200,
                $layer      = $('div.overlay'),
                $layerCont  = $('div.overlayCont'),
                $fbLoginBox = $('#faceBookLoginBox'),
                flag        = null;

            function showLayer() {
                $layerCont.css( {
                    'top': ( ( $( window ).height() - $layerCont.outerHeight() ) / 2 + $( window ).scrollTop() ),
                    'left': ( ( $( window ).width() - $layerCont.outerWidth() ) / 2 + $( window ).scrollLeft() )
                });
                $layer.css({
                    'width': $(document).width(),
                    'height': $(document).height()
                })
                if ($fbLoginBox.length) {
                    if (flag == 'noFacebookLogin') {
                        $fbLoginBox.hide();
                    }
                    else {
                        $fbLoginBox.show();
                    }
                }

                $layer.fadeIn(animSpeed);
                $layerCont.fadeIn(animSpeed);
				$('form#loginForm input:submit').replaceSubmitBtn();
                
                if ( $layer.hasClass( 'fadeOut' ) ) {
                    setTimeout( function() {
                        hideLayer();
                    }, 2000 );
                }
            }
            
            function hideLayer(){
                $layer.fadeOut(animSpeed);
                $layerCont.fadeOut(animSpeed);
            }
            
            $('.showLayer').click(function(e){
                e.preventDefault();

                if(this.rel == 'noFacebookLogin'){
                    flag = 'noFacebookLogin';
                } else {
                    flag = 'facebookLogin';
                }
                showLayer();
            });
            $('.hideLayer').click(function(e){
                hideLayer();
                e.preventDefault();
            });
            $(document).keyup(function(e){
                if (e.keyCode == 27) {
                    hideLayer();
                }
            });
            if ($('.showModal').length) {
                showLayer();
            }
            
            $(window).resize(function(){
                $layer.css({
                    'width': $(document).width(),
                    'height': $(document).height()
                });
                $layerCont.css( {
                    'top': ( ( $( window ).height() - $layerCont.outerHeight() ) / 2 + $( window ).scrollTop() ),
                    'left': ( ( $( window ).width() - $layerCont.outerWidth() ) / 2 + $( window ).scrollLeft() )
                });
            });
        }
    }
    
    function setGalleryThumbnailsContainerWidth(){
        var $scrollable = $('.galleryBox .scrollable'),
            $items = $scrollable.find('a'),
            itemsLength = $items.length;
        $scrollable.width(itemsLength * ($items.outerWidth() + parseInt($items.css('margin-right'))));
    }
    
    function searchField(){
        $('form.searchForm').submit(function(e){
            var $field = $(this).find('input:text');
            var $q = $.trim($field.val());
            if ($q.length > 0) {
                window.top.location = K_QUERY_PATH + 'kereses/' + $q;
            }
            else {
                $field.addClass('error');
                $field.val('Keresés');
            }
            e.preventDefault();
        });
    }
    
    function jumpToComment(){
        var $link           = $('#jumpToCommentForm'),
            $showComments   = $('#showComments'),
            $commentList    = $('.commentList');
            
        if ($link.length) {
            $link.click(function(e){
                e.preventDefault();
                location.hash = $(this).attr('href');
                $('#comment_data').focus().animate({
                    opacity: 0.5
                }, 250, function(){
                    $(this).animate({
                        opacity: 1
                    }, 250);
                });
            });
            
            var lh      = location.hash,
                hasId   = lh.indexOf('#comment-') > -1;
            
            $showComments.click(function(e){
                e.preventDefault();

                var content_data = $( this ).attr( 'href' )
                                            .replace( '#', '' )
                                            .split( '-' );

                $.ajax({
                    url: K_PROCESS_PATH + 'comment/comment/process',
                    type: 'GET',
                    data: {
                        content_id: content_data[1],
                        content_type: content_data[0]
                    },
                    dataType: 'json',
                    success: function(response){
                        $commentList.html( response.item );
                        $('.showCommentsBox').remove();
                        if (hasId) {
                            location.hash = lh;
                        }
                    }
                });
            });
            
            if(hasId && !$(lh).length){
                $showComments.trigger('click');
            }
            
            if($('#commentForm .formError').length){
                location.hash = '#commentForm';
            }
            
            $('.saveCommentForm').click(function(e){
                saveFormValuesToCookie('commentForm','commentFormValues');
            });
            
        }
    }
    
    function saveFormValuesToCookie(formId,cookieName){
        var $form = $('#'+formId);
        if($form.length){
            var $inputs = $('#'+formId).find('input, select, textarea'),
                values = {};
            values.inputs = [];
            $inputs.each(function(index){
                var self = this,
                    $t = $(self);
                if (!values.inputs[this.name]) {
                    values.inputs[this.name] = [];
                }
                values.inputs[this.name].push({
                    id: this.id,
                    name: this.name,
                    tag: this.nodeName.toLowerCase(),
                    type: this.type,
                    checked: (this.nodeName == 'INPUT') ? this.checked : false,
                    value: (function(){
                        var value;
                        if(self.nodeName == 'SELECT'){
                            value = [];
                            if(!self.multiple){
                                var opt = $t.find('option:selected')[0];
                                value[0] = opt.value || opt.innerHTML;
                            } else {
                                $t.find('option:selected').each(function(){
                                    value.push(this.value || this.innerHTML);
                                });
                            }
                        } else {
                            value = self.value
                        }
                        return value;
                    })()
                });
            });
            values = $.stringifyJSON(values);
            $.cookie(cookieName, values);
        }
    }
    
    function restoreFormValuesFromCookie(formId,cookieName){
        var $form = $('#'+formId),
            formValues = $.cookie(cookieName);
        if ($form.length && formValues) {
            formInputValues = $.parseJSON(formValues);
            for (inputGroup in formInputValues.inputs) {
                var inputGroups = formInputValues.inputs[inputGroup], len = inputGroups.length;
                for (var i = 0; i < len; i++) {
                    var inp = inputGroups[i];
                    if (inp.checked) {
                        $('[name="' + inp.name + '"]').eq(i).attr('checked', 1);
                    }
                    else {
                        if (inp.tag == 'select') {
                            if (inp.value.length) {
                                $('select[name="' + inp.name + '"] option').filter(function(){
                                    var optVal = this.value || this.innerHTML;
                                    return $.inArray(optVal, inp.value) > -1;
                                }).attr('selected', 'selected');
                            }
                        }
                        else {
                            $('[name="' + inp.name + '"]').eq(i).val(inp.value);
                        }
                    }
                }
            }
            $.cookie(cookieName, null);
        }
    }
	
	function setSearchWidthHeight() {
		$.each($('.galleryList div p'), function() {
			var $t = $(this);
			$t.width($t.find('img').width());
		});
		$('.articleList.searchResultsList li').last().css({'border-bottom' : 'none', 'padding-bottom' : '0'});
	}
	
	function setCanvasSize(){
		if ($('body.fbml').length) {
			var pHeight = $('div#pContainer').outerHeight();
		    FB.Canvas.setSize({
		        width: 520,
		        height: pHeight
		    });	
		}
	}

    function setTempBodyLink() {
        var $body = $('body'),
            newBodyImg = $body.css('background-image').replace('.jpg")', '_new.jpg")');
         if (!$body.is('.torchrunning')) {
             //$body.prepend($('<a href="' + K_QUERY_PATH + 'samsung-es-a-sport/faklyafutas2012" class="tempBodyLink"></a>').height($(document).height()));
             $body.prepend($('<a href="http://www.samsung.com/hu/smarttvapps/" target="_blank" class="tempBodyLink"></a>').height($(document).height()));
             $('div.contBox').addClass('getBgHarder');
         }
    }
    
    function setTempSamsungSportLogo() {
        var $logo = $('.pHeader img.title');
        if($logo.attr('src').indexOf('title_samsungsport-hu.png') > -1){
            $logo.attr('src',K_APP_PATH + 'static/img/title_samsungsport-hu-white.png')
        }
    }
    
    function niceForm(){
        
        var $nfContainer = $('.torchrunning .content');
        
        $nfContainer.find('input:not(:checkbox,:radio), textarea, select').each(function(){
            var $t = $(this),
                $row = $t.parents('.formRow'),
                $label = $row.find('.labelBox label'),
                multiInput = $row.find('input, select, textarea').length;
            
            if (multiInput < 2) {
                $label.hide()
                if($t.is(':text') || $t.is('textarea')){
                    $t.clearInputs($label.html());
                }
                if($t.is('select')){
                    $t.find('option[value=""]').html($label.html());
                    $t.trigger('change');
                }
            }
        });
        
        $nfContainer.find('input[type=checkbox]:not(.fixed)').each(function(){
            
            var t = $(this),
                p = t.wrap($('<div>').addClass('customCheckBox')).parent(),
                l = $('label[for=' + t.attr('id') + ']'),
                a = $('input[name='+t.attr('name')+']');
                
            t.addClass('fixed').css({
                opacity: 0
            });
            
            if (t.attr('checked')) p.addClass('checked');
            
            t.click(function(){
                if (!t.attr('checked')) {
                    if (t.hasClass('allChecked')){
                        return false;
                    } 
                    else {
                        a.filter('.allChecked').attr('checked', 0).parent().removeClass('checked');
                        t.attr('checked', 0).parent().removeClass('checked');
                        if (a.filter(':checked').not('.allChecked').length == 0 && a.filter('.allChecked').length){
                            a.filter('.allChecked').attr('checked', 1).parent().addClass('checked');
                        }
                    }
                }
                else {
                    if (t.hasClass('allChecked')){
                        t.attr('checked', 1).parent().addClass('checked');
                        a.not('.allChecked').attr('checked', 0).parent().removeClass('checked');
                    } 
                    else {
                        t.attr('checked', 1).parent().addClass('checked');
                        if (a.filter(':checked').not('.allChecked').length == a.length-1){
                            a.attr('checked', 0).parent().removeClass('checked');
                            a.filter('.allChecked').attr('checked', 1).parent().addClass('checked');
                        }
                        else {
                            a.filter('.allChecked').attr('checked', 0).parent().removeClass('checked');
                        }
                            
                    }
                }
            });
            
            p.add(l).hover(
                function(){
                    p.addClass('hovered');
                },
                function(){
                    p.removeClass('hovered');
                });
        });
        
        $nfContainer.find('input[type=radio]:not(.fixed)').each(function(){
            var t = $(this), p = t.wrap($('<div>').addClass('customRadioBox')).parent(), l = $('label[for=' + t.attr('id') + ']'), s = $('input[name='+t.attr('name')+']').not(t);
            t.addClass('fixed').css({
                opacity: 0
            });
            if (t.attr('checked')) p.addClass('checked');
            t.click(function(){
                if (t.attr('checked')) {
                    s.each(function(){
                        $(this).parent().removeClass('checked');
                        $('label[for=' + $(this).attr('id') + ']').removeClass('bold');
                    });
                    p.addClass('checked');
                    l.addClass('bold');
                }
            });
            p.add(l).hover(function(){
                p.addClass('hovered');
            }, function(){
                p.removeClass('hovered');
            });
            if (t.attr('checked')) {
                s.each(function(){
                    $(this).parent().removeClass('checked');
                    $('label[for=' + $(this).attr('id') + ']').removeClass('bold');
                });
                p.addClass('checked');
                l.addClass('bold');
            }
        });
        
        $nfContainer.find('input[type=text]:not(.fixed)').each(function(){
            var t = $(this), p = t.wrap($('<div>').addClass('customText')).parent(), l = $('label[for=' + t.attr('id') + ']'), s = $('input[name='+t.attr('name')+']').not(t);
            t.focus(function(){
                p.addClass('hovered');
            }).blur(function(){
                p.removeClass('hovered');
            });
            p.add(l).hover(function(){
                p.addClass('hovered');
            }, function(){
                p.removeClass('hovered');
            });
            
        });
        
        $nfContainer.find('select:not(.fixed)').each(function(){
            var t = $(this), 
                p = t.wrap($('<div>').addClass('customSelectBox')).parent().css({width:t.width()}),
                b = $('<a href="#" class="btn"><em></em></a>').appendTo(p),
                s = $('<span>'+t.find('option').filter(':selected').html()+'</span>').prependTo(b),
                d = $('<ul class="opts"></ul>').hide(),
                l = $('label[for=' + t.attr('id') + ']');
            
            if(t.is('#nominee_student')){
                t.change(function(){
                    if(this.value=='yes'){
                        $('#nominee_school').enable();
                        $('.schoolNameRow').show();
                    } else {
                        $('#nominee_school').disable();
                        $('.schoolNameRow').hide();
                    }
                });
            }
            
            if (t.hasClass('groupSelectStyle')) {
                d.css({width:330});
                t.children().each(function(i){
                    var o = $(this);
                    if (this.nodeName.toUpperCase() == 'OPTGROUP') {
                        var g = $('<ul></ul>');
                        o.children('option').each(function(j){
                            var tmp = $(this).html().split(' - '),
                                li = $('<li id="'+$(this).attr('value')+'"><p><span><strong class="pckgName">' + tmp[0] + '</strong><strong class="pckgPrice">' + tmp[1] + '</strong><a href="' + $(this).attr('label') + '" target="_blank">Részletek</a></span></p></li>');
                            li.children('p').click(function(e){
                                //t[0].selectedIndex = i;
                                t.find('option[value='+li.attr('id')+']').attr('selected',1);
                                s.html(tmp[0]+' - '+tmp[1]);
                                d.hide();
                                t.trigger('change');
                            });
                            g.append(li);
                        });
                        d.append($('<li><strong class="ttl">' + o.attr('label') + '</strong></li>').append(g));
                    }
                    else {
                        var li = $('<li id="'+o.attr('value')+'"><p><span><strong class="pckgName">' + o.html() + '</strong></span></p></li>');
                        li.children('p').click(function(e){
                            //t[0].selectedIndex = i;
                            t.find('option[value='+li.attr('id')+']').attr('selected',1);
                            s.html(o.html());
                            d.hide();
                            t.trigger('change');
                        });
                        d.append(li);
                    }
                });
            }
            else {
                t.find('option').each(function(i){
                    var o = $(this), li = $('<li id="'+o.attr('value')+'"><p><span><strong>' + o.html() + '</strong></span></p></li>');
                    li.children('p').click(function(e){
                        //t[0].selectedIndex = i;
                        t.find('option[value='+li.attr('id')+']').attr('selected',1);
                        s.html(o.html());
                        d.hide();
                        t.trigger('change');
                    });
                    d.append(li);
                });
            }
            d.append($('<li class="selbottom"><div></div></li>')).prepend($('<li class="seltop"><div></div></li>'));
            
            p.append(d);
                
            t.addClass('fixed').css({
                display: 'none'
            });
            
            b.click(function(e){
                e.preventDefault();
                if (!d.is(':visible')) {
                    d.show();
                    p.addClass('opened');
                    $(this).parents('.formRow').css('z-index',2)
                }
                else {
                    d.hide();
                    p.removeClass('opened');
                    $(this).parents('.formRow').css('z-index',1)
                }
                
            });
            
            p.add(l).hover(function(){
                p.addClass('hovered');
            }, function(){
                p.removeClass('hovered');
            });
        });
        
        $nfContainer.find('textarea:not(.fixed)').each(function(){
            var t = $(this), p = t.wrap($('<div>').addClass('customTextArea')).parent(), l = $('label[for=' + t.attr('id') + ']'), s = $('textarea[name='+t.attr('name')+']').not(t);
            t.focus(function(){
                p.addClass('hovered');
            }).blur(function(){
                p.removeClass('hovered');
            });
            p.add(l).hover(function(){
                p.addClass('hovered');
            }, function(){
                p.removeClass('hovered');
            });
            
        });
        
        $(document).click(function(e){
            $('.customSelectBox.opened .opts:visible').hide();
            if (!$(e.target).parents('.opts').length) $(e.target).parents('.customSelectBox.opened').find('.opts').show();
        });
        
        $('input:submit').replaceSubmitBtn();
        
    }
    
    function formSteps(){
        var $form = $('#torchrunningForm');
        if ($form.length) {
            
            var $fsteps = $('.formstep'), steps = $fsteps.length, cur = 0, activeStep = 0, $line = $('#line'), $btn = $('.stepBtns .next, .stepBtns .prev'), $msg = $('.frmMsg'), displayStep = function(dir, nosub){
                $fsteps.find('.formRow').each(function(){
                    var $row = $(this).removeClass('errorRow okRow');
                    if (nosub !== true) 
                        $row.find('.formError').remove();
                    $row.find('input, select, textarea').removeClass('inputError').blur();
                });
                if (nosub !== true) 
                    $form.submit();
                
                
                
                if (!$fsteps.eq(cur).find('.formError').length) {
                    $msg.hide();
                    if (dir == 'next') {
                        cur++;
                    }
                    else {
                        cur--;
                    }
                    if (cur == 0) {
                        $btn.filter('.next').find('strong').html('Következő')
                        $btn.filter('.next').show();
                        $btn.filter('.prev').hide();
                    }
                    else 
                        if (cur == 3) {
                            $btn.filter('.next').find('strong').html('Befejezés')
                            $btn.filter('.next').show();
                            $btn.filter('.prev').show();
                        }
                        else {
                            $btn.filter('.next').find('strong').html('Következő')
                            $btn.filter('.next').show();
                            $btn.filter('.prev').show();
                        }
                    if (cur < 4) {
                        $fsteps.hide()
                    }
                    $fsteps.eq(cur).show().find('input, select, textarea').removeClass('inputError').blur();
                    if (nosub !== true)
                        $fsteps.eq(cur).find('.formError').remove();
                    if (cur != steps) {
                        $line.removeClass().addClass('step-' + cur).parent().find('li').removeClass('active').filter('#step-' + (cur + 1)).addClass('active');
                    }
                }
                else {
                    $msg.show();
                    $fsteps.eq(cur).find('.formRow').each(function(){
                        var $row = $(this), valid = $row.find(':enabled.valid').length, invalid = $row.find('.inputError').length;
                        if (valid) {
                            $row.addClass('okRow');
                            $row.removeClass('errorRow');
                        }
                        else 
                            if (invalid) {
                                $row.addClass('errorRow');
                                $row.removeClass('okRow');
                            }
                        
                    });
                }
                if (cur == steps && nosub !== true) {
                    $btn.filter('.next').find('strong').html('Befejezés');
                    $btn.filter('.prev').show();
                    $form.find(':submit').click();
                }
                
            }
            
            $fsteps.hide().eq(cur).show();
            $btn.filter('.prev').hide();
            
            $fsteps.each(function(i){
                $t = $(this);
                if ($t.find('.formError').length>0) activeStep=i+1;    
            });
            for (var i=0; i<activeStep; i++) {
                displayStep('next',true);
            }
            
            $btn.click(function(e){
                e.preventDefault();
                var $t = $(this), dir = $t.is('.next') ? 'next' : 'prev';
                displayStep(dir);
            });
            
        }
    }
	
    function countDown(){
        var $cd = $(".countDownBox");
        if ($cd.length) {
            $(".countDownBox").countdown({
                date: {
                    from: "2011/08/22 00:00",
                    to: "2012/07/27 00:00"
                },
                label: {
                    from: "10:00",
                    to: "20:00"
                },
                separator: '',
                sync: location.href
            });
        }
    }
    
    function videoDialog(){
       
        var d = $("#videoDialog");
        
        if (d.length == 0) {
            d = $('<div id="videoDialog"><div id="videoContent"></div></div>');
            $('body').append(d);
        }
        d.dialog({autoOpen:false});
        
        $('a.openVideoDialog').click(function(e){
            e.preventDefault();
            
            d.dialog('destroy');
            d.dialog({
                width: 740,
                height: 456,
                draggable: false,
                modal: true
            });
            swfobject.embedSWF(K_APP_PATH+"static/swf/playa.swf", "videoContent", "720", "406", "9.0.0", K_APP_PATH+"static/swf/lib/swfobject/expressInstall.swf", {}, {
                "allowScriptAccess": "sameDomain",
                "allowFullScreen": "true",
                "quality": "best",
                "base": K_APP_PATH+"static/swf", 
                "wmode": "transparent"
            }, {});
            
        })
        
    }
    
    $(function(){
        noJs();
        newsRotator();
        $('input:submit.replace').replaceSubmitBtn();
        $('.searchForm input:text').clearInputs('Keresés');
        nicknameTooltip();
        contentColumns();
        showSubMenu();
        modalLayer();
        showPollResults();
        relatedGalleriesItems();
        setGalleryThumbnailsContainerWidth();
        searchField();
        jumpToComment();
        restoreFormValuesFromCookie('commentForm','commentFormValues');
        setSearchWidthHeight();
        setTempBodyLink();
        setTempSamsungSportLogo();
        niceForm();
        formSteps();
        countDown();
        $("#dialog").dialog({ 
          draggable: false,
          modal: true
        });
        videoDialog();
    });
    
})(jQuery);

