$(document).ready(function(){

var dev = $('#dev'),
    ie = dev.css('z-index'),
    headtitle = $('#headtitle'),
    acio = $('#acio'),
    head = $('#head'),
    page = $('#page'),
    gem = $('#gem'),
    menu = $('#menu'),
    menupont = $('#menu li a'),
    submenu = $('#submenu'),
    submenubox = $('.submenu'),
    submenupont = $('#submenu li'),
    submenucontent_item = $('#submenucontent li'),
    mirrormenu = $('#mirrormenu'),
    dept = $('#dept'),
    galeria = $(".galeria li a"),
    galeriaimg = $(".galeria li a img"),
    fullgaleria = $(".fullgaleria a"),
    fullgaleriaimg = $(".fullgaleria a img"),
    icon = $(".icon"),
    zoom= $(".zoom"),
    akaa= $(".akaa"),
    panic = $("#panic"),
    bubble = $(".bubble"),
    loc=eval('location.href'),
    H = $(window).height();
   
    loc = loc.split('/').pop();
    loc = loc.split('.');
    var filename = loc[0];
    (!filename || filename=="index")? '' : $('#quicklinks .absolutehidden').removeClass('absolutehidden');
    (filename=="teszt" || filename=="notfound" || filename=="kereses")? $('.feature').addClass('hidden') : $('.feature').removeClass('hidden') ;
      
    /* XXX TARGET OLDAL KIVETEL*/
    /* gen: .feature hidden | spec: #id hidden*/
    (filename=="nyilt_nap_a_kiskepzoben")? $('#nyiltnap_title').addClass('hidden') : $('#nyiltnap_title').removeClass('hidden');
    (filename=="rhino_3D_tanfolyam")? $('#rhino_title').addClass('hidden') : $('#rhino_title').removeClass('hidden');
    /*TARGET OLDAL KIVETEL END*/

    var cookie_name = 'ACIO';
    var options = { path: '/', expires: 7 };

    ($("#galeria").length==1) ?
    $("#galeria").jcarousel({
        scroll: 1,
        animation: 600,
        easing: "ceio",
        itemFirstInCallback:  showgaleria
    }) :'';

    ($("#galeria_02").length==1) ?
    $("#galeria_02").jcarousel({
        scroll: 1,
        animation: 600,
        easing: "ceio",
        itemFirstInCallback:  showgaleria
    }) :'';

    ($("#galeria_03").length==1) ?
    $("#galeria_03").jcarousel({
        scroll: 1,
        animation: 600,
        easing: "ceio",
        itemFirstInCallback:  showgaleria
    }) :'';
        
    submenucontent_item.css('visibility','hidden');
    icon.css('opacity','0.7');
    
/* EASINGS */
    $.easing['circ'] = function(p, n, firstNum, diff) {
       var c=firstNum+diff;        
       return -c * (Math.sqrt(1 - (p/=1)*p) - 1) + firstNum;
    };
    
    $.easing['ceio'] = function(p, n, firstNum, diff) {
        var c=firstNum+diff;  
        if ((p/=0.5) < 1)
            return c/2*p*p*p + firstNum;
        else
            return c/2*((p-=2)*p*p + 2) + firstNum;
    }; 
/* EASINGS END */

mp_over = function() {
        if ($(this).hasClass("")){
        num = $(this).parent().index()+1;
        (num<10) ? dept.attr('src', './gfx/m0'+ num +'.png') : dept.attr('src', './gfx/m'+ num +'.png');
        } else {
        num = $(this).attr('class');
        dept.attr('src', './gfx/'+ num +'.png');
        }
        dept.css('display','block');
        dept.css('opacity','0');
        dept.css('visibility','visible');
        dept.animate({'opacity':'1'}, 600, "ceio", function(){dept.stop()} );
};
mp_out = function() {
        dept.stop();
        dept.attr('src', './gfx/dummy.png');
        dept.css('visibility','hidden');
        dept.css('opacity','0');
        dept.css('display','none');
};

(menupont.length)? menupont.hoverIntent( mp_over, mp_out): '';

m_over = function() {
        head.addClass('neutral');
        menu.removeClass('m_out').addClass('m_over');
};
m_out = function() {
        menu.stop();
        head.removeClass('neutral');
        menu.removeClass('m_over').addClass('m_out');
};

(menu.length)? menu.hoverIntent( m_over, m_out): '';

icon.hover(
    function(){
        $(this).stop();
        $(this).animate({'opacity':'1'}, 200);
    },
    function(){
        $(this).stop();
        $(this).animate({'opacity':'0.7'}, 200);
    }
);

panic.hover(
    function(){
        $(this).stop();
        $(this).animate({'top':'0px'}, 200, 'ceio');
    },
    function(){
        $(this).stop();
        $(this).animate({'top':'-80px'}, 200, 'ceio');
    }
);

$('.help').hover(
    function(){
        $('.littlepanic').stop();
        $('.littlepanic').animate({'left':'-21px', 'width':'20px'}, 200, 'ceio');
    },
    function(){
        $('.littlepanic').stop();
        $('.littlepanic').animate({'left':'0px', 'width':'0px'}, 200, 'ceio');
    }
);

$('#rhino_title img').hover(
    function(){
        $('#rhino_title img.i02').stop();
        $('#rhino_title img.i02').css('opacity','0').removeClass('hidden');
        $('#rhino_title img.i02').animate({'opacity':'1'}, 200, 'ceio');
    },
    function(){
        $('#rhino_title img.i02').stop();
        $('#rhino_title img.i02').animate({'opacity':'0'}, 200, 'ceio', function(){
            $(this).css('opacity','0').addClass('hidden');
        });
        
    }
);



fv2011_over = function() {
        $('#felveteli2011').css('background-position','-250px');
};
fv2011_out = function() {
        $('#felveteli2011').css('background-position','0px');
};

($('#felveteli2011').length)? $('#felveteli2011').hoverIntent( fv2011_over,fv2011_out): '';


//panic.click(function(){});

submenupont.click(function(e){
    (!submenucontent_item.length)? '': e.preventDefault();
    (H<"650" && submenucontent_item.length)? $('html,body').delay(800).animate({'scrollTop':'245px'}, 500, 'swing') : '';
    submenupont.css('padding-bottom','0px');
    submenupont.css('margin-bottom','0px');
    submenupont.css('border-bottom','0px solid #dd0000');
    submenucontent_item.css('visibility','hidden');
    if (ie!="6") submenucontent_item.eq($(this).index()).css('opacity','0');
    if (ie!="6") submenucontent_item.eq($(this).index()).css('visibility','visible').animate({'opacity':'1'}, 200);
    submenucontent_item.eq($(this).index()).css('visibility','visible')
    if (ie!="6") submenucontent_item.eq($(this).index()).css('opacity','1');
    submenupont.eq($(this).index()).eq(0).css('padding-bottom','2px');
    submenupont.eq($(this).index()).eq(0).css('margin-bottom','-4px');
    submenupont.eq($(this).index()).eq(0).css('border-bottom','1px solid #dd0000');
    $.cookie(cookie_name, $(this).index(), options);
});

(!$.cookie(cookie_name)) ? $.cookie(cookie_name, '0', options): submenupont.eq(''+$.cookie(cookie_name)+'').trigger('click');

/*DONACIO FORCE*/
//if (!$.cookie(cookie_name)) {
//    $.cookie(cookie_name, '6', options)
//    submenupont.eq(6).trigger('click')
//} else {
//    submenupont.eq(6).trigger('click'); }

/**/
submenupont_over = function() {
    bb = $(this).find('.bubble');
    bb.animate({
            'opacity':'1',
            'top':'-20px'
            }, 200, "swing");
};

submenupont_out = function() {
    bb = $(this).find('.bubble');
    bb.animate({
            'opacity':'0',
            'top':'0px'
            }, 100, "swing");
};

if (bubble.length) {
    submenupont.hoverIntent( {
        sensitivity: 7,
        interval: 200,  
        timeout: 10,
        over: submenupont_over,
        out: submenupont_out
    });
}
/**/
smpci_over = function() {
    submenupont.eq($(this).index()).eq(0).css('padding-bottom','2px');
    submenupont.eq($(this).index()).eq(0).css('margin-bottom','-4px');
    submenupont.eq($(this).index()).eq(0).css('border-bottom','1px solid #dd0000');
};
smpci_out = function() {
    submenupont.eq($(this).index()).eq(0).css('padding-bottom','0px');
    submenupont.eq($(this).index()).eq(0).css('margin-bottom','0px');
    submenupont.eq($(this).index()).eq(0).css('border-bottom','0px solid #dd0000');
};

if (submenucontent_item.length) {
    submenucontent_item.hoverIntent( {
        sensitivity: 7,
        interval: 50,  
        timeout: 10,
        over: smpci_over,
        out: smpci_out
    });
}

/*floatbox fullheight*/
if ($('.fullheight').length!=0) { $('.fullheight').height($('.fullheight').parent().height()); }

/*GEM*/
if ($('.torn').length==0) {
    var gems = "6";
    randNum = Math.floor ( Math.random ( ) * gems + 1 );
    //(randNum=="2" || randNum=="5") ? randNum="3" : ''; /*HIDE No3BG */
    gem.attr('src', './gfx/gem_0'+ randNum +'.png');
} else {
    gem.attr('src', './gfx/gem_01.png');
}
/*GEM END*/

/* GALERIA */
    function showgaleria() {
        galeria.colorbox({transition:"none", width:"75%", height:"95%"});
        galeria.hover(
            function(){
                $(this).children(":first").stop();
                $(this).children(":first").css({
                    'border-color':'white',
                    'top':'0px',
                    'left':'0px'
                    });
                $(this).children(":first").animate({
                        'border-width':'0px',
                        'opacity':'1',
                        'width':'60px',
                        'height':'60px',
                        'top':'-5px',
                        'left':'-5px'
                        }, 100, "swing", function(){
                });
            },
            function(){
                $(this).children(":first").stop();
                $(this).children(":first").css('border-color','white');
                $(this).children(":first").animate({
                        'border-width':'5px',
                        'opacity':'0.5',
                        'width':'50px',
                        'height':'50px',
                        'top':'-5px',
                        'left':'-5px'
                        }, 100, "swing", function(){
                });
            }
        );        
    };

(fullgaleria.length) ? showfullgaleria() : '';


fullgaleria.each(function() {
    $(this).width( $(this).children().width() )   
    $(this).height( $(this).children().height() )
});


//fullgaleria.width( fullgaleria.children(":first").width() )
//fullgaleria.height( fullgaleria.children(":first").height() )



function showfullgaleria() {
        fullgaleria.colorbox({transition:"none", width:"75%", height:"95%"});
        fullgaleria.hover(
            function(){
                $(this).children(":first").stop();
                tw = $(this).width()+10;
                th = $(this).height()+10;
                $(this).children(":first").css({
                    'border-color':'white',
                    'top':'0px',
                    'left':'0px'
                    });
                $(this).children(":first").animate({
                        'border-width':'0px',
                        'opacity':'1',
                        'width': tw+'px',
                        'height': th+'px',
                        'top':'-5px',
                        'left':'-5px'
                        }, 100, "swing", function(){
                });
            },
            function(){
                $(this).children(":first").stop();
                $(this).children(":first").css('border-color','white');
                $(this).children(":first").animate({
                        'border-width':'5px',
                        'opacity':'0.5',
                        'width':tw-10+'px',
                        'height':th-10+'px',
                        'top':'-5px',
                        'left':'-5px'
                        }, 100, "swing", function(){
                });
            }
        );        
    };
    
/* GALERIA END */

/* SIMP ACCORDION */
    $('.dij').click(function() {
        $('.dijszoveg').slideUp('normal');
        if($(this).next().is(':hidden') == true) {
            $(this).next().slideDown('normal');
        } 
    });
/* SIMP ACCORDION END */

/* SIMP ACCORDION */
    ($('.ev_nevsor').length) ? $('.ev_nevsor').css('display','none') : '';    
    $('.ev').click(function() {
        $('.ev_nevsor').slideUp('normal');
        if($(this).next().is(':hidden') == true) {
            $(this).next().slideDown('normal');
        } 
    });
/* SIMP ACCORDION END */


/* SIMP ACCORDION */
    $('.accordiontitle').click(function() {
        $('.accordioncontent').slideUp('normal');
        if($(this).next().is(':hidden') == true) {
            $(this).next().slideDown('normal');
        } 
    });
/* SIMP ACCORDION END */

/* ANCHOR NAV */
function filterPath(string) {
    return string
            .replace(/^\//,'')
            .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
            .replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElement = 'html, body';
$('html, body').each(function () {
    var initScrollTop = $(this).attr('scrollTop');
    $(this).attr('scrollTop', initScrollTop + 1);
    if ($(this).attr('scrollTop') == initScrollTop + 1) {
        scrollElement = this.nodeName.toLowerCase();
        $(this).attr('scrollTop', initScrollTop);
        return false;
    }    
});

$('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if  (   locationPath == thisPath
            && (location.hostname == this.hostname || !this.hostname)
            && this.hash.replace(/#/, '')
        ) {
            if ($(this.hash).length) {
                $(this).click(function(event) {
                    var targetOffset = $(this.hash).offset().top;
                    var target = this.hash;
                    event.preventDefault();
                    $(scrollElement).animate(
                        {scrollTop: targetOffset},
                        1000, "ceio",
                        function() {
                            location.hash = target;
                    });
                    
                });
            }
    }
});
/* ANCHORNAV END */


/* COLORBOX */
(zoom.length) ? zoom.colorbox({transition:"none", width:"75%", height:"95%"}) : '';
(akaa.length) ? akaa.colorbox({transition:"none", width:"780px", innerHeight:"560px", top:"0px", iframe:true}) : '';
($("a[rel='tanarmunka']").length) ? $("a[rel='tanarmunka']").colorbox({transition:"none", width:"75%", height:"95%"}) : '';
/* COLORBOX END */

/* gaq - event */
document.onclick = function(event) { /* ra vel rum ba */
 
    event = event || window.event;
    var target = event.target || event.srcElement,
        targetElement = target.tagName.toLowerCase();
 
    if (targetElement == "a") {
        var href = target.getAttribute("href"),
            urlHost = document.domain.replace(/^www\./i,"");
        var urlPattern = "^(?:https?:)?\/\/(?:(?:www)\.)?" + urlHost + "\/?";
        eventCheck(href,urlPattern);
    }
 
    function eventCheck(href,urlPattern){
        if ((href.match(/^https?\:/i)) && (!href.match(urlPattern))){
            if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) {
                _gaq.push(['_trackEvent', 'Download', 'click', href]);
            } else {
                _gaq.push(['_trackEvent', 'External', 'click', href]);
            }
        } else if (href.match(/^mailto\:/i)) {
            _gaq.push(['_trackEvent', 'Email', 'click', href.substr(7)]);
        } else if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) {
            _gaq.push(['_trackEvent', 'Download', 'click', href]);
        }
    }
};

$('#rukverc').click(function(){ _gaq.push(['_trackEvent', 'Anchor', 'click', 'rukverc']); });

/*xxx toplinks*/
//$('.evvegikiallitas2011').click(function(){ _gaq.push(['_trackEvent', 'Anchor', 'click', 'evvegikiallitas2011-tojgli']); });
//$('#rhino_img').click(function(){ _gaq.push(['_trackEvent', 'TopLink', 'click', 'rhino']); });
//$('#nyiltnap_img').click(function(){ _gaq.push(['_trackEvent', 'TopLink', 'click', 'nyiltnap']); });
//$('#felveteli2011').click(function(){ _gaq.push(['_trackEvent', 'Anchor', 'click', 'felveteli-2011-postit']); });

/* gaq - event end */

if ($('.fh').length!=0) { $('.fh').height($('.fh').parent().height()); }


/* w resize */
$(window).resize(function() {
    H = $(window).height();
    (H<"650" && submenucontent_item.length)? $('html,body').delay(800).animate({'scrollTop':'245px'}, 500, 'swing') : '';
});
/* w resize end */


});
