



var num_of_try_newsletter_subscription = 0; //ezzel szamoljuk, hogy hanyszor probaltak hírlevélre feliratkozni, 'max_try' darab utan tiltunk
var max_try = 20;

$(document).ready(function(){


    //Facebook inicializalas
    FB.init({ 
        appId:'245495998838120', cookie:true, status:true, xfbml:true 
    });
    FB.Event.subscribe('auth.login', function(response) {
        window.location = 'http://gsm-online.hu/?page=fb_registration';
    });
    


/*
    $(".submenus").css("display", "none");  
    $(".menuitem").hover(function(){
        $(this).children(".submenu-wrap").children(".submenus").css("display", "block");
    },function(){
        $(this).children(".bottom-wrap").children(".submenu-wrap").children(".submenus").css("display", "none");
    });
    $(".menuitem").mousemove(function(){$(this).children(".submenus").css("display", "block");});
    $(".submenus").mousemove(function(){$(this).css("display", "block");});
*/


/*    alert('default.js ready');    */

    


    $("#search_input").example(default_input_search);    
    $("#newsletter_name").example(default_input_name);    
    $("#newsletter_email").example(default_input_email);    
    
    /*
    $(".search-top, #search_input").focus(function(){    
        $("#search_input").animate({'width' : '200'}, 500);
        $(".search-list").show();        
    });*/
    
    
    
    
    //$(document).children().not(".search-top, #search_input, .search-list").click(function(){    
    $(document).children().not(".search-top, #search_input, .search-list").click(function(){    
        $(".search-list").hide();
    });
    
    
    
    
    $("#search_input").focus(function(){        
        /*$("#search_input").animate({'width' : '200'}, 500);*/
        $(".search-list").show();        
    });
    
    
   
    
    
    /*
    $(".search-top").children("*").click(function(){        
        
        $(".search-list").show();        
    });
    */
    
    
    
    /*
    $(".search-top, #search_input").blur(function(){    
        $("#search_input").animate({'width' : '130'}, 500);
        $(".search-list").hide();        
    });
    */
    
    /*
    $(":not(.search-top)").children("*").click(function(){        
        $("#search_input").animate({'width' : '130'}, 500);
        $(".search-list").hide();
        
    });*/
    
    
    
    
    //enter-re is kuldjuk a formot
    $("#login_pass").keypress(function(e)
    {
        code= (e.keyCode ? e.keyCode : e.which);
        if (code == 13) 
        {
             $("#login_form").submit();
        }

    });
    
    
    
    /* hirlevel feliratkozas*/
    $("#newsletter_submit").click(function(){

        num_of_try_newsletter_subscription++;
        if(num_of_try_newsletter_subscription > max_try) {
            $("#newsletter_submit").remove();
            return 0;
        }
        


        var op = 'hirlevelfeliratkozas';
                
        $(".hirlevel-response").show();

        var newsletter_name = $("#newsletter_name").val()
        var newsletter_email = $("#newsletter_email").val();
        
        
        $.ajax({
               
             
            
              url: '/ajax/'+op+'/'+newsletter_name+'/'+newsletter_email,
              method: 'post',
              success: function(data){
                
                
                    $(".hirlevel-loading").hide();
                    
                    $(".hirlevel-response").html(data.content);
                    $(".hirlevel-response").show();
                
                    if( data.clear_form == 1 ) clear_form_elements("#hirlevel_feliratkozas");
                
              }
            
        });


    }); //hirlevel feliratkozas vege
    
    
    //belepesre kattintas
    $("#login_submit").click(function(){
        
        $("#login_form").submit();
        
    });
    
    
    
    
    
    //baloldali gyarto treeview csere
    $("#switch2mobiltelefon").click(function(){        
        $(".treetab").hide();
        $(".treetab-mobiltelefon").show();  
        $("#switch2tartozek").removeClass('active');
        $("#switch2mobiltelefon").addClass('active');
    });
    $("#switch2tartozek").click(function(){        
        $(".treetab").hide();
        $(".treetab-tartozek").show();
        $("#switch2mobiltelefon").removeClass('active');
        $("#switch2tartozek").addClass('active');
    });
    
    
    
    
    
    /**
     * 
     * az utolso video beágyazást átméretezzük 
     * max 300px széles
     * */
    /*
    var max_width = 283;
    var ratio = 0;
    var w = $(".video-last-wrap iframe").width();
    var h = $(".video-last-wrap iframe").height();
    ratio = max_width / w;
    $(".video-last-wrap iframe").width(max_width);    
    $(".video-last-wrap iframe").height(h*ratio);
    */
    
    $(".video-last-wrap iframe").width(284);    
    $(".video-last-wrap iframe").height(162);
    
    
    $(".left-wrap .center iframe").width(485);    
    $(".left-wrap .center iframe").height(350);
    
   
    $('.mycarousel').jcarousel({
        
        'scroll' : 3,
        'rtl': false
        
    }); 
    
    
    
    
    $("iframe").attr("wmode", "transparent");


     $("a.fancyimage").fancybox({
            'type' : 'image',
            'onStart': 
                function(){
                       $(".video-last-wrap").hide();                         
                }, // change th id here to thing you want to hide 
            'onClosed': 
                function(){
                         $(".video-last-wrap").show();
                } // change the id here-enable it re-enable it on close 
        });


    
});

    




function debug(text) {
    $('#debug').append(text+'<br />');
}


function clear_form_elements(ele) {

    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');                
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
        
        $(this).trigger('blur');
        
    });

}






function fblogout(){
    
    FB.getLoginStatus(function(response) {
        if (response.status == 'connected') {
            FB.logout(function(response2) {
                window.location = 'http://gsm-online.hu/?page=login&op=logout';
            });
        }else{
            window.location = 'http://gsm-online.hu/?page=login&op=logout';
        }
    });
}



