$(document).ready(function(){
    
    var special = $('#special'),
        specialimgs = $('#special img'),
        specialbottom = $('.specialbottomtext'),
        specialbottomtext = $('.specialbottomtext a'),
        speciallinks = $('.sl'),
        dev = $('#dev'),
        strip = $('#strip'),
        sg = $('#smilegallery'),
        sgc = $('#sg_content'),
        star = $('#star'),
        sb = $('#sidebox'),
        x = "0",
        submit = $('.submitbutton'),
        menu = $('#menu'),
        gc = $('#goalcontent'),
        sgc_img = $('#sg_content img'),
        mtbbox = $('#mtbbox'),
        mtb = $('#mtb'),
        H = $(window).height();
        ($(window).height()>"500")? smallscreen="0" : smallscreen="1";

    if (smallscreen=="1") {
        $('#headstrip').css("top","-40px");
        $('body').css("margin-top","-40px");
        $('body').css("background-position","center -40px");
    } else {}
        
        
    $('#bubble').css('opacity','0.0');
    $('#lang').css('opacity','0.5');
    

    $('#lang').mouseover(function(){
        $(this).animate({'opacity':'1'}, 200);
    });
    $('#lang').mouseout(function(){
        $(this).animate({'opacity' : '.5'}, 200);
    });

    /*SMILEGALLERY*/
    sgc_img.mouseover(function(){
        $(this).css("cursor","pointer");
        index = $(sgc_img).index(this)+1;       
        lim = sgc_img.length;
            if (index==lim) {
                sgc.css("left", "0px");
            } else {
                sgc.animate({"left": "" + 0-index*190 + "px"}, 1400, "swing");
            }
    });
    sgc_img.click(function(){
        window.location.href = "mosolygaleria.html";
    });
    

    /*SPECIALIS KEZELESEK*/
    /*show special*/
   
    sl_over = function() {
            $(specialimgs).stop();
            $(special).removeClass("absolutehidden");
            index = $(speciallinks).index(this);
    
            $(specialimgs).css({"z-index":"10"})
                    .css({display:"block"});
            $(specialimgs).eq(index).css({"z-index":"999"})
                    .css({"visibility":"visible"})
                    .css({"opacity":"0"});
    
            $(specialimgs).eq(index).animate({"opacity":"1"}, 300);
            
            /* STUFF */
            currimg = $(specialimgs).eq(index).attr("src");
            si_num = $(specialimgs).length-1;
    };
    sl_out = function() {
            $(specialimgs).stop();
            index = $(speciallinks).index(this);
            $(specialimgs).eq(index).animate({"opacity":"0"}, 10);
            $(specialimgs).eq(index).css({"z-index":"500"})
                    .css({"visibility":"visible"});
    };
    
    speciallinks.hoverIntent( {
        sensitivity: 3,
        interval: 200,  
        timeout: 100,
        over: sl_over,
        out: sl_out
    });
    
    
    /*hide special*/
    specialbottomtext.click(function(){
        $(specialimgs).stop();
        $(special).addClass("absolutehidden");
        (x=="0")? $(this).open() : $(this).close() ;
        x = (x=="0")? "1": "0";
    });
    specialbottomtext.hover(
        function(){
            specialbottom.css('background-color','rgba(255,255,255,0.7)');
        },
        function(){
            specialbottom.css('background-color','transparent');
        }
    );   
    
    /*SPECIALIS KEZELESEK END*/
        
        
    $("a[rel='hitec']").colorbox({transition:"none", width:"75%", height:"90%"});
    $(".ingallery ul li a:not(.nc)").colorbox({transition:"none", width:"75%", height:"90%"});
    $("#ingallery ul li a:not(.nc)").colorbox({transition:"none", width:"75%", height:"90%"});
    $("#smilegallerycontent a[rel='sg']").colorbox({transition:"none", width:"75%", height:"90%"});

    star.mouseover(function(){
        (x=="0") ? star.attr('src', './gfx/email_o.png') : star.attr('src', './gfx/cancel.png');
        (x=="0") ? $('#bubble').animate({'opacity':'1'}, 400, "swing") : '';
    });

    star.mouseout(function(){
        (x=="0") ? star.attr('src', './gfx/email.png') : star.attr('src', './gfx/cancel.png');
        (x=="0") ? $('#bubble').animate({'opacity':'0'}, 400, "swing") : '';
    });    
    
    star.click(function(){       
        (x=="0")? $(this).open() : $(this).close() ;
        x = (x=="0")? "1": "0";
    });

    $.fn.open = function() {
        star.attr('src', './gfx/cancel.png');
        $(special).css('display','none');
        $('#bubble').animate({'opacity':'0'}, 400, "swing");
        gc.animate({'opacity':'0'}, 400, "swing", function(){
            gc.css('display','none');
            sb.css('display','block');
            sb.animate({'opacity':'1'}, 400, "swing");
            $('.menulist').animate({'opacity':'0'}, 400, "swing");
            $('#menu .head').animate({'opacity':'0'}, 400, "swing");
            $('.goaldesc').css('display','block');
            $('.goaldesc').animate({'opacity':'1'}, 400, "swing");
            });
    };
    
    $.fn.close = function() {
        star.attr('src', './gfx/email.png');
        $(special).css('display','block');
        sb.animate({'opacity':'0'}, 400, "swing", function(){
            x="0";
            star.attr('src', './gfx/email.png');
            sb.css('display','none');
            gc.css('display','block');
            gc.animate({'opacity':'1'}, 400, "swing", function(){});
            $('.menulist').animate({'opacity':'1'}, 400, "swing");
            $('#menu .head').animate({'opacity':'1'}, 400, "swing");
            $('.goaldesc').animate({'opacity':'0'}, 400, "swing", function(){
                $('.goaldesc').css('display','none');
                });
        });
    };

    $('.submitbutton').click(function(){
        $("#trident").trigger("submit");
        pageTracker._trackEvent('FORM','submit','idopont');
    });
   
    $(window).resize(function() {
        H = $(window).height();
        ($(window).height()>"500")? smallscreen="0" : smallscreen="1";
        if (smallscreen=="1") {
            $('#headstrip').css("top","-40px");
            $('body').css("margin-top","-40px");
            $('body').css("background-position","center -40px");
        } else {
            $('#headstrip').css("top","0px");
            $('body').css("margin-top","0px");
            $('body').css("background-position","center top");
        }
    });
    
    //window.setInterval(yourFunction, 1000);
    var vis = false;
    if (mtb.length){
    $.timer(1500, function (timer) {
    	if (!vis) {
            $('#mtb').animate({'opacity':'1'}, 500, "swing");
            vis = true;
    	}
    	else {
    		$('#mtb').animate({'opacity':'0'}, 500, "swing");
    		vis = false;
    	}
    });
    } 
    
    
});